Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detached #494

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -69,3 +69,11 @@ samples2/
datas/*.py

.idea/
.DS_Store
backtrader/.DS_Store
contrib/.DS_Store
samples/.DS_Store
/datas
/samples
/datas/
/samples/
6 changes: 3 additions & 3 deletions backtrader/comminfo.py
Original file line number Diff line number Diff line change
@@ -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'''