AI4Finance-Foundation / FinRL-Meta

FinRL­-Meta: Dynamic datasets and market environments for FinRL.
https://ai4finance.org
MIT License
1.17k stars 556 forks source link

FinRL_PaperTrading_Demo.ipynb: TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp #287

Open captnemo26 opened 1 year ago

captnemo26 commented 1 year ago

I keep getting this error. All my Alpaca credentials are correct and that is the only thing i have touched in the notebook. Any help on what to do is appreciated.

data = DP.clean_data(data) data = DP.add_technical_indicator(data, INDICATORS) data = DP.add_vix(data)


TypeError Traceback (most recent call last) /usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py in _validate_comparison_value(self, other) 563 try: --> 564 self._check_compatible_with(other) 565

24 frames /usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimes.py in _check_compatible_with(self, other) 521 def _check_compatible_with(self, other) -> None: --> 522 if other is NaT: 523 return

/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimes.py in _assert_tzawareness_compat(self, other) 743 # pd.NaT quacks both aware and naive --> 744 pass 745 elif self.tz is None:

TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.

The above exception was the direct cause of the following exception:

InvalidComparison Traceback (most recent call last) /usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py in _cmp_method(self, other, op) 933 --> 934 try: 935 other = self._validate_comparison_value(other)

/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py in _validate_comparison_value(self, other) 566 except (TypeError, IncompatibleFrequency) as err: --> 567 # e.g. tzawareness mismatch 568 raise InvalidComparison(other) from err

InvalidComparison: 2003-04-13 00:00:00+00:00

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) in <cell line: 1>() ----> 1 data = DP.clean_data(data) 2 data = DP.add_technical_indicator(data, INDICATORS) 3 data = DP.add_vix(data)

/usr/local/lib/python3.9/site-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.9/site-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.9/site-packages/finrl/meta/data_processors/processor_alpaca.py in get_trading_days(self, start, end) 295 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)

/usr/local/lib/python3.9/site-packages/exchange_calendars/calendar_utils.py in get_calendar(self, name, start, end, side) 284 285 cached = self._get_cached_factory_output(name, kwargs) --> 286 return cached if cached is not None else self._fabricate(name, kwargs) 287 288 def get_calendar_names(

/usr/local/lib/python3.9/site-packages/exchange_calendars/calendar_utils.py in _fabricate(self, name, kwargs) 180 except KeyError as e: 181 raise InvalidCalendarName(calendar_name=name) from e --> 182 calendar = factory(kwargs) 183 self._factory_output_cache[name] = (calendar, kwargs) 184 return calendar

/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py in init(self, start, end, side) 291 # Series mapping sessions with nonstandard opens/closes. 292 _special_opens = self._calculate_special_opens(start, end) --> 293 _special_closes = self._calculate_special_closes(start, end) 294 295 # Overwrite the special opens and closes on top of the standard ones.

/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py in _calculate_special_closes(self, start, end) 2593 2594 def _calculate_special_closes(self, start, end): -> 2595 return self._special_dates( 2596 self.special_closes, 2597 self.special_closes_adhoc,

/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py in _special_dates(self, calendars, ad_hoc_dates, start_date, end_date) 2542 """ 2543 # List of Series for regularly-scheduled times. -> 2544 regular = [ 2545 scheduled_special_times( 2546 calendar,

/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py in (.0) 2543 # List of Series for regularly-scheduled times. 2544 regular = [ -> 2545 scheduled_special_times( 2546 calendar, 2547 start_date,

/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py in scheduled_special_times(calendar, start, end, time, tz) 2840 time (as a UTC Timestamp). 2841 """ -> 2842 days = calendar.holidays(start, end) 2843 return pd.Series( 2844 index=pd.DatetimeIndex(days, tz=UTC),

/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py in holidays(self, start, end, return_name) 456 # get them again 457 if self._cache is None or start < self._cache[0] or end > self._cache[1]: --> 458 pre_holidays = [ 459 rule.dates(start, end, return_name=True) for rule in self.rules 460 ]

/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py in (.0) 457 if self._cache is None or start < self._cache[0] or end > self._cache[1]: 458 pre_holidays = [ --> 459 rule.dates(start, end, return_name=True) for rule in self.rules 460 ] 461 if pre_holidays:

/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py in dates(self, start_date, end_date, return_name) 284 ) 285 holiday_dates = holiday_dates[ --> 286 (holiday_dates >= filter_start_date) & (holiday_dates <= filter_end_date) 287 ] 288 if return_name:

/usr/local/lib/python3.9/site-packages/pandas/core/ops/common.py in new_method(self, other) 79 other = item_from_zerodim(other) 80 ---> 81 return method(self, other) 82 83 return new_method

/usr/local/lib/python3.9/site-packages/pandas/core/arraylike.py in ge(self, other) 58 @unpack_zerodim_and_defer("ge") 59 def ge(self, other): ---> 60 return self._cmp_method(other, operator.ge) 61 62 # -------------------------------------------------------------

/usr/local/lib/python3.9/site-packages/pandas/core/indexes/base.py in _cmp_method(self, other, op) 6769 6770 elif isinstance(self._values, ExtensionArray): -> 6771 result = op(self._values, other) 6772 6773 elif is_object_dtype(self.dtype) and not isinstance(self, ABCMultiIndex):

/usr/local/lib/python3.9/site-packages/pandas/core/ops/common.py in new_method(self, other) 79 other = item_from_zerodim(other) 80 ---> 81 return method(self, other) 82 83 return new_method

/usr/local/lib/python3.9/site-packages/pandas/core/arraylike.py in ge(self, other) 58 @unpack_zerodim_and_defer("ge") 59 def ge(self, other): ---> 60 return self._cmp_method(other, operator.ge) 61 62 # -------------------------------------------------------------

/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py in _cmp_method(self, other, op) 934 try: 935 other = self._validate_comparison_value(other) --> 936 except InvalidComparison: 937 return invalid_comparison(self, other, op) 938

/usr/local/lib/python3.9/site-packages/pandas/core/ops/invalid.py in invalid_comparison(left, right, op) 34 else: 35 typ = type(right).name ---> 36 raise TypeError(f"Invalid comparison between dtype={left.dtype} and {typ}") 37 return res_values 38

TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp