I want my trades to be 1% of the initial balance of the account. #737
Unanswered
anderMartin92
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Try: class MyStrat(Strategy):
def init(self):
self._trade_max_cash = self.equity * .01 # 1% of initial cash
def next(self):
...
self.buy(..., size=int(self._trade_max_cash // self.data.Close[-1])) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I want my trades to be 1% of the initial balance of the account. Even with 0 commissions the results vary a lot. Here I leave the formula with which I calculate 1%.
`money = 1000000
def my_size(sl, signal):
ep = self.data.Close[-1]
stop_percenti = trendPorcent(ep, (ep-sl), signal)
position_size = (ep * (0.01 * money) / sl) / self.leverage
mysize = (position_size * 100 / money) / 100
return float(mysize)
bt = Backtest(df, MyStrat, cash = money, margin=1/50, commission=.000)`
The results of PnL that it returns are these:
If the initial balance is one million, they should generate a profit/loss of 10k (1%).
If I modify the commission to 0.002 it goes crazy and the result is this:
thank you for all!!
Beta Was this translation helpful? Give feedback.
All reactions