Hello, I've been trying really hard to understand the buying power calculation and SetHoldings(), I've searched this forum as well as the GitHub issues and still couldn't find what I want to know, I really hope you guys can help me.

As shown in the attached backtest, I call SetHoldings() and log various attributes, the logging result is shown below:

These are my questions:

1. Why is the initial buying power $100000 instead of $200000? I expected my buying power to be $200000 because my leverage is 2.

2. Why did my buying power become ~$50000 after buying the stock?

3. Why did the SetHoldings("WMT", 1) only buy 1556 shares of the stock instead of 1557? The cash was sufficient to buy 1557 shares and pay for the fees. The strange thing is that it bought one single share the next day.

Thanks a lot in advance!!

Author