Margin account simulation
Hi! At this point I wasn't able to open position larger then amount of cash on the account. Usually broker allow to open at least 2x cash. I was trying to use cerebro.broker.set_checksubmit(False), but unsuccessful.
Is there any way to simulate broker margin account i.e. ability to loan some money from broker?
Margin (aka leverage) is not supported. This is a conscious design decision.
There are ways to emulate it. For example:
- A custom commission scheme which reduces the cost of asset acquisition
Which means that more things can be bought with the same cash. See:
Thank you! It is pity. I'll try to play with commissions.
For the trading with the real broker (say IB), backtrader will not use leverage too? Or it is a limitation of the backtester only?
The configuration (Margin or not) of the account used with Interactive Brokers is not controlled by backtrader.
The backtester doesn't have a limitation. See what for example Interactive Broker offers you with the leverage with some assets:
- Futures: no leverage - either you have the money in the account for the guarantee or you can't operate
- Stocks: leverage - but market dependent
- Forex: greatet leverate as with stocks
From that simple view with just 3 different assets it should be clear that it is not the account what has the leverage but the assets (obviously there are accounts which doesn't offer leverage for any asset)
And that's the reason for the design of the internal broker. Blindly offering leverage for any asset type would simply mean that someone would be testing for example futures with the illusion that leverage is available, or forex with the limitations of the leverage applied to stocks.
As such, the proper way to do it is to make sure each asset gets the associated cash deduction level from the commission scheme applied to it.
The latest release of backtrader,
126.96.36.199, has added leverage.
Rather than having people subclassing
CommissionInfo, it is fully integrated into that hierarchy and with the broker. See the latest
BTFDblog post for a sample.
Deleted by author.