Back

Understanding buying power calculation and SetHoldings()

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!!

Update Backtest








very good question!

but very very bad approach!

1 & 2) read the documentation my friend:

SetHoldings sets a fraction of unlevered equity. e.g. If you have 2x available leverage,
and SetHoldings to 1.0 the algorithm will use 1.0 of your available buying power.
To maximize buying power in this case you would make the SetHoldings fractions total 2.0.

0

in the algorithm lab click on the left API TAB and check the portfolio section following methods:

GetBuyingPower

GetMarginRemaining

MarginRemaining

..

0

Mochunhei, As Michael said, 'SetHoldings('WMT', 1.0)' keeps maintaining the weight of the stock holding to the fixed 100 pecrent of portfolio (1.0x). Your example algo will not use up entire leverage (2.0x) because of 'SetHoldings('WMT', 1.0). If you want to use all of margin you put, you should change it to 'SetHoldings('WMT', 2.0). And also, you need to change 'Resolution.Daily' to 'Minute'  or use 'Schedule' function if you want to trade more frequently.
Or you can approach different way: Change your order type to a quantity based one (e.g. MarketOrder, and so on). I attached a sample algo where it uses up all the margin available in two trades (See 'Total Cost' in the 'Logs'.). It will buy 1.0x of total  portfoio value each time until it consumes all the margin you set. Don't be bothered by 'GetBuyingPower'. Once you set leverage, you don't have to worry about the 'BuyingPower'.
One thing you should be careful of is that you should watch the leverage because you might get a margin call if your portfolio value drops significantly.

BTW, I think 'SetHoldings' method is a very good and convenient way to control your leverage level to a certain level. Hope this helps. Thank you.

0


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed