Back

Not constant Time using self.UtcTime

Hey all,

I try to create an intraday trading strategy, thus, every EOD I would like to Liquidate my portfolio, 

Using Schedule events :      

self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("SPY", 1) , Action(self.EOD))


def EOD(self):
self.Log("EOD: Fired at : {0}".format(self.UtcTime))
self.Liquidate()

and in the alpha itself, I would like to perform a logic only at the first minute of a trading day :


START_TIME = datetime.time(14, 30, 0)
END_TIME = datetime.time(14, 31, 0)


# AT THE ALPHA :
def Update(self, algorithm, data):

if not self.should_get_updates(algorithm):
return []
#Rest of the logic here 

return insights


def should_get_updates(self,algorithm):
if time_in_range(START_TIME,END_TIME, datetime.time(algorithm.UtcTime.hour,algorithm.UtcTime.minute, 0) ):
algorithm.Debug(f'[should_get_updates] - return True to : {algorithm.UtcTime }')

return True
else:
return False


def time_in_range(start, end, x):
"""Return true if x is in the range [start, end]"""
if start <= end:
return start <= x < end
else:
return start <= x or x < end

And actually, it works fine except periods in the year when the EOD and SOD are changed:

71234_1564560735.jpg

 

When checking Wikipedia:

71234_1564560799.jpg

Does the UTC time suppose to be changed during the year?

is there any way to emit insights using AlphaModel,Update with external interrupt logic?

 I tried to call AlphaModel.Update but seems like the portfolio construction didn't like that and wasn't affected at all

THANKS for the helpers
 

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.


The market trades New York time - due to daylight saving the UTC offset will change twice every year, yes. It's not UTC that changes, it's the offset against UTC that changes.

You can change the timezone your algorithm operates in using self.SetTimeZone(). It's probably a good idea to keep the algo timezone the same as the market timezone.

1

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