From e6a643ec840e3c381e881ac288720a9dd069b746 Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Fatchurrahman Putra Danar Date: Sun, 4 Apr 2021 07:24:39 +0700 Subject: [PATCH 1/3] commission constraints for rebates --- backtesting/backtesting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index ce1ef57c..4a80bcf2 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -664,7 +664,7 @@ class _Broker: def __init__(self, *, data, cash, commission, margin, trade_on_close, hedging, exclusive_orders, index): assert 0 < cash, f"cash should be >0, is {cash}" - assert 0 <= commission < .1, f"commission should be between 0-10%, is {commission}" + assert -.1 <= commission < .1, f"commission should be between -10% (e.g. market-maker's rebates) and 10% (fees), is {commission}" assert 0 < margin <= 1, f"margin should be between 0 and 1, is {margin}" self._data: _Data = data self._cash = cash From 1114e09fc768a04dc8b04e37910a242c00ca1ffe Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Fatchurrahman Putra Danar Date: Sun, 4 Apr 2021 07:40:54 +0700 Subject: [PATCH 2/3] linter warning fix --- backtesting/backtesting.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index 4a80bcf2..8e9962be 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -664,7 +664,8 @@ class _Broker: def __init__(self, *, data, cash, commission, margin, trade_on_close, hedging, exclusive_orders, index): assert 0 < cash, f"cash should be >0, is {cash}" - assert -.1 <= commission < .1, f"commission should be between -10% (e.g. market-maker's rebates) and 10% (fees), is {commission}" + assert -.1 <= commission < .1, (f"commission should be between -10% " + "(e.g. market-maker's rebates) and 10% (fees), is {commission}") assert 0 < margin <= 1, f"margin should be between 0 and 1, is {margin}" self._data: _Data = data self._cash = cash From 7d907c6094a863d4fa296a1a11463a3c811a4d49 Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Fatchurrahman Putra Danar Date: Mon, 5 Apr 2021 06:26:22 +0700 Subject: [PATCH 3/3] assert linter warning --- backtesting/backtesting.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index 8e9962be..edb7be01 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -664,8 +664,9 @@ class _Broker: def __init__(self, *, data, cash, commission, margin, trade_on_close, hedging, exclusive_orders, index): assert 0 < cash, f"cash should be >0, is {cash}" - assert -.1 <= commission < .1, (f"commission should be between -10% " - "(e.g. market-maker's rebates) and 10% (fees), is {commission}") + assert -.1 <= commission < .1, \ + ("commission should be between -10% " + f"(e.g. market-maker's rebates) and 10% (fees), is {commission}") assert 0 < margin <= 1, f"margin should be between 0 and 1, is {margin}" self._data: _Data = data self._cash = cash