Hi Jared I'm afraid the problem is more serious than just a decimal rounding issue. I adjusted my effective leverage down to about 20% of what is full leverage and still have the margin errors when i go back to 2016, but not in 2017-2018.
I also noticed a straight equity algo that was posted by Jing Wu, which had backtesting back to 2008. I didn't inspect the calculation for weight allocation too closely but it was a strategy worked on by several traders. When I cloned it and ran the backtest I also saw lots of these margin errors, so effectively the orders were not placed because the system thought the portfolio wouldn't allow that amount of leverage. Again that could be erroneous weight calculation in the code but I thought it stranget hat no one else brought up that issue with the algo.
The data normalization mode looks like it might help for doing some calculations, but from my perspective this shouldn't affect the margin calculation. The backtester should accurately calculate the margin requirement no matter when kind of data I choose to use for the algorithm. I could be wrong about that though, and I will play around with that.
I'm pretty sure this illustrates is the problem:
All options contracts in historical data are based on normal prices. So back in 2016, I wanted to buy 10 contracts with a strike price of $20.00. That is equivalent to 1000 shares of underlying, which would be $20,000 of underlying. But I am proposing that the lean backtester is then using the adjusted historical price, which could be like $1000 dollars per share. If this is the case, the backtester is thinking that the underlying is 1000 shares at $1000 so it would require margin for $1,000,000 of underlying. Hence not allowing me to trade.
Using the adjust price for straight trading equities is OK, since in backtesting I also assume the historical price of the equity is the adjusted price. so to get $20,000 of exposure, with adjusted hist price of $1,000 I would only trade 20 shares, instead of 1000 shares at the real price of $20.00. But with the options contracts, using this adjusted price for margin requirement calculation isn't working.
Would it be possible to give an option in the brokerage model to completely disable all margin requirements? Obvioulsy this is not ideal but it would nice to be able to run a backtest without having to worry about the backtesting engine disallowing trades based on margin requirements.