Closed mhallsmoore closed 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.
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.