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

Error #762

Closed
pepi99 opened this issue Dec 11, 2024 · 3 comments
Closed

Error #762

pepi99 opened this issue Dec 11, 2024 · 3 comments

Comments

@pepi99
Copy link

pepi99 commented Dec 11, 2024

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[186], line 8
      5 first_obs = np.datetime64('2024-06-01')
      7 am = arch_model(returns, vol='Garch', p=1, o=0, q=1, dist='Normal')
----> 8 res = am.fit(first_obs=first_obs, last_obs=last_obs)

File ~/Documents/sp&derivatives/price_analysis/.venv/lib/python3.12/site-packages/arch/univariate/base.py:641, in ARCHModel.fit(self, update_freq, disp, starting_values, cov_type, show_warning, first_obs, last_obs, tol, options, backcast)
    635 # Closed form is applicable when model has no parameters
    636 # Or when distribution is normal and constant variance
    637 has_closed_form = (
    638     v.closed_form and d.num_params == 0 and isinstance(v, ConstantVariance)
    639 )
--> 641 self._adjust_sample(first_obs, last_obs)
    643 resids = np.asarray(self.resids(self.starting_values()), dtype=float)
    644 self._check_scale(resids)

File ~/Documents/sp&derivatives/price_analysis/.venv/lib/python3.12/site-packages/arch/univariate/mean.py:677, in HARX._adjust_sample(self, first_obs, last_obs)
    671 def _adjust_sample(
    672     self,
    673     first_obs: Union[int, DateLike, None],
    674     last_obs: Union[int, DateLike, None],
    675 ) -> None:
    676     index = self._y_series.index
--> 677     _first_obs_index = cutoff_to_index(first_obs, index, 0)
    678     _first_obs_index += self._hold_back
    679     _last_obs_index = cutoff_to_index(last_obs, index, self._y.shape[0])

File ~/Documents/sp&derivatives/price_analysis/.venv/lib/python3.12/site-packages/arch/utility/array.py:278, in cutoff_to_index(cutoff, index, default)
    276 int_index = default
    277 if isinstance(cutoff, (str, dt.datetime, np.datetime64, Timestamp)):
--> 278     assert isinstance(index, DatetimeIndex)
    279     int_index = date_to_index(cutoff, index)
    280 elif isinstance(cutoff, int) or issubclass(cutoff.__class__, np.integer):

Code:

# last_obs = dt.datetime(2024, 6, 1)
# first_obs = dt.datetime(2023, 1, 1)
import numpy as np
last_obs = np.datetime64('2023-01-01')
first_obs = np.datetime64('2024-06-01')

am = arch_model(returns, vol='Garch', p=1, o=0, q=1, dist='Normal')
res = am.fit(first_obs=first_obs, last_obs=last_obs)
@bashtage
Copy link
Owner

What is returns? What is type(returns.index)?

@bashtage
Copy link
Owner

To be clear, when using dates, you must use a pandas DatetimeIndex.

@bashtage
Copy link
Owner

bashtage commented Jan 9, 2025

Goign to close since no response. I suggest checking that you have pandas DatetimeIndex on your data Series

@bashtage bashtage closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants