Set position to 5% of buying power; Python

In python I want to set my option position to 5% of the buying power. I was considering using a loop with an increasing mulitple on every loop until the mulitiple * the contracts ask price is close to 5% of my buying power. Then use that multiple as the number of contracts to purchase However, I can't seem to find the funciton/class in python that will give me my account's buying power.

Update Backtest

In the algorithm lab is on the left side a API tab.

Click on it and extend Portfolio. There is what you need.

Also: below portfolio is Setholdings. take a look at that too.

and in the community section on the right side is a link to some example algos.....go through some :)


Thanks for the pointer! SetHoldings looks like the perfect solution. However, it seems that it places orders based on market orders. Is there a way to have setHoldings place the limit orders based on the option's ask price? Or can SeHoldings() return a value so I can use it to calculate the number of contracts to buy, However, I doubt I can do this because the API states that the return is system.void


Hi Pual,

You could use 

quantity = self.CalculateOrderQuantity(symbol, percentage)
self.LimitOrder(symbol, int(quantity), limitPrice)

Thanks Jing! I will see if this works


Update Backtest


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.


This discussion is closed