TimeZone Mis-Match Between Start and End Times
Closed this issue · 0 comments
Expected Behavior
This algorithm runs without error
class MyAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2010, 1, 1)
self.schedule.on(
FuncDateRule(name="name", get_dates_function=self._get_dates),
self.time_rules.at(0, 1),
lambda: None
)
def _get_dates(self, start_date, end_date):
start_date <= end_date
return []
Actual Behavior
We get
[ERROR] FATAL UNHANDLED EXCEPTION:Engine.Run(): Error running algorithm Python.Runtime.PythonException: can't compare offset-naive and offset-aware datetimes, File "/QuantConnect/backtesting/./cache/algorithm/project/main.py", line 16, in _get_dates, start_date <= end_date, at Python.Runtime.PythonException.ThrowLastAsClrException() in src
untimePythonException.cs:line 52, at Python.Runtime.Dispatcher.TrueDispatch(Object[] args) in src
untimeDelegateManager.cs:line 346, at Python.Runtime.Dispatcher.Dispatch(Object[] args) in src
untimeDelegateManager.cs:line 210, at __System_Func3[[System_DateTime, System_Private_CoreLib, Version=6_0_0_0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System_DateTime, System_Private_CoreLib, Version=6_0_0_0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System_Collections_Generic_IEnumerable
1[[System_DateTime, System_Private_CoreLib, Version=6_0_0_0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
To avoid this error, I need to use
start_date.replace(tzinfo=None) <= end_date
Potential Solution
https://github.com/QuantConnect/Lean/blob/master/Common/Scheduling/ScheduleManager.cs#L284
Should be Time.EndOfTime.ToUniversalTime()
Reproducing the Problem
Run algorithm above
System Information
QC Cloud
Checklist
- I have completely filled out this template
- I have confirmed that this issue exists on the current
master
branch - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue