Why is BM flat on the first chart? Please check the code.
`
import pandas as pd
import pytz
from qstrader.alpha_model.fixed_signals import FixedSignalsAlphaModel
from qstrader.asset.equity import Equity
from qstrader.asset.universe.static import StaticUniverse
from qstrader.data.backtest_data_handler import BacktestDataHandler
from qstrader.data.daily_bar_csv import CSVDailyBarDataSource
from qstrader.statistics.tearsheet import TearsheetStatistics
from qstrader.trading.backtest import BacktestTradingSession
# Construct the symbols and assets necessary for the backtest
strategy_symbols = ['SPY', 'AGG']
strategy_assets = ['EQ:%s' % symbol for symbol in strategy_symbols]
strategy_universe = StaticUniverse(strategy_assets)
# To avoid loading all CSV files in the directory, set the
# data source to load only those provided symbols
# Construct an Alpha Model that simply provides
# static allocations to a universe of assets
# In this case 60% SPY ETF, 40% AGG ETF,
# rebalanced at the end of each month
Why is BM flat on the first chart? Please check the code.
` import pandas as pd
import pytz
from qstrader.alpha_model.fixed_signals import FixedSignalsAlphaModel from qstrader.asset.equity import Equity from qstrader.asset.universe.static import StaticUniverse from qstrader.data.backtest_data_handler import BacktestDataHandler from qstrader.data.daily_bar_csv import CSVDailyBarDataSource from qstrader.statistics.tearsheet import TearsheetStatistics from qstrader.trading.backtest import BacktestTradingSession
start_dt = pd.Timestamp('2009-12-31', tz=pytz.UTC) end_dt = pd.Timestamp('2015-12-31', tz=pytz.UTC)
strategy_symbols = ['SPY', 'AGG'] strategy_assets = ['EQ:%s' % symbol for symbol in strategy_symbols] strategy_universe = StaticUniverse(strategy_assets)
data_source = CSVDailyBarDataSource(csv_dir="C://Users//silen//Documents//♠ Asset Allocation Engine//Qstrader//examples",asset_type=Equity, csv_symbols=strategy_symbols)
data_source.asset_bar_frames['EQ:SPY'] data_source.asset_bar_frames['EQ:AGG']
data_handler = BacktestDataHandler(universe=strategy_universe, data_sources=[data_source])
strategy_alpha_model = FixedSignalsAlphaModel({'EQ:SPY': 0.6, 'EQ:AGG': 0.4})
strategy_backtest = BacktestTradingSession( start_dt, end_dt, strategy_universe, strategy_alpha_model, rebalance='end_of_month', long_only=True, cash_buffer_percentage=0.01, data_handler=data_handler )
strategy_backtest.run()
benchmark_assets = ['EQ:SPY'] benchmark_universe = StaticUniverse(benchmark_assets)
benchmark_alpha_model = FixedSignalsAlphaModel({'EQ:SPY': 1.0}) benchmark_backtest = BacktestTradingSession( start_dt, end_dt, benchmark_universe, benchmark_alpha_model, rebalance='buy_and_hold', long_only=True, cash_buffer_percentage=0.01, data_handler=data_handler )
benchmark_backtest.run()
benchmark_equity=benchmark_backtest.get_equity_curve() trategy_equity=strategy_backtest.get_equity_curve()
tearsheet = TearsheetStatistics( strategy_equity=strategy_backtest.get_equity_curve(), benchmark_equity=benchmark_backtest.get_equity_curve(), title='60/40 US Equities/Bonds' )
tearsheet.plot_results() `