
p7]c           @   s(  d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d  d l j j Z d  d l j j Z d  d l m  Z  d Z! d	 Z" e j# Z$ e j% Z% d
 e j& f d     YZ' d e j( f d     YZ) d e j* f d     YZ+ e j, e+ e)  e- d k r$d  d l. j/ Z0 d  d l Z e0 j1 j2 j3 d e4  Z5 g  e5 j d d g D]4 Z6 e7 e8 e6 d   d e7 e8 e6 d   ^ qZ9 e j: e5 j d d d g d e9 Z; e' e;  Z< n  d S(   i(   t   long(   t   is_numeric_dtypeN(   t   to_datetimet
   Int64Indext   DatetimeIndext   Periodt   PeriodIndext
   RangeIndext	   Timestampt   Seriest   Indext   Float64Indext
   date_ranget   period_range(   t	   to_offset(   t   data(   t   ValueWarnings  
    %(model)s

    Parameters
    ----------
    %(params)s
    dates : array-like of datetime, optional
        An array-like object of datetime objects. If a pandas object is given
        for endog or exog, it is assumed to have a DateIndex.
    freq : str, optional
        The frequency of the time-series. A Pandas offset or 'B', 'D', 'W',
        'M', 'A', or 'Q'. This is optional if dates are given.
    %(extra_params)s
    %(extra_sections)s
s   Timeseries model base classt   TimeSeriesModelc           B   s   e  Z e i e d  6e d 6e d 6d d 6Z d d d d d  Z d d d  Z	 d d  Z
 d d	  Z d e d
  Z d   Z d   Z e e e  Z RS(   t   modelt   paramst   extra_paramst    t   extra_sectionst   nonec         K   s6   t  t |   j | | d | | |  j | |  d  S(   Nt   missing(   t   superR   t   __init__t   _init_dates(   t   selft   endogt   exogt   datest   freqR   t   kwargs(    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   .   s    c         C   sz  | d k	 r | } n |  j j } | d k rH | d k	 rH t d   n  t } | d k	 rt | t t f  sAy t j	 |  } t
 |  s t | t  s t t   k r t | d t  r t d   n  t | t  r | j } n  t |  } t | t  st d   n  | } WqA| d k	 r>t d   q>qAXn  t | t t f  r| d k r| j d k r| j } | d k	 rt } | d k	 rt j d | t  qqn  | d k	 rt |  } n  | d k r	| j d k r	| d k	 rt d   qq| d k	 rv| j d k rvt d | d d	 | d
 d |  } | rm| j |  rmt d   n  | } q| d k	 r| r| j | k rt d   qq| d k	 rt d   qn  | d k	 } t | t t f  } t | t  }	 t | t  }
 | r| j d k	 n d } t t |  j j d   } |	 rT| j |  n d } | r| po|
 po| rt j d t  n  | r| rt j d t  n  t } | r| s|	 r| s|
 r| } n | } t } | |  _  | |  _! | d k |  _" | o
| |  _# |  j# r%|  j  j n d |  _$ | |  _% |  j# rI|  j  n d |  j _& |  j# rj|  j  j' n d |  j _ d S(   s  
        Initialize dates

        Parameters
        ----------
        dates : array_like, optional
            An array like object containing dates.
        freq : str, tuple, datetime.timedelta, DateOffset or None, optional
            A frequency specification for either `dates` or the row labels from
            the endog / exog data.

        Notes
        -----
        Creates `self._index` and related attributes. `self._index` is always
        a Pandas index, and it is always Int64Index, DatetimeIndex, or
        PeriodIndex.

        If Pandas objects, endog / exog may have any type of index. If it is
        an Int64Index with values 0, 1, ..., nobs-1 or if it is (coerceable to)
        a DatetimeIndex or PeriodIndex *with an associated frequency*, then it
        is called a "supported" index. Otherwise it is called an "unsupported"
        index.

        Supported indexes are standardized (i.e. a list of date strings is
        converted to a DatetimeIndex) and the result is put in `self._index`.

        Unsupported indexes are ignored, and a supported Int64Index is
        generated and put in `self._index`. Warnings are issued in this case
        to alert the user if the returned index from some operation (e.g.
        forecasting) is different from the original data's index. However,
        whenever possible (e.g. purely in-sample prediction), the original
        index is returned.

        The benefit of supported indexes is that they allow *forecasting*, i.e.
        it is possible to extend them in a reasonable way. Thus every model
        must have an underlying supported index, even if it is just a generated
        Int64Index.

        s,   Frequency provided without associated index.i    s   Numeric index givens   Could not coerce to date indexs2   Non-date index index provided to `dates` argument.sM   No frequency information was provided, so inferred frequency %s will be used.sY   No frequency information was provided with date index and no frequency could be inferred.t   startt   endiR    sE   The given frequency argument could not be matched to the given index.sB   The given frequency argument is incompatible with the given index.sK   Given index could not be coerced to dates but `freq` argument was provided.sL   An unsupported index was provided and will be ignored when e.g. forecasting.s|   A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.N((   t   NoneR   t
   row_labelst
   ValueErrort   Falset
   isinstanceR   R   t   npt   asarrayR   R   t   tuplet   floatR	   t   valuesR   R
   R    t   inferred_freqt   Truet   warningst   warnR   R   R   t   equalsR   R   t   rangeR   t   shapet   _indext   _index_generatedt   _index_nonet   _index_datest   _index_freqt   _index_inferred_freqR   t   freqstr(   R   R   R    t   indexR.   R5   t   resampled_indext	   has_indext
   date_indext	   int_indext   range_indext   has_freqt	   incrementt   is_incrementt   index_generated(    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   6   s    +	

				
	
				c         C   s  | d
 k r |  j } n  | } t | t t f  } t | t  } t | t  } t |  } t |  } | r/t | t	 t
 t j f  r/| d k  r | | k r | | } q/| | d k r/y | j }	 | j }
 Wn# t k
 r | j }	 | j }
 n X|	 | d |
 } t d |	 d | d |
  } q/n  | r| r| rt | t	 t
 t j f  r| d k  r| | k r| | } q| | d k rt t j | d t	 | d    } qn  | r)| t k rt } n t } t | t	 t
 t j f  r| d k  r&| | k  r&| | | } q&| t |  d k ru| d | d d t	 | d  d | j  } | d } q&| | } q)| t k rt | d | j } n t |  } | | d k r)| d | d d	 | d | j  } | d | k s&| d | d d t |  d d | j  } q&q)n  | rA| j |  } n^ | sM| ry | | Wn+ t t f k
 r} t t |    n X| } n | j |  } | | k	 } t | t  r| j } n | } | | | d  | f S(   s4  
        Get the location of a specific key in an index

        Parameters
        ----------
        key : label
            The key for which to find the location if the underlying index is
            a DateIndex or a location if the underlying index is a RangeIndex
            or an Int64Index.
        base_index : pd.Index, optional
            Optionally the base index to search. If None, the model's index is
            searched.

        Returns
        -------
        loc : int
            The location of the key
        index : pd.Index
            The index including the key; this is a copy of the original index
            unless the index had to be expanded to accomodate `key`.
        index_was_expanded : bool
            Whether or not the index was expanded to accomodate `key`.

        Notes
        -----
        If `key` is past the end of of the given index, and the index is either
        an Int64Index or a date index, this function extends the index up to
        and including key, and then returns the location in the new index.

        i    i   R"   t   stopt   stepit   periodsR    R#   N(   R$   R5   R(   R   R   R   R   t   typet   lent   intR    R)   t   integerR"   RG   t   AttributeErrort   _startt   _stept   arangeR   R   R    R   R   t   get_loct
   IndexErrorR&   t   KeyErrort   strt   sliceRF   (   R   t   keyt
   base_indexR<   R?   R@   RA   t   index_classt   nobst   base_index_startt   base_index_stepRF   t   index_fnt   date_keyt   loct   et   index_was_expandedR#   (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   _get_index_loc   s    !		,	
	c         C   s  y |  j  | |  \ } } } Wn t k
 r} y t | t t t j f  sg |  j j j	 |  } n   t | t
  r | j } n  t | t j  r | j t k r t j |  } q | d } n  t | t j  s   n  |  j j | d  } t } Wq|  qXn X| | | f S(   sy  
        Get the location of a specific key in an index or model row labels

        Parameters
        ----------
        key : label
            The key for which to find the location if the underlying index is
            a DateIndex or is only being used as row labels, or a location if
            the underlying index is a RangeIndex or an Int64Index.
        base_index : pd.Index, optional
            Optionally the base index to search. If None, the model's index is
            searched.

        Returns
        -------
        loc : int
            The location of the key
        index : pd.Index
            The index including the key; this is a copy of the original index
            unless the index had to be expanded to accomodate `key`.
        index_was_expanded : bool
            Whether or not the index was expanded to accomodate `key`.

        Notes
        -----
        This method expands on `_get_index_loc` by first trying the given
        base index (or the model's index if the base index was not given) and
        then falling back to try again with the model row labels as the base
        index.

        i    i   (   Ra   RS   R(   RK   R    R)   RL   R   R%   RQ   RU   R"   t   ndarrayt   dtypet   boolt   argmaxt   numberst   IntegralR'   (   R   RV   RW   R^   R<   R`   R_   (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   _get_index_label_loc  s(     
c         C   s  y |  j  |  \ } } } Wn t k
 r; t d   n X| d
 k rg t | t |  j  d  } n  y |  j  |  \ } } } Wn t k
 r t d   n Xt | t  r | j } n  t | t  r | j	 d } n  | | }	 | | k  rt
 d   n  | d
 k	 rtt |	  t |  k s5t
 d   n  t |  j t j  re| ret j d t  n  t |  }	 nz |  j r|  j r|  j j d
 k	 r| p| r|  j j | | d !}	 q| st j d t  qn |  j rd
 }	 n  |	 d
 k	 r)|	 d |  j _ |	 d	 |  j _ |	 |  j _ n$ d
 |  j _ d
 |  j _ d
 |  j _ t |  j  }
 t | |
 d d  } | | 8} | | | |	 f S(   s
  
        Get the location of a specific key in an index or model row labels

        Parameters
        ----------
        start : label
            The key at which to start prediction. Depending on the underlying
            model's index, may be an integer, a date (string, datetime object,
            pd.Timestamp, or pd.Period object), or some other object in the
            model's row labels.
        end : label
            The key at which to end prediction (note that this key will be
            *included* in prediction). Depending on the underlying
            model's index, may be an integer, a date (string, datetime object,
            pd.Timestamp, or pd.Period object), or some other object in the
            model's row labels.
        index : pd.Index, optional
            Optionally an index to associate the predicted results to. If None,
            an attempt is made to create an index for the predicted results
            from the model's index or model's row labels.
        silent : bool, optional
            Argument to silence warnings.

        Returns
        -------
        start : integer
            The index / observation location at which to begin prediction.
        end : int
            The index / observation location at which to end in-sample
            prediction. The maximum value for this is nobs-1.
        out_of_sample : int
            The number of observations to forecast after the end of the sample.
        prediction_index : pd.Index or None
            The index associated with the prediction results. This index covers
            the range [start, end + out_of_sample]. If the model has no given
            index and no given row labels (i.e. endog/exog is not Pandas), then
            this will be None.

        Notes
        -----
        The arguments `start` and `end` behave differently, depending on if
        they are integer or not. If either is an integer, then it is assumed
        to refer to a *location* in the index, not to an index value. On the
        other hand, if it is a date string or some other type of object, then
        it is assumed to refer to an index *value*. In all cases, the returned
        `start` and `end` values refer to index *locations* (so in the former
        case, the given location is validated and returned whereas in the
        latter case a location is found that corresponds to the given index
        value).

        This difference in behavior is necessary to support `RangeIndex`. This
        is because integers for a RangeIndex could refer either to index values
        or to index locations in an ambiguous way (while for `Int64Index`,
        since we have required them to be full indexes, there is no ambiguity).

        sY   The `start` argument could not be matched to a location related to the index of the data.i   sW   The `end` argument could not be matched to a location related to the index of the data.s)   Prediction must have `end` after `start`.se   Invalid `index` provided in prediction. Must have length consistent with `start` and `end` arguments.s   Because the model data (`endog`, `exog`) were not given as Pandas objects, the prediction output will be Numpy arrays, and the given `index` argument will only be used internally.sm   No supported index is available. Prediction results will be given with an integer index beginning at `start`.i    iN(   Rh   RS   R$   t   maxRJ   R5   R(   RU   R"   RF   R&   R   t
   PandasDataR0   R1   R   R
   R6   R7   R%   t   predict_startt   predict_endt   predict_datesR   (   R   R"   R#   R<   t   silentt   start_indext	   start_oost	   end_indext   end_oost   prediction_indexRY   t   out_of_sample(    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   _get_prediction_index  sV    <
	
			
c         C   s
   |  j  j S(   N(   R   t   xnames(   R   (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   _get_exog_namesU  s    c         C   s+   t  | t  s | g } n  | |  j _ d  S(   N(   R(   t   listR   Rv   (   R   t   vals(    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   _set_exog_namesX  s    N(   t   __name__t
   __module__t   _tsa_doct
   _model_doct   _generic_paramst   _missing_param_doct   __doc__R$   R   R   Ra   Rh   R'   Ru   Rw   Rz   t   propertyt
   exog_names(    (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   (   s   	I		t   TimeSeriesModelResultsc           B   s   e  Z d  d  Z RS(   g      ?c         C   s/   | j  |  _  t t |   j | | | |  d  S(   N(   R   R   R   R   (   R   R   R   t   normalized_cov_paramst   scale(    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   b  s    (   R{   R|   R   (    (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   a  s   t   TimeSeriesResultsWrapperc           B   sK   e  Z i  Z e j e j j e  Z i d  d 6Z e j e j j	 e  Z	 RS(   R   t   predict(
   R{   R|   t   _attrst   wrapt   union_dictst   baset   LikelihoodResultsWrappert   _wrap_attrst   _methodst   _wrap_methods(    (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyR   h  s   	t   __main__t	   as_pandast   yeart   quarteri    t   :i   t   realgdpt   realinvt   realconsR<   (=   t   statsmodels.compat.pythonR    t   statsmodels.compat.pandasR   Rf   R0   t   numpyR)   t   pandasR   R   R   R   R   R   R   R	   R
   R   R   R   t   pandas.tseries.frequenciesR   t   statsmodels.baseR   t   statsmodels.base.modelR   R   t   statsmodels.base.wrappert   wrapperR   t   statsmodels.tools.sm_exceptionsR   R}   R~   t   _model_params_docR   R   t   LikelihoodModelR   t   LikelihoodModelResultsR   t   ResultsWrapperR   t   populate_wrapperR{   t   statsmodels.apit   apit   smt   datasetst	   macrodatat   loadR'   t   mdatat   xRT   RK   R   t	   DataFramet   dft   ex_mod(    (    (    s=   lib/python2.7/site-packages/statsmodels/tsa/base/tsa_model.pyt   <module>   s:   R		  ;	K%