sddr = matrix_v_port.pct_change().std() cr = matrix_v_port.iloc[-1] / matrix_v_port.iloc[0] - 1 # Get the statistics for the benchmark daily_ret_bench = matrix_v_bench.pct_change() adr_bench = matrix_v_bench.pct_change().mean() sddr_bench = matrix_v_bench.pct_change().std() cr_bench = matrix_v_bench.iloc[-1] / matrix_v_port.iloc[0] - 1 # Get the normalized data for the two portfolios port_norm = matrix_v_port / matrix_v_port.iloc[0] bench_norm = matrix_v_bench / matrix_v_bench.iloc[0] print 'Cumulative return of the benchmark is ', cr_bench print 'Cumulative return of the portfolio is ', cr print 'Stdev of the daily return of the benchmark is ', sddr_bench print 'Stdev of the daily return of the portfolio is ', sddr print 'Mean of the daily return of the benchmark is ', adr_bench print 'Mean of the daily return of the portfolio is ', adr print 'The trading strategy is \n', df_trades pl_data = pd.concat([port_norm, bench_norm], axis=1) pl_data.columns = ['Manual Strategy', 'Benchmark'] ms.plot_data(pl_data, orders=orders) if __name__ == '__main__': ms.testStrategy(symbol='JPM', sd=dt.datetime(2008, 1, 1), ed=dt.datetime(2009, 12, 31), sv=100000) testStrategy(symbol='JPM', sd=dt.datetime(2008, 1, 1), ed=dt.datetime(2009, 12, 31), sv=100000)
print('Author', author()) symbol = "JPM" start_date = dt.datetime(2008, 1, 1) end_date = dt.datetime(2009, 12, 31) start_val = 100000 commission = 9.95 impact = 0.005 verbose = False print('------ Indicators Chart ------') getCombinedIndicators([symbol], start_date, end_date, lookback=20) print('------ Manual Strategy ------') ms.testStrategy(symbol, start_date, end_date, start_val, name='Portvals_MS_Insample.png', verbose=verbose) ms.testStrategy(symbol, dt.datetime(2010, 1, 1), dt.datetime(2011, 12, 31), start_val, name='Portvals_MS_Outsample.png', verbose=verbose) print() print( '------ Strategy Learner ------ \n------ BagLearner with Random Tree Learner ------' ) learner = sl.StrategyLearner(verbose=verbose, commission=commission,