From 53af4c0464d328e0f14b4f7604b56885a8b917c2 Mon Sep 17 00:00:00 2001 From: Camilo1704 Date: Wed, 25 Mar 2020 13:11:45 -0300 Subject: [PATCH] cash calculations modified --- backtester/backtester.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backtester/backtester.py b/backtester/backtester.py index 2da7d2b..02864fb 100644 --- a/backtester/backtester.py +++ b/backtester/backtester.py @@ -177,7 +177,7 @@ class Backtest: # We simulate a sell of the stock positions and then a rebuy. # This would **not** work if we added transaction fees. - self.current_cash += stock_capital + self.current_cash = stocks_allocation + total_capital * self.allocation['cash'] self._buy_stocks(stocks, stocks_allocation, sma_days) # exit/enter contracts @@ -332,6 +332,7 @@ class Backtest: options (pd.DataFrame): Options data for the current time step. options_allocation (float): Capital amount allocated to options. """ + self.current_cash += options_allocation # Remove contracts already in inventory inventory_contracts = pd.concat(