Forex trading leverage settings in backtrader
BernardLin last edited by
Hi, @backtrader @ab_trader , I am trying to backtest a forex trading strategy on backtrader, I read the Docs and it seems that the go-to method is cerebro.broker.setcommission(). I would like to trade forex with a 200 leverage, however, when I set cerebro.broker.setcommission(leverage=200) or cerebro.broker.setcommission(margin=0.05). there was no change to my backtest results. The only notable change happened when I set cerebro.broker.setcommission(mult=200), but @ab_trader you specified in https://community.backtrader.com/topic/729/difference-between-leverage-and-multi/2 that mult is usually not 1/margin, so how should I set it up？
Ｉalso see in https://www.backtrader.com/docu/user-defined-commissions/commission-schemes-subclassing.html that "margin=2000 # Margin is needed for futures-like instruments", does that mean I don't need to designate a margin for forex? So it is only "mult" then?
It would seem you are simply changing settings at random. My personal advice is that you really read what those things mean. A quick summary:
leverage: allows you to buy more of an asset than you have in cash
multiplier: multiplies the winnings/losses of an asset, but it won't let you buy more of the asset.
margin: it is for futures, which regardless of the notional value have a real value which is the margin and it is what your account has to have in order to keep you trading and to avoid your broker getting you out of the market.
when I set cerebro.broker.setcommission(leverage=200) or cerebro.broker.setcommission(margin=0.05). there was no change to my backtest results
As expected. If you don't buy/sell more it doesn't matter how much leverage you use. But we don't know what you are doing, it's only a guess.
BernardLin last edited by BernardLin
Ah, many thanks! I will look again at the difference between the terms in depth!
A new question just hit me, to further build up on this question. It seems that your reply implies that backtrader takes the asset class by default as shares or futures which are denominated in USD. What if I am trading forex pairs? I guess it works the same way for currency pairs like EURUSD as the price is denominated also in USD. But what if I am trading USDCHF, USDJPY or USDCHN? These pairs are denominated in other currencies other than USD, yet my base currency is still USD. This seems to pose an issue, do you have any suggestions how I can solve this? Much gratitude for your help!