mhallsmoore / qstrader

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

Update examples #177

Closed mhallsmoore closed 7 years ago

mhallsmoore commented 7 years ago

This is a reasonably large update to remove old examples and update others to use the current API.

I've modified how the Backtest object works, but only in so much as to utilise default PositionSizer, Compliance, RiskManager etc objects so that the ***_backtest.py files are not cluttered with many class initialisations.

Be warned - this does change the Backtest API slightly! Perhaps the best way to test it is to head to the examples directory and look at "moving_average_cross_backtest.py" or "buy_and_hold_backtest.py", which now work with the updated API.

I also fixed an insidious bug that was causing backtest results to be non-deterministic. This happened because Pandas was stochastically sorting the Yahoo prices DataFrame. These prices were then being filtered into the queue in random order across runs.

TearsheetStatistics now also functions when no trades have been placed. Previously, an exception was generated if this was the case. In particular, the Buy-and-Hold example will now function under a tearsheet example.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-9.3%) to 54.696% when pulling 84b21486d464325bce254ddf104a28b712e670c0 on update_examples into 2714ae4b95b362e31a450cda1f0a711777659fce on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-9.2%) to 54.779% when pulling f0e428edb2e347bdb1c8f70a75be5dcc344b1b12 on update_examples into 2714ae4b95b362e31a450cda1f0a711777659fce on master.

mhallsmoore commented 7 years ago

I've just added some of the older Position fixes into this branch. There was an error in how the Realised PnL was being calculated. In addition, the Portfolio itself was miscalculating its equity value, based on the incorrect handling of the Realised PnL.

They have both been fixed in this update. @femtotrader's tests for the Position were also added in and now pass.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-7.5%) to 56.475% when pulling 57d3514bc454df0d373d53b5bf21e69a4bf3fbc6 on update_examples into 2714ae4b95b362e31a450cda1f0a711777659fce on master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-7.6%) to 56.349% when pulling 57d3514bc454df0d373d53b5bf21e69a4bf3fbc6 on update_examples into 2714ae4b95b362e31a450cda1f0a711777659fce on master.