Hi there, I am having trouble controlling leverage in the backtest and live trading since
context.account.buying_power (IB: BuyingPower) for IB Margin Account = Available Funds * 4. But the backtest value buying_power is set to infinity.
I have been trying something like this:
net_liquid=context.portfolio.portfolio_value
buying_power=context.account.available_funds*4
leverage= (buying_power/(net_liquid))
order_target_percent(sec, leverage)
But the result is different. I am wondering if anyone has any suggestions?