U
    ÃmœdÊ  ã                   @   s‚  d dl mZmZmZ d dlmZmZ d dlZd dl	m
Z
mZmZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZ d dlmZmZmZmZ d dlm Z  eejej!ej"f Z#ee$ej%f Z&d	Z'G d
d„ deƒZ(G dd„ de(eƒZ)G dd„ de)ƒZ*G dd„ de(ƒZ+G dd„ de(eƒZ,G dd„ de,ƒZ-G dd„ de(eƒZ.G dd„ de.e,ƒZ/G dd„ de.ƒZ0G dd„ de.e)ƒZ1G dd„ dƒZ2dS ) é    )ÚAppenderÚis_int_indexÚto_numpy)ÚABCÚabstractmethodN)ÚHashableÚListÚOptionalÚSequenceÚSetÚTupleÚTypeÚUnion)Úqr)Úd_or_f)Ú	bool_likeÚ
float_likeÚrequired_int_likeÚstring_like)Úfreq_to_periodz�start is less than the first observation in the index. Values can only be created for observations after the start of the index.
c                   @   s  e Zd ZdZdZeedœdd„ƒZee	e
 ejdœdd„ƒZedee	e
 ee	e
  ejd
œdd„ƒZeedœdd„ƒZedœdd„Zeeee
df dœdd„ƒƒZee	e
 ejdœdd„ƒZedejeee	e
  ejdœdd„ƒZedœdd„Zeedœdd„Zd	S ) ÚDeterministicTermz/Abstract Base Class for all Deterministic TermsF©Úreturnc                 C   s   | j S )z?Flag indicating whether the values produced are dummy variables)Ú	_is_dummy©Úself© r   úV/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/tsa/deterministic.pyÚis_dummy$   s    zDeterministicTerm.is_dummy©Úindexr   c                 C   s   dS )aR  
        Produce deterministic trends for in-sample fitting.

        Parameters
        ----------
        index : index_like
            An index-like object. If not an index, it is converted to an
            index.

        Returns
        -------
        DataFrame
            A DataFrame containing the deterministic terms.
        Nr   ©r   r    r   r   r   Ú	in_sample)   s    zDeterministicTerm.in_sampleN©Ústepsr    Úforecast_indexr   c                 C   s   dS )a1  
        Produce deterministic trends for out-of-sample forecasts

        Parameters
        ----------
        steps : int
            The number of steps to forecast
        index : index_like
            An index-like object. If not an index, it is converted to an
            index.
        forecast_index : index_like
            An Index or index-like object to use for the forecasts. If
            provided must have steps elements.

        Returns
        -------
        DataFrame
            A DataFrame containing the deterministic terms.
        Nr   )r   r$   r    r%   r   r   r   Úout_of_sample:   s    zDeterministicTerm.out_of_samplec                 C   s   dS )z.A meaningful string representation of the termNr   r   r   r   r   Ú__str__U   s    zDeterministicTerm.__str__c                 C   s   t | ƒjf}t|| j ƒS ©N)ÚtypeÚ__name__ÚhashÚ_eq_attr)r   Únamer   r   r   Ú__hash__Y   s    zDeterministicTerm.__hash__.c                 C   s   dS )z9tuple of attributes that are used for equality comparisonNr   r   r   r   r   r,   ]   s    zDeterministicTerm._eq_attrc                 C   s>   t | tjƒr| S zt | ¡W S  tk
r8   tdƒ‚Y nX d S )Nz*index must be a pandas Index or index-like)Ú
isinstanceÚpdÚIndexÚ	ExceptionÚ	TypeError©r    r   r   r   Ú_index_likeb   s    zDeterministicTerm._index_like)r    r$   r%   r   c           
      C   sÌ  |dk	rPt  |¡}t|tjƒs"t‚|jd |krLtd|jd › d|› d�ƒ‚|S t| tjƒrvtj	| d d || j
d�S t| tjƒr¸| j
dk	r¸tj| d | j
d	d
�d }tj|| j
|d
�S t| tjƒ�rHt| tjƒsÖt‚z| j}| j}W nD tk
�r*   t| ƒdk�r| d | d  nd}| d | }Y nX |||  }tj|||d�S t| ƒ�r’t t | ¡dk¡�r’t | d d | d | d ¡}t |¡S ddl}|jdtd	d� | jd }	t |	d |	| d ¡S )zExtend the forecast indexNr   z(The number of values in forecast_index (z) must match steps (z).éÿÿÿÿé   ©ÚperiodsÚfreqé   ©r:   r9   éþÿÿÿ©ÚstepzÃOnly PeriodIndexes, DatetimeIndexes with a frequency set, RangesIndexes, and Index with a unit increment support extending. The index is set will contain the position relative to the data length.)Ú
stacklevel)r   r5   r/   r0   r1   ÚAssertionErrorÚshapeÚ
ValueErrorÚPeriodIndexÚperiod_ranger:   ÚDatetimeIndexÚ
date_rangeÚ
RangeIndexr?   ÚstopÚAttributeErrorÚlenr   ÚnpÚallÚdiffÚarangeÚwarningsÚwarnÚUserWarning)
r    r$   r%   Znext_obsr?   ÚstartrI   Zidx_arrrP   Únobsr   r   r   Ú_extend_indexk   sL    
ÿ
  ÿ
"  
ú
zDeterministicTerm._extend_indexc                 C   s   |   ¡ dt| ƒd›� S )Nz at 0xÚ0x)r'   Úidr   r   r   r   Ú__repr__ž   s    zDeterministicTerm.__repr__)Úotherr   c                 C   sN   t |t| ƒƒrF| j}|j}t|ƒt|ƒkr.dS tdd„ t||ƒD ƒƒS dS d S )NFc                 S   s   g | ]\}}||k‘qS r   r   )Ú.0ÚaÚbr   r   r   Ú
<listcomp>§   s     z,DeterministicTerm.__eq__.<locals>.<listcomp>)r/   r)   r,   rK   rM   Úzip)r   rY   Zown_attrZoth_attrr   r   r   Ú__eq__¡   s    zDeterministicTerm.__eq__)N)N)r*   Ú
__module__Ú__qualname__Ú__doc__r   ÚpropertyÚboolr   r   r
   r   r0   Ú	DataFramer"   Úintr	   r&   Ústrr'   r.   r   r,   Ústaticmethodr1   r5   rU   rX   Úobjectr_   r   r   r   r   r      s@    ü
û ý
ü2r   c                   @   s€   e Zd ZdZdeeddœdd„Zeedœd	d
„ƒZeedœdd„ƒZ	ee
e dœdd„ƒZejejdœdd„Zedœdd„ZdS )ÚTimeTrendDeterministicTermz:Abstract Base Class for all Time Trend Deterministic TermsTr   N©ÚconstantÚorderr   c                 C   s   t |dƒ| _t|dƒ| _d S )Nrl   rm   )r   Ú	_constantr   Ú_order©r   rl   rm   r   r   r   Ú__init__¯   s    z#TimeTrendDeterministicTerm.__init__r   c                 C   s   | j S )z+Flag indicating that a constant is included)rn   r   r   r   r   rl   ³   s    z#TimeTrendDeterministicTerm.constantc                 C   s   | j S )zOrder of the time trend©ro   r   r   r   r   rm   ¸   s    z TimeTrendDeterministicTerm.orderc                 C   sb   g }ddddœ}| j r | d¡ td| jd ƒD ],}||krL| || ¡ q0| d|› �¡ q0|S )NÚtrendZtrend_squaredZtrend_cubed)r7   r;   é   Úconstr7   ztrend**)rn   ÚappendÚrangero   )r   ÚcolumnsZtrend_namesÚpowerr   r   r   Ú_columns½   s    
z#TimeTrendDeterministicTerm._columns©Úlocsr   c                 C   sb   t | jƒ| j }t |d|f¡}tjd|ft d�}t d| jd ¡|dt | jƒd …f< ||C }|S )Nr7   ©Zdtyper   )rf   rn   ro   rL   ZtileÚzerosrO   )r   r|   ZntermsÚtermsry   r   r   r   Ú
_get_termsÊ   s    $z%TimeTrendDeterministicTerm._get_termsc                 C   sP   g }| j r| d¡ | jr0| d| jd › �¡ |s:dg}d |¡}d|› d�S )NÚConstantzPowers 1 to r7   ÚEmptyú,z
TimeTrend(ú))rn   rv   ro   Újoin)r   r   Z	terms_strr   r   r   r'   Ò   s    

z"TimeTrendDeterministicTerm.__str__)Tr   )r*   r`   ra   rb   rd   rf   rq   rc   rl   rm   r   rg   rz   rL   Úndarrayr€   r'   r   r   r   r   rj   ¬   s   rj   c                       sÀ   e Zd ZdZdeeddœ‡ fdd„Zeed dœd	d
„ƒZ	e
ejjƒeee ejf ejdœdd„ƒZe
ejjƒdeeee ejf eee  ejdœdd„ƒZeeedf dœdd„ƒZ‡  ZS )Ú	TimeTrendao  
    Constant and time trend determinstic terms

    Parameters
    ----------
    constant : bool
        Flag indicating whether a constant should be included.
    order : int
        A non-negative int containing the powers to include (1, 2, ..., order).

    See Also
    --------
    DeterministicProcess
    Seasonality
    Fourier
    CalendarTimeTrend

    Examples
    --------
    >>> from statsmodels.datasets import sunspots
    >>> from statsmodels.tsa.deterministic import TimeTrend
    >>> data = sunspots.load_pandas().data
    >>> trend_gen = TimeTrend(True, 3)
    >>> trend_gen.in_sample(data.index)
    Tr   Nrk   c                    s   t ƒ  ||¡ d S r(   )Úsuperrq   rp   ©Ú	__class__r   r   rq   ù   s    zTimeTrend.__init__)rs   r   c                 C   s4   |  d¡}d}d|krd}nd|kr(d}| ||d�S )aY  
        Create a TimeTrend from a string description.

        Provided for compatibility with common string names.

        Parameters
        ----------
        trend : {"n", "c", "t", "ct", "ctt"}
            The string representation of the time trend. The terms are:

            * "n": No trend terms
            * "c": A constant only
            * "t": Linear time trend only
            * "ct": A constant and a time trend
            * "ctt": A constant, a time trend and a quadratic time trend

        Returns
        -------
        TimeTrend
            The TimeTrend instance.
        Úcr   Úttr;   Útr7   ©rl   rm   ©Ú
startswith)Úclsrs   rl   rm   r   r   r   Úfrom_stringü   s    
zTimeTrend.from_stringr   c                 C   sR   |   |¡}|jd }tjd|d tjd�d d …d f }|  |¡}tj|| j|d�S ©Nr   r7   r}   ©rx   r    )	r5   rB   rL   rO   Údoubler€   r0   re   rz   )r   r    rT   r|   r   r   r   r   r"     s
    

"
zTimeTrend.in_sampler#   c                 C   sh   |   |¡}|jd }|  |||¡}tj|d || d tjd�d d …d f }|  |¡}tj|| j	|d�S r“   )
r5   rB   rU   rL   rO   r•   r€   r0   re   rz   )r   r$   r    r%   rT   Úfcast_indexr|   r   r   r   r   r&   %  s    

*
zTimeTrend.out_of_sample.r   c                 C   s   | j | jfS r(   )rn   ro   r   r   r   r   r,   3  s    zTimeTrend._eq_attr)Tr   )N)r*   r`   ra   rb   rd   rf   rq   Úclassmethodrg   r’   r   r   r"   r   r
   r   r0   r1   re   r&   r	   rc   r   r,   Ú__classcell__r   r   r‰   r   r‡   Þ   s$   
þ	
 ü
ûr‡   c                   @   s  e Zd ZdZdZdeeddœdd„Zeedœd	d
„ƒZeedœdd„ƒZ	e
eee ejejf d dœdd„ƒZeeedf dœdd„ƒZedœdd„Zeee dœdd„ƒZeejjƒeee ejf ejdœdd„ƒZeejjƒdeeee ejf eee  ejdœdd„ƒZdS )ÚSeasonalitya   
    Seasonal dummy deterministic terms

    Parameters
    ----------
    period : int
        The length of a full cycle. Must be >= 2.
    initial_period : int
        The seasonal index of the first observation. 1-indexed so must
        be in {1, 2, ..., period}.

    See Also
    --------
    DeterministicProcess
    TimeTrend
    Fourier
    CalendarSeasonality

    Examples
    --------
    Solar data has an 11-year cycle

    >>> from statsmodels.datasets import sunspots
    >>> from statsmodels.tsa.deterministic import Seasonality
    >>> data = sunspots.load_pandas().data
    >>> seas_gen = Seasonality(11)
    >>> seas_gen.in_sample(data.index)

    To start at a season other than 1

    >>> seas_gen = Seasonality(11, initial_period=4)
    >>> seas_gen.in_sample(data.index)
    Tr7   N)ÚperiodÚinitial_periodr   c                 C   sL   t |dƒ| _t |dƒ| _|dk r(tdƒ‚d| j  kr>|ksHn tdƒ‚d S )Nrš   r›   r;   zperiod must be >= 2r7   z-initial_period must be in {1, 2, ..., period})r   Ú_periodÚ_initial_periodrC   )r   rš   r›   r   r   r   rq   ]  s     ÿzSeasonality.__init__r   c                 C   s   | j S )zThe period of the seasonality©rœ   r   r   r   r   rš   g  s    zSeasonality.periodc                 C   s   | j S )z+The seasonal index of the first observation)r�   r   r   r   r   r›   l  s    zSeasonality.initial_periodr   c                 C   sh   |   |¡}t|tjƒr|j}n(t|tjƒr>|jr6|jn|j}ntdƒ‚|dkrVtdƒ‚t	|ƒ}| |d�S )aF  
        Construct a seasonality directly from an index using its frequency.

        Parameters
        ----------
        index : {DatetimeIndex, PeriodIndex}
            An index with its frequency (`freq`) set.

        Returns
        -------
        Seasonality
            The initialized Seasonality instance.
        z,index must be a DatetimeIndex or PeriodIndexNz+index must have a freq or inferred_freq set)rš   )
r5   r/   r0   rD   r:   rF   Úinferred_freqr3   rC   r   )r‘   r    r:   rš   r   r   r   Ú
from_indexq  s    
zSeasonality.from_index.c                 C   s   | j | jfS r(   )rœ   r�   r   r   r   r   r,   Ž  s    zSeasonality._eq_attrc                 C   s   d| j › d�S )NzSeasonality(period=r„   rž   r   r   r   r   r'   ’  s    zSeasonality.__str__c                 C   s:   | j }g }td|d ƒD ]}| d|› d|› d�¡ q|S )Nr7   ús(rƒ   r„   )rœ   rw   rv   )r   rš   rx   Úir   r   r   rz   •  s
    zSeasonality._columnsc                 C   sp   |   |¡}|jd }| j}t ||f¡}| jd }t|ƒD ]"}|| | }d||d |…|f< q:tj|| j	|d�S ©Nr   r7   r”   )
r5   rB   rœ   rL   r~   r�   rw   r0   re   rz   )r   r    rT   rš   ÚtermÚoffsetr¢   Úcolr   r   r   r"   �  s    


zSeasonality.in_sampler#   c                 C   s‚   |   |¡}|  |||¡}|jd }| j}t ||f¡}| jd }t|ƒD ]&}	|| |	 | }
d||	d |…|
f< qHtj	|| j
|d�S r£   )r5   rU   rB   rœ   rL   r~   r�   rw   r0   re   rz   )r   r$   r    r%   r–   rT   rš   r¤   r¥   r¢   Zcol_locr   r   r   r&   «  s    


zSeasonality.out_of_sample)r7   )N)r*   r`   ra   rb   r   rf   rq   rc   rš   r›   r—   r   r
   r   r0   rF   rD   r    r   r,   rg   r'   r   rz   r   r   r"   r1   re   r&   r	   r   r   r   r   r™   8  s8   "
þ
þ
 ü
ûr™   c                   @   sF   e Zd ZdZeddœdd„Zeedœdd„ƒZej	ej	d	œd
d„Z
dS )ÚFourierDeterministicTermz7Abstract Base Class for all Fourier Deterministic TermsN)rm   r   c                 C   s   t |dƒ| _d S ©Nr   )r   ro   )r   rm   r   r   r   rq   Á  s    z!FourierDeterministicTerm.__init__r   c                 C   s   | j S )z'The order of the Fourier terms includedrr   r   r   r   r   rm   Ä  s    zFourierDeterministicTerm.orderr{   c                 C   s‚   dt j | t j¡ }t  |jd d| j f¡}t| jƒD ]B}tt j	t j
fƒD ],\}}||d | ƒ|d d …d| | f< qNq:|S )Nr;   r   r7   )rL   ÚpiÚastyper•   ÚemptyrB   ro   rw   Ú	enumerateÚsinÚcos)r   r|   r   r¢   ÚjÚfuncr   r   r   r€   É  s    (z#FourierDeterministicTerm._get_terms)r*   r`   ra   rb   rf   rq   rc   rm   rL   r†   r€   r   r   r   r   r§   ¾  s
   r§   c                       sâ   e Zd ZdZdZeedœ‡ fdd„Zeedœdd„ƒZ	ee
e dœd	d
„ƒZeejjƒeee ejf ejdœdd„ƒZeejjƒdeeee ejf eee  ejdœdd„ƒZeeedf dœdd„ƒZedœdd„Z‡  ZS )ÚFouriera™  
    Fourier series deterministic terms

    Parameters
    ----------
    period : int
        The length of a full cycle. Must be >= 2.
    order : int
        The number of Fourier components to include. Must be <= 2*period.

    See Also
    --------
    DeterministicProcess
    TimeTrend
    Seasonality
    CalendarFourier

    Notes
    -----
    Both a sine and a cosine term are included for each i=1, ..., order

    .. math::

       f_{i,s,t} & = \sin\left(2 \pi i \times \frac{t}{m} \right)  \\
       f_{i,c,t} & = \cos\left(2 \pi i \times \frac{t}{m} \right)

    where m is the length of the period.

    Examples
    --------
    Solar data has an 11-year cycle

    >>> from statsmodels.datasets import sunspots
    >>> from statsmodels.tsa.deterministic import Fourier
    >>> data = sunspots.load_pandas().data
    >>> fourier_gen = Fourier(11, order=2)
    >>> fourier_gen.in_sample(data.index)
    F)rš   rm   c                    s4   t ƒ  |¡ t|dƒ| _d| j | jkr0tdƒ‚d S )Nrš   r;   z2 * order must be <= period)rˆ   rq   r   rœ   ro   rC   )r   rš   rm   r‰   r   r   rq   û  s    zFourier.__init__r   c                 C   s   | j S )zThe period of the Fourier termsrž   r   r   r   r   rš     s    zFourier.periodc              
   C   sV   | j }t|ƒ ¡ }g }td| jd ƒD ]*}dD ] }| |› d|› d|› d�¡ q.q&|S )Nr7   ©r­   r®   ú(rƒ   r„   )rœ   r   Ústriprw   ro   rv   )r   rš   Z
fmt_periodrx   r¢   Útypr   r   r   rz     s     zFourier._columnsr   c                 C   s<   |   |¡}|jd }|  t |¡| j ¡}tj||| jd�S ©Nr   ©r    rx   )	r5   rB   r€   rL   rO   rœ   r0   re   rz   )r   r    rT   r   r   r   r   r"     s    

zFourier.in_sampleNr#   c                 C   sP   |   |¡}|  |||¡}|jd }|  t ||| ¡| j ¡}tj||| j	d�S r¶   )
r5   rU   rB   r€   rL   rO   rœ   r0   re   rz   )r   r$   r    r%   r–   rT   r   r   r   r   r&     s
    

zFourier.out_of_sample.c                 C   s   | j | jfS r(   ©rœ   ro   r   r   r   r   r,   &  s    zFourier._eq_attrc                 C   s   d| j › d| j› d�S )NzFourier(period=ú, order=r„   r¸   r   r   r   r   r'   *  s    zFourier.__str__)N)r*   r`   ra   rb   r   Úfloatrf   rq   rc   rš   r   rg   rz   r   r   r"   r   r
   r   r0   r1   re   r&   r	   r   r,   r'   r˜   r   r   r‰   r   r±   Ò  s,   &	
þ
 ü
ûr±   c                   @   sŒ   e Zd ZdZeddœdd„Zeedœdd„ƒZee	j
e	jf ejd	œd
d„Ze	j
e	jffe	jeeeedf f ee	j
e	jf dœdd„ZdS )ÚCalendarDeterministicTermz4Abstract Base Class for calendar deterministic termsN)r:   r   c                 C   s>   zt jd|dd�}|j| _W n tk
r8   tdƒ‚Y nX d S )Nz
2020-01-01r7   r<   z freq is not understood by pandas)r0   rG   r:   Ú_freqrC   )r   r:   r    r   r   r   rq   1  s
    z"CalendarDeterministicTerm.__init__r   c                 C   s   | j jS ©z(The frequency of the deterministic terms©r¼   Úfreqstrr   r   r   r   r:   8  s    zCalendarDeterministicTerm.freqr   c                 C   sX   t |tjƒr| ¡ }|| | j¡ ¡  }| | j¡}|d  ¡ | ¡  }t|ƒt|ƒ S )Nr7   )r/   r0   rD   Úto_timestampÚ	to_periodr¼   r   )r   r    Údeltar©   Úgapr   r   r   Ú_compute_ratio=  s    z(CalendarDeterministicTerm._compute_ratio.)r    Úallowedr   c                 C   s®   t |tƒr|f}t ||ƒs”t|ƒdkr6d|d j }nBd dd„ |d d… D ƒ¡}t|ƒdkrf|d	7 }|d
|d j 7 }t| ƒj› d|› �}t|ƒ‚t |tjtjfƒsªt	‚|S )Nr7   za r   z, c                 s   s   | ]}|j V  qd S r(   )r*   )rZ   r[   r   r   r   Ú	<genexpr>U  s     z>CalendarDeterministicTerm._check_index_type.<locals>.<genexpr>r6   r;   rƒ   z and z! terms can only be computed from )
r/   r)   rK   r*   r…   r3   r0   rF   rD   rA   )r   r    rÅ   Zallowed_typesÚmsgr   r   r   Ú_check_index_typeG  s    

ÿz+CalendarDeterministicTerm._check_index_type)r*   r`   ra   rb   rg   rq   rc   r:   r   r0   rF   rD   rL   r†   rÄ   r1   r   r   rÈ   r   r   r   r   r»   .  s   þþýùr»   c                       sÎ   e Zd ZdZeeddœ‡ fdd„Zeee dœdd„ƒZ	e
ejjƒeee ejf ejd	œd
d„ƒZe
ejjƒdeeee ejf eee  ejdœdd„ƒZeeedf dœdd„ƒZedœdd„Z‡  ZS )ÚCalendarFouriera…  
    Fourier series deterministic terms based on calendar time

    Parameters
    ----------
    freq : str
        A string convertible to a pandas frequency.
    order : int
        The number of Fourier components to include. Must be <= 2*period.

    See Also
    --------
    DeterministicProcess
    CalendarTimeTrend
    CalendarSeasonality
    Fourier

    Notes
    -----
    Both a sine and a cosine term are included for each i=1, ..., order

    .. math::

       f_{i,s,t} & = \sin\left(2 \pi i \tau_t \right)  \\
       f_{i,c,t} & = \cos\left(2 \pi i \tau_t \right)

    where m is the length of the period and :math:`\tau_t` is the frequency
    normalized time.  For example, when freq is "D" then an observation with
    a timestamp of 12:00:00 would have :math:`\tau_t=0.5`.

    Examples
    --------
    Here we simulate irregularly spaced hourly data and construct the calendar
    Fourier terms for the data.

    >>> import numpy as np
    >>> import pandas as pd
    >>> base = pd.Timestamp("2020-1-1")
    >>> gen = np.random.default_rng()
    >>> gaps = np.cumsum(gen.integers(0, 1800, size=1000))
    >>> times = [base + pd.Timedelta(gap, unit="s") for gap in gaps]
    >>> index = pd.DatetimeIndex(pd.to_datetime(times))

    >>> from statsmodels.tsa.deterministic import CalendarFourier
    >>> cal_fourier_gen = CalendarFourier("D", 2)
    >>> cal_fourier_gen.in_sample(index)
    N)r:   rm   r   c                    s(   t ƒ  |¡ t | |¡ t|dƒ| _d S r¨   )rˆ   rq   r§   r   ro   )r   r:   rm   r‰   r   r   rq   “  s    zCalendarFourier.__init__r   c              
   C   sH   g }t d| jd ƒD ].}dD ]$}| |› d|› d| jj› d�¡ qq|S )Nr7   r²   r³   z,freq=r„   )rw   ro   rv   r¼   r¿   )r   rx   r¢   rµ   r   r   r   rz   ˜  s
    $zCalendarFourier._columnsr   c                 C   s:   |   |¡}|  |¡}|  |¡}|  |¡}tj||| jd�S ©Nr·   )r5   rÈ   rÄ   r€   r0   re   rz   )r   r    Úratior   r   r   r   r"      s
    



zCalendarFourier.in_sampler#   c                 C   s^   |   |¡}|  |||¡}|  |¡ t|tjtjfƒs8t‚|  |¡}|  	|¡}tj
||| jd�S rÊ   )r5   rU   rÈ   r/   r0   rF   rD   rA   rÄ   r€   re   rz   )r   r$   r    r%   r–   rË   r   r   r   r   r&   «  s    



zCalendarFourier.out_of_sample.c                 C   s   | j j| jfS r(   ©r¼   r¿   ro   r   r   r   r   r,   º  s    zCalendarFourier._eq_attrc                 C   s   d| j j› d| j› d�S )NzFourier(freq=r¹   r„   rÌ   r   r   r   r   r'   ¾  s    zCalendarFourier.__str__)N)r*   r`   ra   rb   rg   rf   rq   rc   r   rz   r   r   r"   r   r
   r   r0   r1   re   r&   r	   r   r,   r'   r˜   r   r   r‰   r   rÉ   b  s&   0
þ

 ü
ûrÉ   c                       s°  e Zd ZdZdZddddœddid	d
idddœdœZeeddœ‡ fdd„Zeedœdd„ƒZ	eedœdd„ƒZ
eejejf ejdœdd„Zeejejf ejdœdd„Zeejejf ejdœdd„Zeejejf ejdœdd „Zeejejf ejdœd!d"„Zeee dœd#d$„ƒZeejjƒeee ejf ejdœd%d&„ƒZeejjƒd/e eee ejf e!ee  ejd'œd(d)„ƒZee"ed*f dœd+d,„ƒZ#edœd-d.„Z$‡  Z%S )0ÚCalendarSeasonalitya¾  
    Seasonal dummy deterministic terms based on calendar time

    Parameters
    ----------
    freq : str
        The frequency of the seasonal effect.
    period : str
        The pandas frequency string describing the full period.

    See Also
    --------
    DeterministicProcess
    CalendarTimeTrend
    CalendarFourier
    Seasonality

    Examples
    --------
    Here we simulate irregularly spaced data (in time) and hourly seasonal
    dummies for the data.

    >>> import numpy as np
    >>> import pandas as pd
    >>> base = pd.Timestamp("2020-1-1")
    >>> gen = np.random.default_rng()
    >>> gaps = np.cumsum(gen.integers(0, 1800, size=1000))
    >>> times = [base + pd.Timedelta(gap, unit="s") for gap in gaps]
    >>> index = pd.DatetimeIndex(pd.to_datetime(times))

    >>> from statsmodels.tsa.deterministic import CalendarSeasonality
    >>> cal_seas_gen = CalendarSeasonality("H", "D")
    >>> cal_seas_gen.in_sample(index)
    Té¨   é   é   )ÚHÚBÚDrÑ   é   ÚMrt   é   é   )rÕ   ÚQ)ÚWrÓ   rØ   ÚAN)r:   rš   r   c                    s    t ƒ }|jdd„ | j ¡ D ƒŽ  t| j ¡ ƒ}t|dt|ƒdd�}t|d|dd�}|| j| krvtd|› d|› d	�ƒ‚t	ƒ  
|¡ || _| jj d
¡d | _d S )Nc                 S   s   g | ]}t | ¡ ƒ‘qS r   )ÚlistÚkeys)rZ   Úvalr   r   r   r]   ó  s     z0CalendarSeasonality.__init__.<locals>.<listcomp>r:   F)ÚoptionsÚlowerrš   zThe combination of freq=z and period=z is not supported.ú-r   )ÚsetÚupdateÚ
_supportedÚvaluesrÛ   rÜ   r   ÚtuplerC   rˆ   rq   rœ   r¼   r¿   ÚsplitÚ	_freq_str)r   r:   rš   Zfreq_optionsZperiod_optionsr‰   r   r   rq   ð  s0    ÿ   ÿ   ÿÿzCalendarSeasonality.__init__r   c                 C   s   | j jS r½   r¾   r   r   r   r   r:     s    zCalendarSeasonality.freqc                 C   s   | j S )zThe full periodrž   r   r   r   r   rš     s    zCalendarSeasonality.periodr   c                 C   sf   | j jdkr|jd|j  S | j jdkr.|jS tjddd�j ¡ }|j}| |¡ ¡ s^t	dƒ‚|S d S )NrÑ   rÔ   rÓ   z2000-1-1é
   )r9   z=freq is B but index contains days that are not business days.)
r¼   r¿   ÚhourZ	dayofweekr0   Zbdate_rangeÚuniqueÚisinrM   rC   )r   r    ZbdaysÚlocr   r   r   Ú_weekly_to_loc  s    ÿz"CalendarSeasonality._weekly_to_locc                 C   s   |j S r(   )ré   r!   r   r   r   Ú_daily_to_loc!  s    z!CalendarSeasonality._daily_to_locc                 C   s   |j d d S )Nr7   rt   )Úmonthr!   r   r   r   Ú_quarterly_to_loc&  s    z%CalendarSeasonality._quarterly_to_locc                 C   s$   | j jdkr|jd S |jd S d S )NrÕ   r7   )r¼   r¿   rï   Zquarterr!   r   r   r   Ú_annual_to_loc+  s    
z"CalendarSeasonality._annual_to_locc                 C   sŽ   | j dkr|  |¡}n6| j dkr,|  |¡}n | j dkrB|  |¡}n
|  |¡}| j| j  | j }t |j	d |f¡}d|t 
|j	d ¡|f< |S )NrÓ   rÙ   rØ   r   r7   )rœ   rî   rí   rð   rñ   rã   rç   rL   r~   rB   rO   )r   r    r|   Z
full_cycler   r   r   r   r€   3  s    



zCalendarSeasonality._get_termsc              
   C   sN   g }| j | j | j }t|ƒD ]*}| d| j› d|d › d| j› d�¡ q|S )Nr¡   ú=r7   z	, period=r„   )rã   rœ   rç   rw   rv   )r   rx   Úcountr¢   r   r   r   rz   C  s    ÿzCalendarSeasonality._columnsc                 C   s0   |   |¡}|  |¡}|  |¡}tj||| jd�S rÊ   )r5   rÈ   r€   r0   re   rz   )r   r    r   r   r   r   r"   M  s    


zCalendarSeasonality.in_sampler#   c                 C   sT   |   |¡}|  |||¡}|  |¡ t|tjtjfƒs8t‚|  |¡}tj	||| j
d�S rÊ   )r5   rU   rÈ   r/   r0   rF   rD   rA   r€   re   rz   )r   r$   r    r%   r–   r   r   r   r   r&   W  s    


z!CalendarSeasonality.out_of_sample.c                 C   s   | j | jfS r(   )rœ   rç   r   r   r   r   r,   e  s    zCalendarSeasonality._eq_attrc                 C   s   d| j › d�S )NzSeasonal(freq=r„   )rç   r   r   r   r   r'   i  s    zCalendarSeasonality.__str__)N)&r*   r`   ra   rb   r   rã   rg   rq   rc   r:   rš   r   r0   rF   rD   rL   r†   rí   rî   rð   rñ   r€   r   rz   r   r   r"   r
   r   r1   re   r&   rf   r	   r   r,   r'   r˜   r   r   r‰   r   rÍ   Â  sX   #
üþþþþ	þ	
þ	
 ü
ûrÍ   c                	       s.  e Zd ZdZdddœeeeeeee	f  ddœ‡ fdd„Z
eee d	œd
d„ƒZedeeeeee	f  d dœdd„ƒZeejejf ejejdœdd„Zeejjƒeee ejf ejdœdd„ƒZeejjƒdeeee ejf eee  ejdœdd„ƒZeeedf d	œdd„ƒZed	œdd„Z‡  Z S ) ÚCalendarTimeTrenda
  
    Constant and time trend determinstic terms based on calendar time

    Parameters
    ----------
    freq : str
        A string convertible to a pandas frequency.
    constant : bool
        Flag indicating whether a constant should be included.
    order : int
        A non-negative int containing the powers to include (1, 2, ..., order).
    base_period : {str, pd.Timestamp}, default None
        The base period to use when computing the time stamps. This value is
        treated as 1 and so all other time indices are defined as the number
        of periods since or before this time stamp. If not provided, defaults
        to pandas base period for a PeriodIndex.

    See Also
    --------
    DeterministicProcess
    CalendarFourier
    CalendarSeasonality
    TimeTrend

    Notes
    -----
    The time stamp, :math:`\tau_t`, is the number of periods that have elapsed
    since the base_period. :math:`\tau_t` may be fractional.

    Examples
    --------
    Here we simulate irregularly spaced hourly data and construct the calendar
    time trend terms for the data.

    >>> import numpy as np
    >>> import pandas as pd
    >>> base = pd.Timestamp("2020-1-1")
    >>> gen = np.random.default_rng()
    >>> gaps = np.cumsum(gen.integers(0, 1800, size=1000))
    >>> times = [base + pd.Timedelta(gap, unit="s") for gap in gaps]
    >>> index = pd.DatetimeIndex(pd.to_datetime(times))

    >>> from statsmodels.tsa.deterministic import CalendarTimeTrend
    >>> cal_trend_gen = CalendarTimeTrend("D", True, order=1)
    >>> cal_trend_gen.in_sample(index)

    Next, we normalize using the first time stamp

    >>> cal_trend_gen = CalendarTimeTrend("D", True, order=1,
    ...                                   base_period=index[0])
    >>> cal_trend_gen.in_sample(index)
    Tr   N©Úbase_period)r:   rl   rm   rö   r   c                   sb   t ƒ  |¡ tj| ||d� d| _|d k	rHtj|d| jd�}|jd | _|d krTd nt|ƒ| _	d S )NrŽ   r   r7   r8   )
rˆ   rq   rj   Ú_ref_i8r0   rE   r¼   Úasi8rg   Ú_base_period)r   r:   rl   rm   rö   Úprr‰   r   r   rq   £  s      ÿzCalendarTimeTrend.__init__r   c                 C   s   | j S )zThe base period)rù   r   r   r   r   rö   µ  s    zCalendarTimeTrend.base_period)r:   rs   rö   r   c                 C   s8   |  d¡}d}d|krd}nd|kr(d}| ||||d�S )a  
        Create a TimeTrend from a string description.

        Provided for compatibility with common string names.

        Parameters
        ----------
        freq : str
            A string convertible to a pandas frequency.
        trend : {"n", "c", "t", "ct", "ctt"}
            The string representation of the time trend. The terms are:

            * "n": No trend terms
            * "c": A constant only
            * "t": Linear time trend only
            * "ct": A constant and a time trend
            * "ctt": A constant, a time trend and a quadratic time trend
        base_period : {str, pd.Timestamp}, default None
            The base period to use when computing the time stamps. This value
            is treated as 1 and so all other time indices are defined as the
            number of periods since or before this time stamp. If not
            provided, defaults to pandas base period for a PeriodIndex.

        Returns
        -------
        TimeTrend
            The TimeTrend instance.
        r‹   r   rŒ   r;   r�   r7   rõ   r�   )r‘   r:   rs   rö   rl   rm   r   r   r   r’   º  s    #
zCalendarTimeTrend.from_string)r    rË   r   c                 C   sh   t |tjƒr| | j¡}|j}|| j d }| tj	¡| }|d d …d f }|  
|¡}tj|| j|d�S )Nr7   r”   )r/   r0   rF   rÁ   r¼   rø   r÷   rª   rL   r•   r€   re   rz   )r   r    rË   Zindex_i8Útimer   r   r   r   Ú_termså  s    
zCalendarTimeTrend._termsr   c                 C   s*   |   |¡}|  |¡}|  |¡}|  ||¡S r(   )r5   rÈ   rÄ   rü   )r   r    rË   r   r   r   r"   ò  s    


zCalendarTimeTrend.in_sampler#   c                 C   sN   |   |¡}|  |||¡}|  |¡ t|tjtjfƒs8t‚|  |¡}|  	||¡S r(   )
r5   rU   rÈ   r/   r0   rD   rF   rA   rÄ   rü   )r   r$   r    r%   r–   rË   r   r   r   r&   û  s    


zCalendarTimeTrend.out_of_sample.c                 C   s,   | j | j| jjf}| jd k	r(|| jf7 }|S r(   )rn   ro   r¼   r¿   rù   )r   Úattrr   r   r   r,   	  s    ý
zCalendarTimeTrend._eq_attrc                 C   sR   t  | ¡}d|d d…  d| jj› d� }| jd k	rN|d d… d| j› d� }|S )NÚCalendarr6   z, freq=r„   zbase_period=)rj   r'   r¼   r¿   rù   )r   Úvaluer   r   r   r'     s
    
 
zCalendarTimeTrend.__str__)Tr   )N)N)!r*   r`   ra   rb   rg   rd   rf   r	   r   ÚDateLikerq   rc   rö   r—   r’   r0   rF   rD   rL   r†   re   rü   r   r   r"   r
   r   r1   r&   r   r,   r'   r˜   r   r   r‰   r   rô   m  sR   8  üúù üû+ þ
þ
 ü
û
rô   c                
   @   s¢  e Zd ZdZddddddddœeee ejf e	ee
ef  eeeeee edœdd	„Zeejd
œdd„ƒZeee d
œdd„ƒZeej eej dœdd„Zejejdœdd„Zeejjƒejd
œdd„ƒZeejjƒd*ee	eee ejf  ejdœdd„ƒZejeejejf dœdd„Zeeejdœdd„Zejejejdœdd „Zeeejd!œd"d#„Z ee!e"ef ee!e"ef ejdœd$d%„Z#dd
œd&d'„Z$d(d)„ Z%dS )+ÚDeterministicProcessa”  
    Container class for deterministic terms.

    Directly supports constants, time trends, and either seasonal dummies or
    fourier terms for a single cycle. Additional deterministic terms beyond
    the set that can be directly initialized through the constructor can be
    added.

    Parameters
    ----------
    index : {Sequence[Hashable], pd.Index}
        The index of the process. Should usually be the "in-sample" index when
        used in forecasting applications.
    period : {float, int}, default None
        The period of the seasonal or fourier components. Must be an int for
        seasonal dummies. If not provided, freq is read from index if
        available.
    constant : bool, default False
        Whether to include a constant.
    order : int, default 0
        The order of the tim trend to include. For example, 2 will include
        both linear and quadratic terms. 0 exclude time trend terms.
    seasonal : bool = False
        Whether to include seasonal dummies
    fourier : int = 0
        The order of the fourier terms to included.
    additional_terms : Sequence[DeterministicTerm]
        A sequence of additional deterministic terms to include in the process.
    drop : bool, default False
        A flag indicating to check for perfect collinearity and to drop any
        linearly dependent terms.

    See Also
    --------
    TimeTrend
    Seasonality
    Fourier
    CalendarTimeTrend
    CalendarSeasonality
    CalendarFourier

    Notes
    -----
    See the notebook `Deterministic Terms in Time Series Models
    <../examples/notebooks/generated/deterministics.html>`__ for an overview.

    Examples
    --------
    >>> from statsmodels.tsa.deterministic import DeterministicProcess
    >>> from pandas import date_range
    >>> index = date_range("2000-1-1", freq="M", periods=240)

    First a determinstic process with a constant and quadratic time trend.

    >>> dp = DeterministicProcess(index, constant=True, order=2)
    >>> dp.in_sample().head(3)
                const  trend  trend_squared
    2000-01-31    1.0    1.0            1.0
    2000-02-29    1.0    2.0            4.0
    2000-03-31    1.0    3.0            9.0

    Seasonal dummies are included by setting seasonal to True.

    >>> dp = DeterministicProcess(index, constant=True, seasonal=True)
    >>> dp.in_sample().iloc[:3,:5]
                const  s(2,12)  s(3,12)  s(4,12)  s(5,12)
    2000-01-31    1.0      0.0      0.0      0.0      0.0
    2000-02-29    1.0      1.0      0.0      0.0      0.0
    2000-03-31    1.0      0.0      1.0      0.0      0.0

    Fourier components can be used to alternatively capture seasonal patterns,

    >>> dp = DeterministicProcess(index, constant=True, fourier=2)
    >>> dp.in_sample().head(3)
                const  sin(1,12)  cos(1,12)  sin(2,12)  cos(2,12)
    2000-01-31    1.0   0.000000   1.000000   0.000000        1.0
    2000-02-29    1.0   0.500000   0.866025   0.866025        0.5
    2000-03-31    1.0   0.866025   0.500000   0.866025       -0.5

    Multiple Seasonalities can be captured using additional terms.

    >>> from statsmodels.tsa.deterministic import Fourier
    >>> index = date_range("2000-1-1", freq="D", periods=5000)
    >>> fourier = Fourier(period=365.25, order=1)
    >>> dp = DeterministicProcess(index, period=3, constant=True,
    ...                           seasonal=True, additional_terms=[fourier])
    >>> dp.in_sample().head(3)
                const  s(2,3)  s(3,3)  sin(1,365.25)  cos(1,365.25)
    2000-01-01    1.0     0.0     0.0       0.000000       1.000000
    2000-01-02    1.0     1.0     0.0       0.017202       0.999852
    2000-01-03    1.0     0.0     1.0       0.034398       0.999408
    NFr   r   ©rš   rl   rm   ÚseasonalÚfourierÚadditional_termsÚdrop)r    rš   rl   rm   r  r  r  r  c          
      C   s”  t |tjƒst |¡}|| _g | _d| _d | _|  ¡  t|ddd�}t	|dƒ | _
}t|dƒ| _t	|dƒ | _}t|dƒ| _t|ƒ}d | _t	|d	ƒ| _|| _|s¤|r¶| j t||ƒ¡ |rÆ|rÆtd
ƒ‚|sÎ|rî|d krî|d krît| jƒ | _}|�rt|dƒ}| j t|ƒ¡ n2|�rBt|dƒ}|d k	�s.t‚| j t||d�¡ |D ]<}	t |	tƒ�s^tdƒ‚|	| jk�rx| j |	¡ ntdƒ‚�qF|| _d | _d S )NFrš   T)Úoptionalrl   rm   r  r  r  zÂseasonal and fourier can be initialized through the constructor since these will be necessarily perfectly collinear. Instead, you can pass additional components using the additional_terms input.)rm   zJAll additional terms must be instances of subsclasses of DeterministicTermzuOne or more terms in additional_terms has been added through the parameters of the constructor. Terms must be unique.)r/   r0   r1   Ú_indexÚ_deterministic_termsÚ_extendableÚ_index_freqÚ_validate_indexr   r   rn   r   ro   Ú	_seasonalÚ_fourierrå   Ú_cached_in_sampleÚ_dropÚ_additional_termsrv   r‡   rC   r   rœ   r™   rA   r±   r   r3   Ú_retain_cols)
r   r    rš   rl   rm   r  r  r  r  r¤   r   r   r   rq   z  sX    
ÿ

ÿÿzDeterministicProcess.__init__r   c                 C   s   | j S )zThe index of the process)r  r   r   r   r   r    ¹  s    zDeterministicProcess.indexc                 C   s   | j S )z/The deterministic terms included in the process)r	  r   r   r   r   r   ¾  s    zDeterministicProcess.terms)r   r   c           	      C   sº   d }| j D ]}t|ttfƒr
|p$|j}q
|d krjd}|D ]0}||jd k ¡ |jd dk@ }|pf| ¡ }q8|}t| j ƒD ]<\}}|j	}|r¬|r¬|| jd d …dd …f ||< |p²|}qx|S )NFr   r7   )
r	  r/   r‡   rô   rl   ÚilocrM   Úanyr¬   r   )	r   r   Z	has_constZdtermr¤   Z	const_colZ
drop_firstr¢   r   r   r   r   Ú_adjust_dummiesÃ  s     
 
z$DeterministicProcess._adjust_dummiesc                 C   sŒ   t j|dkdd�}t  |¡r0|jd d …| f }|jdd�|jdd�k}t  |¡dkrˆt  |¡d }d||d d… < |jd d …| f }|S )Nr   ©Zaxisr7   F)rL   rM   r  rì   ÚmaxÚminÚsumÚwhere)r   r   Zall_zeroZis_constantZ
const_locsr   r   r   Ú_remove_zeros_onesÖ  s    
z'DeterministicProcess._remove_zeros_onesc                 C   s¶  | j d k	r| j S | j}| js:tjt |jd df¡|d�S g }| jD ]}| | 	|¡¡ qD|  
|¡}tj|dd�}|  |¡}| j�r¤t|ƒ}t|ddd�}|d }|d }t t |¡¡}	|	d |jd  t t¡j }
tt |	|
k¡ƒ}|j| }dg}d}td|jd ƒD ]R}tj |d |d …d |d …f ¡}||k�rN| |¡ |}||k�r �qb�qt|ƒ|k�r„|jd d …|f }n |jd d …t |d |… ¡f }|j| _|| _ |S )	Nr   r4   r7   r  ÚrT)ÚmodeZpivotingr6   ) r  r  r	  r0   re   rL   r«   rB   rv   r"   r  Úconcatr  r  r   r   ÚabsZdiagZfinforº   Zepsrf   r  ÚTrw   ZlinalgZmatrix_rankrK   r  Úsortrx   r  )r   r    Ú	raw_termsr¤   r   Z	terms_arrÚresr  ÚpZabs_diagZtolZrankZrpxZkeepZ	last_rankr¢   Z	curr_rankr   r   r   r"   â  sF    




$



 zDeterministicProcess.in_sample)r$   r%   r   c                 C   s®   t |dƒ}| jr"| jd kr"|  ¡  | j}| jsLtjt 	|j
d df¡|d�S g }| jD ]}| | |||¡¡ qVtj|dd�}| jd k	sŒt‚|j
d t| jƒkrª|| j }|S )Nr$   r   r4   r7   r  )r   r  r  r"   r  r	  r0   re   rL   r«   rB   rv   r&   r  rA   rK   )r   r$   r%   r    r"  r¤   r   r   r   r   r&     s    


z"DeterministicProcess.out_of_sample)rI   r   c                 C   s>   | j }t|tjƒr(tj|d ||jd�S tj|d || jd�S )Nr   )Úendr:   )rS   r%  r:   )r  r/   r0   rD   rE   r:   rG   r  )r   rI   r    r   r   r   Ú_extend_time_index   s    z'DeterministicProcess._extend_time_index)rS   rI   r   c                 C   s¨  | j }t|ƒ}t|tjƒs"|s"t‚||d k r6ttƒ‚t|tjƒrJ|j}nt	|ƒdkrdt
 |¡ ¡ nd}|dkr”||d  | dkr”td|› d�ƒ‚|r¬t t
 ||¡¡}ntj|||d�}|d | j d krä|  ¡ }|j| }|S |d | j d k�rT|d | }|d |k�r@tj|||d�}	| j|	jd |	d�}
|
j| S | j|jd |d�S || j d k}|| }||  }|  ¡ j| }| j|jd |d�}tj||gdd	�S )
Nr   r7   z,The step of the index is not 1 (actual step=zM). start must be in the sequence that would have been generated by the index.r>   r6   )r%   )r$   r%   r  )r  r   r/   r0   rH   rA   rC   ÚSTART_BEFORE_INDEX_ERRr?   rK   rL   rN   r  r1   rO   r"   rì   r&   rB   r  )r   rS   rI   r    Zis_int64_indexZidx_stepÚnew_idxr"   Z
next_valueÚtmpÚoosZin_sample_locZin_sample_idxZout_of_sample_idxZin_sample_exogZoos_exogr   r   r   Ú_range_from_range_index)  sF    
ÿ


 ÿz,DeterministicProcess._range_from_range_indexc                 C   sæ   | j }t| j tjƒrHt|tjƒr.|j| jd�}t|tjƒrH|j| jd�}||d k r\ttƒ‚|| j d kr||  	¡ j
||… S |  |¡}|||d k }|  |jd |¡}||d krÂ|j
||… S tj|  	¡ |gdd�}|j
||… S )N)r:   r   r6   r  )r  r/   r0   rD   Ú	TimestamprÁ   r  rC   r'  r"   rì   r&  r&   rB   r  )r   rS   rI   r    r(  Zoos_idxr*  Zbothr   r   r   Ú_range_from_time_indexT  s"    
z+DeterministicProcess._range_from_time_index)rÿ   r-   r   c                 C   sœ   |dk rt |› d�ƒ‚|| jjd k r0| j| S || jjd d  d }| j}t| jtjƒr~tj|d | j|d�}|d  ¡ S tj	|d | j|d�}|d S )Nr   z must be non-negative.r7   r6   r<   )
rC   r  rB   r/   r0   rD   rE   r  rÀ   rG   )r   rÿ   r-   Zadd_periodsr    rú   Zdrr   r   r   Ú_int_to_timestampi  s&    
  ÿ  ÿz&DeterministicProcess._int_to_timestampc                 C   s®   | j stdƒ‚t| jƒtjfks*t| jƒrRt|dƒ}t|dƒ}|d7 }|  ||¡S t	|t
tjfƒrp|  |d¡}n
t |¡}t	|t
tjfƒr˜|  |d¡}n
t |¡}|  ||¡S )aç  
        Deterministic terms spanning a range of observations

        Parameters
        ----------
        start : {int, str, dt.datetime, pd.Timestamp, np.datetime64}
            The first observation.
        stop : {int, str, dt.datetime, pd.Timestamp, np.datetime64}
            The final observation. Inclusive to match most prediction
            function in statsmodels.

        Returns
        -------
        DataFrame
            A data frame of deterministic terms
        zýThe index in the deterministic process does not support extension. Only PeriodIndex, DatetimeIndex with a frequency, RangeIndex, and integral Indexes that start at 0 and have only unit differences can be extended when producing out-of-sample forecasts.
rS   rI   r7   )r
  r3   r)   r  r0   rH   r   r   r+  r/   rf   rL   Úintegerr.  r,  r-  )r   rS   rI   r   r   r   rw   z  s     ÿ



zDeterministicProcess.rangec                 C   s˜   t | jtjƒr | jj| _d| _ntt | jtjƒrN| jjp<| jj| _| jd k	| _nFt | jtj	ƒrdd| _n0t
| jƒr”| jd dko�t t | j¡dk¡| _d S )NTr   r7   )r/   r  r0   rD   r:   r  r
  rF   rŸ   rH   r   rL   rM   rN   r   r   r   r   r  §  s    

ÿz$DeterministicProcess._validate_indexc              
   C   s&   t || j| j| j| j| j| j| jd�S )ap  
        Create an identical determinstic process with a different index

        Parameters
        ----------
        index : index_like
            An index-like object. If not an index, it is converted to an
            index.

        Returns
        -------
        DeterministicProcess
            The deterministic process applied to a different index
        r  )r  rœ   rn   ro   r  r  r  r  r!   r   r   r   Úapplyµ  s    øzDeterministicProcess.apply)N)&r*   r`   ra   rb   r   r
   r   r0   r1   r	   rº   rf   rd   r   rq   rc   r    r   r   re   r  r  r   r"   r&   r,  rF   rD   r&  r+  r-  rg   r.  ÚIntLiker   rw   r  r0  r   r   r   r   r    s`   aöö?
(
 ýüý	, þü-r  )3Zstatsmodels.compat.pandasr   r   r   Úabcr   r   ÚdatetimeÚdtÚtypingr   r   r	   r
   r   r   r   r   ÚnumpyrL   Zpandasr0   Zscipy.linalgr   Zstatsmodels.iolib.summaryr   Zstatsmodels.tools.validationr   r   r   r   Zstatsmodels.tsa.tsatoolsr   r,  Z
datetime64r   rf   r/  r1  r'  r   rj   r‡   r™   r§   r±   r»   rÉ   rÍ   rô   r  r   r   r   r   Ú<module>   s6   ( 2Z \4` , 0