From a473d4c8cef06ac27b801aa8f016a8b90e12bab3 Mon Sep 17 00:00:00 2001 From: Adi Sai Date: Wed, 1 Mar 2023 23:37:33 -0500 Subject: [PATCH 1/2] Broker add deposit and withdraw functions --- backtesting/backtesting.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index 9c168703..e301d072 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -721,6 +721,16 @@ def __init__(self, *, data, cash, commission, margin, def __repr__(self): return f'' + + def deposit_cash(self, amount: float): + self._cash += amount + return self._cash + + def withdraw_cash(self, amount: float): + if amount > self._cash: + return self._cash + self.cash -= amount + return self._cash def new_order(self, size: float, From b9122deb660e166ee43ed58bb4c03fab4076e7a5 Mon Sep 17 00:00:00 2001 From: Adi Sai Date: Wed, 1 Mar 2023 23:41:29 -0500 Subject: [PATCH 2/2] Strategy add deposit and withdraw functions --- backtesting/backtesting.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index e301d072..4d276fad 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -74,6 +74,12 @@ def _check_params(self, params): "can be optimized or run with.") setattr(self, k, v) return params + + def deposit_cash(self, amount): + return self._broker.deposit_cash(amount) + + def withdraw_cash(self, amount): + return self._broker.withdraw_cash(amount) def I(self, # noqa: E743 func: Callable, *args,