From 689c5b477504012909e0da0301560080549b9bdc Mon Sep 17 00:00:00 2001 From: EvanHong99 <939778128@qq.com> Date: Sun, 3 Mar 2024 21:28:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=AF=B9resample=E7=9A=84=E6=95=B4?= =?UTF-8?q?=E4=B8=AA=E6=B5=81=E7=A8=8B=E8=BF=9B=E8=A1=8C=E4=BA=86=E6=8E=A2?= =?UTF-8?q?=E7=A9=B6=EF=BC=8C=E5=9C=A8example.py=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86'MyResampler'=E5=92=8C'MyBar'=EF=BC=8C?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E6=88=90=E5=8A=9F=E4=BD=BF=E5=BE=97=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=9C=A8resample=E4=B9=8B=E5=90=8E=E8=A2=ABstrategy?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=88=B0=E3=80=82=20bug:=20=E4=B8=8D?= =?UTF-8?q?=E7=9F=A5=E4=B8=BA=E4=BD=95=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=B9=B6?= =?UTF-8?q?=E6=9C=AA=E6=88=90=E5=8A=9F=E6=B1=82=E5=92=8C=EF=BC=8C=E7=94=9A?= =?UTF-8?q?=E8=87=B3baselines=E9=83=BD=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E6=B1=82=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 37c83965c..cf0bd17d2 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,11 @@ samples2/ datas/*.py .idea/ +.DS_Store +backtrader/.DS_Store +contrib/.DS_Store +samples/.DS_Store +/datas +/samples +/datas/ +/samples/ From ed7cd735a2be342d25e7f20fd23e166aae256dbe Mon Sep 17 00:00:00 2001 From: Chen Date: Wed, 17 Apr 2024 21:45:58 +0800 Subject: [PATCH 2/2] bug fix: cash short mode for future like assets --- backtrader/comminfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backtrader/comminfo.py b/backtrader/comminfo.py index 6bfd8e015..ece81921c 100644 --- a/backtrader/comminfo.py +++ b/backtrader/comminfo.py @@ -177,7 +177,7 @@ def get_margin(self, price): - Use param ``automargin`` * ``price`` if ``automargin > 0`` ''' if not self.p.automargin: - return self.p.margin + return price * self.p.margin elif self.p.automargin < 0: return price * self.p.mult @@ -192,9 +192,9 @@ def get_leverage(self): def getsize(self, price, cash): '''Returns the needed size to meet a cash operation at a given price''' if not self._stocklike: - return int(self.p.leverage * (cash // self.get_margin(price))) + return self.p.leverage * (cash / self.get_margin(price)) - return int(self.p.leverage * (cash // price)) + return self.p.leverage * (cash / price) def getoperationcost(self, size, price): '''Returns the needed amount of cash an operation would cost'''