Exemple #1
0
// turtle_portfolio_performance
// turtle_portfolio_transaction
// 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;
Exemple #2
0
function stat_beta($data1, $data2)
{
    return stat_cov($data1, $data2) / stat_var($data1);
}