mhallsmoore / qstrader

QuantStart.com - QSTrader backtesting simulation engine.
https://www.quantstart.com/qstrader/
MIT License
2.91k stars 854 forks source link

why BM line is flat? #341

Closed silent0506 closed 4 years ago

silent0506 commented 4 years ago

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)

# 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

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])

# 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

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()

# Construct benchmark assets (buy & hold SPY)

benchmark_assets = ['EQ:SPY'] benchmark_universe = StaticUniverse(benchmark_assets)

# Construct a benchmark Alpha Model that provides
# 100% static allocation to the SPY ETF, with no rebalance

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()

# Performance Output

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() `

mhallsmoore commented 4 years ago

Hi @silent0506,

Did you manage to fix this issue?

Kind regards,

Mike.