def manual_test_policy_bb(symbol, sd, ed, start_value): trades_df = manual_bb_indicator(symbol, sd, ed) commission = 0 impact = 0.005 # pass df_trade to marketsimcode to plot portvals = mktsim.compute_portvals(trades_df=trades_df, start_val=start_value, commission=commission, impact=impact) mktsim.gen_plot(trades_df, portvals, "BollingerBandStrategy: Fund vs Benchmark", symbol)
def test_policy_sma(symbol, sd, ed, start_value): trades_df = sma_indicator(symbol, sd, ed) commission = 9.95 impact = 0.005 portvals = mktsim.compute_portvals(symbol, trades_df=trades_df, start_val=start_value, commission=commission, impact=impact) mktsim.gen_plot(trades_df, portvals, "SimpleMovingAverageStrategy: Fund vs Benchmark")
elif prices_JPM.iloc[i + 1] < prices_JPM.iloc[i]: trades_df.iloc[i] = -1000 else: trades_df.iloc[i] = 0 #print trades_df #convert to df trades_df = trades_df.to_frame() return trades_df if __name__ == "__main__": symbol = 'JPM' start_value = 100000 sd = dt.date(2008, 1, 1) ed = dt.date(2009, 12, 31) commission = 0 impact = 0 trades_df = testPolicy(symbol=symbol, start_date=sd, end_date=ed, start_value=start_value) #print trades_df # pass df_trade to marketsimcode to plot portvals = mktsim.compute_portvals(trades_df=trades_df, start_val=start_value, commission=commission, impact=impact) mktsim.gen_plot(trades_df, portvals, "BestPossibleStrategy: Fund vs Benchmark")
sym = "JPM" #USE JPM for reports sd_insample = dt.date(2008, 1, 1) ed_insample = dt.date(2009, 12, 31) # train with in-sample data sl_learner = sl.StrategyLearner(verbose=True, impact=impact) sl_learner.addEvidence(symbol=sym, sd=sd_insample, ed=ed_insample, sv=10000) # test with in-sample data print "Test In-sample with ML strategy\n" df_delta_trades_ML = sl_learner.testPolicy(symbol=sym, sd=sd_insample, ed=ed_insample, sv=10000) # pass df_trade to marketsimcode to plot portvals = mktsim.compute_portvals_trade_delta( trades_delta_df=df_delta_trades_ML, start_val=start_value, commission=commission, impact=impact, symbol=sym) mktsim.gen_plot(df_delta_trades_ML, portvals, "Strategy Learner: Fund vs Benchmark", symbol=sym) #indic.bollingerBand(sym="JPM", sd=dt.date(2008,1,1), ed=dt.date(2009,12,31))
def manual_test_policy_ema(symbol, sd, ed, start_value): trades_df = manual_ema_indicator(symbol, sd, ed) commission = 0 impact = 0.005 portvals = mktsim.compute_portvals(trades_df=trades_df, start_val=start_value, commission=commission, impact=impact) mktsim.gen_plot(trades_df, portvals, "ExponentialMovingAverageStrategy: Fund vs Benchmark", symbol)