Back

T+1 and time increments

Is there an method already built in for incrementing by some time increment that takes into account when the market is open? 

For example, I sell a stock 2 hours after I buy it. This takes place even over the end of day and over weekends. So if I buy on Friday at 3pm, then I would sell it on Monday at 10:30AM. 

 

I could bulid one myself but was curious if it had already been implemented somewhere. 

Update Backtest








So I found this which describes regular schedules. 

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/ScheduledEventsAlgorithm.py

However, I'm still looking for the documentation on checking if a day is a trading day. I did find this 

https://www.quantconnect.com/forum/discussion/891/trading-days-vs-days

But it still doesn't quite work in Python. An example of this in python would be great. 

0

Not currently; we have similar code for days but not intraday timespans like that. We have a MarketOpen check you could use and then iterate forward in minute increments? This is how we do it for the History API.

https://github.com/QuantConnect/Lean/blob/1ccd33bef724af683d0e806f116ef22cfdac9cf4/Common/Time.cs#L398public static DateTime GetStartTimeForTradeBars(SecurityExchangeHours exchange, DateTime end, TimeSpan barSize, int barCount, bool extendedMarketHours)
{
if (barSize <= TimeSpan.Zero)
{
throw new ArgumentException("barSize must be greater than TimeSpan.Zero", "barSize");
}

var current = end.RoundDown(barSize);
for (int i = 0; i < barCount;)
{
var previous = current;
current = current - barSize;
if (exchange.IsOpen(current, previous, extendedMarketHours))
{
i++;
}
}
return current;
}
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.


I pieced together all the code logic to work. However I'm getting an order status of 3 on a market order that doesn't kick off an error or seem to get filled for some reason. 

0

Please chekout the docs, under Order Error Codes, to get meaning of order status:

Error Code Interpretation
-3 InsufficientBuyingPower - Not enough money to to submit order.
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.


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