Пример #1
0
// turtle_portfolio
include_once 'dbfunction.php';
//include_once 'portfolio_selection.php';
include_once 'turtle_share_module.php';
include_once 'stats_module.php';
if ($_GET['action'] == 'test_cov') {
    $count = 0;
    $spy = array();
    $stock = array();
    $today_date = date("Y-m-d");
    $year_ago_date = date('Y-m-d', strtotime('-1 year'));
    $spy = stock_return('SPY', $year_ago_date, $today_date);
    $stock = stock_return('AAPL', $year_ago_date, $today_date);
    $cov = stat_cov($spy, $stock);
    print "cov: {$cov} \n";
    $cc = stat_corr_coef($spy, $stock);
    print "corr coeff: {$cc} \n";
    $r_squared = stat_r_squared($spy, $stock);
    //$r_sqaured = pow($cc, 2);
    print "r sqaured: {$r_squared} \n";
    //$beta = stat_cov($spy, $stock) / stat_var($spy);
    $beta = stat_beta($spy, $stock);
    print "beta: {$beta} \n";
} else {
    if ($_GET['action'] == 'test_calculate_portfolio_beta') {
        $today_date = date("Y-m-d");
        $year_ago_date = date('Y-m-d', strtotime('-1 year'));
        $spy = stock_return('SPY', $year_ago_date, $today_date);
        $count = 0;
        $pvalue = turtle_portfolio_value(2);
        $query = "select symbol, last_price, shares, last_price*shares, last_price*shares/" . $pvalue;
Пример #2
0
function stat_r_squared($data1, $data2)
{
    return pow(stat_corr_coef($data1, $data2), 2);
}