This may be pretty simple but I've been searching for it and cant find it. How to round to nearest 100?
back ground: I'm working on a covered call strategy and want to purchase a certain % of the portfolio in a stock then sell covered calls on that amount. To make it easy I want to calculate the number of shares to buy, store that number and devide it by 100 to know the number of calls to sell. However, I dont know how to set holdings to a specific number of shares when the portfolio value should change over time (hopefully upwards :) ). My plan was to use the following:
quantity = self.CalculateOrderQuantity("IBM", 0.4)
Then round the quantity value, and I know how to round to decimal places but how can I round up or down to 100? Once I have that value then I can purchase that specific number of blocks of 100s of shares and can easily sell calls on that number as well.
Thanks,
David
Nico Xenox
Hey David Eldringhoff,
you could use the round function to round to the nearest 100.
or you use something like math.ceil, that will always round up on the 100
You can read more about them here
Best,
Nico
David Eldringhoff
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!