Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This error appears while training: ( ValueError: Parameter start received with timezone defined as 'UTC' although a Date must be timezone naive.) #296

Open
FatehMuhammad opened this issue May 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@FatehMuhammad
Copy link

Alpaca successfully connected
/usr/local/lib/python3.10/dist-packages/finrl/meta/data_processors/processor_alpaca.py:52: FutureWarning: Timedelta.delta is deprecated and will be removed in a future version.
if pd.Timedelta(time_interval).delta < day_delta:

ValueError Traceback (most recent call last)
in <cell line: 1>()
----> 1 train(start_date = '2022-08-30',
2 end_date = '2022-09-08',
3 ticker_list = ticker_list,
4 data_source = 'alpaca',
5 time_interval= '1Min',

7 frames
in train(start_date, end_date, ticker_list, data_source, time_interval, technical_indicator_list, drl_lib, env, model_name, if_vix, **kwargs)
29 dp = DataProcessor(data_source, **kwargs)
30 data = dp.download_data(ticker_list, start_date, end_date, time_interval)
---> 31 data = dp.clean_data(data)
32 data = dp.add_technical_indicator(data, technical_indicator_list)
33 if if_vix:

/usr/local/lib/python3.10/dist-packages/finrl/meta/data_processor.py in clean_data(self, df)
44
45 def clean_data(self, df) -> pd.DataFrame:
---> 46 df = self.processor.clean_data(df)
47
48 return df

/usr/local/lib/python3.10/dist-packages/finrl/meta/data_processors/processor_alpaca.py in clean_data(self, df)
73 df = df[df.timestamp != time]
74
---> 75 trading_days = self.get_trading_days(start=self.start, end=self.end)
76 # produce full timestamp index
77 times = []

/usr/local/lib/python3.10/dist-packages/finrl/meta/data_processors/processor_alpaca.py in get_trading_days(self, start, end)
296 def get_trading_days(self, start, end):
297 nyse = tc.get_calendar("NYSE")
--> 298 df = nyse.sessions_in_range(
299 pd.Timestamp(start, tz=pytz.UTC), pd.Timestamp(end, tz=pytz.UTC)
300 )

/usr/local/lib/python3.10/dist-packages/exchange_calendars/exchange_calendar.py in sessions_in_range(self, start, end, _parse)
2197 Sessions from start through end.
2198 """
-> 2199 slc = self._get_sessions_slice(start, end, _parse)
2200 return self.sessions[slc]
2201

/usr/local/lib/python3.10/dist-packages/exchange_calendars/exchange_calendar.py in _get_sessions_slice(self, start, end, _parse)
2174 def _get_sessions_slice(self, start: Date, end: Date, _parse=True) -> slice:
2175 """Slice representing a range of sessions."""
-> 2176 start, end = self._parse_start_end_dates(start, end, _parse)
2177 slice_start = self.sessions_nanos.searchsorted(start.value, side="left")
2178 slice_end = self.sessions_nanos.searchsorted(end.value, side="right")

/usr/local/lib/python3.10/dist-packages/exchange_calendars/exchange_calendar.py in _parse_start_end_dates(self, start, end, _parse)
2170 if not _parse:
2171 return start, end
-> 2172 return parse_date(start, "start", self), parse_date(end, "end", self)
2173
2174 def _get_sessions_slice(self, start: Date, end: Date, _parse=True) -> slice:

/usr/local/lib/python3.10/dist-packages/exchange_calendars/calendar_helpers.py in parse_date(date, param_name, calendar, raise_oob)
376
377 if ts.tz is not None:
--> 378 raise ValueError(
379 f"Parameter {param_name} received with timezone defined as '{ts.tz.zone}'"
380 f" although a Date must be timezone naive."

ValueError: Parameter start received with timezone defined as 'UTC' although a Date must be timezone naive.

@FatehMuhammad
Copy link
Author

I think the error message indicates that the 'start' parameter of the method sessions_in_range is received with timezone 'UTC', but it is expecting a timezone naive datetime object. In Python, a timezone naive datetime object is a datetime without an associated timezone.

@FatehMuhammad
Copy link
Author

The problem is occurring here:

df = nyse.sessions_in_range(
pd.Timestamp(start, tz=pytz.UTC), pd.Timestamp(end, tz=pytz.UTC)
)

To fix this error, I tried creating timezone naive Timestamps by not passing the tz argument to the pd.Timestamp function, but didn't resolve the issue.

df = nyse.sessions_in_range(
pd.Timestamp(start), pd.Timestamp(end)
)

@YangletLiu YangletLiu added the bug Something isn't working label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants