Trying to have algorithm adjust / rebalance holdings at close of each day. However, the code I am using to try to force this is not working as expected:
if (DateTime.Now.TimeOfDay <= System.TimeSpan.Parse("15:45:00")) return;
Is there a better way to do this? Perhaps I could use MarketOnClose orders, however, because of the daily rebalancing, using SetHoldings is a very convenient way to define what I am trying to do.
Michael Handschuh
sampledToday = Time;
Also, it appears you're comparing your timespan again with DateTime.Now instead of the algorithm's Time property. The last thing I modified was setting your custom data to use fill forward behavior. This will copy the daily data onto the minute bars. I've also defined the exchange property so it doesn't perform fill forward over weekends and during not equity trading hours. I've modified and attached the algorithm. Let me know if you have further questions on algorithm Time.Reuben
Michael Handschuh
public int GetSetHoldingsOrderQuantity(symbol, decimal targetPercentage) This way you could call the above function and use the result to submit any order type.
Reuben
Reuben
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!