예제 #1
0
def test_hypothesis_test():
  """Test the hypthosis_test function."""
  base = power(2.0, 1.0/252.0)
  benchmark_backtest = get_backtest_from_open_values([1, 1*base, 1*base**2, 1*base**3])
  test_backtest = get_backtest_from_open_values([1, 1*base**2, 1*base**4, 1*base**6])
  benchmarkt_returns = get_log_daily_returns(benchmark_backtest)
  test_returns = get_log_daily_returns(test_backtest)
  (actual_mean, actual_p_value) = hypothesis_test(test_returns, benchmarkt_returns)
  assert_true(abs(actual_mean - 100.0) < 0.000001)
  assert_equal(actual_p_value, 0.0)
예제 #2
0
def main():
  start_date = date(2002,1,1)
  end_date = date(2012, 7, 7)
  buy_hold = Backtest(start_date, end_date, commissions_class=WellsPMACommissions, 
                      strategy_class=BuyHoldSPY, taxes_class=Taxes,
                      end_of_day_class=Yahoo, portfolio=Portfolio(1e7))
  halloween = Backtest(start_date, end_date, commissions_class=WellsPMACommissions, 
                                 strategy_class=Halloween, taxes_class=Taxes,
                                 end_of_day_class=Yahoo, portfolio=Portfolio(1e7))
  buy_hold_returns = get_log_daily_returns(buy_hold)
  halloween_returns = get_log_daily_returns(halloween)
  (excess_return, p_value) = hypothesis_test(halloween_returns, buy_hold_returns)
  print "Excess return of Halloween: " + str(excess_return) + "%"
  print "p-value of Halloween: " + str(p_value) + "%"