
    M/Ph^                        d dl mZ d dlZd dlmZ d dlZd dlm	Z	 d dl
Z
d dlmZ d dlm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j                    j        Z G d de          Z e
j        ddd dg dg          d             Z e
j        ddg dddddddgddgdg          d             Z  e
j        ddddddg          d             Z! e
j        dddg          d             Z" e
j        dg d          d             Z# e
j        dddg          d             Z$ e
j        dd dg          d             Z% e
j        ddddddg          d             Z& e
j        dddg          d              Z' e
j        dddg          d!             Z( e
j        ddd"g          d#             Z) e
j        d$          d%             Z e
j        dddg          d&             Z*d'efd(Z+d) Z,d*efd+Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d*efd1Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<e
j=        j>        d;             Z?d< Z@e
j=        A                    d=g d>          e
j=        A                    d?dd@g          e
j=        A                    dAd@dg          dB                                     ZBdC ZCdD ZDdE ZEdF ZFdG ZGdH ZHdI ZIdJ ZJdK ZKdL ZLe
j=        j>        e
j=        jM        e
j=        A                    dMg d          e
j=        A                    dNddg          dO                                                 ZNd*efdPZOdQ ZPd*efdRZQdS ZRe
j=        A                    dTddg          e
j=        A                    dUddg          dV                         ZSe
j=        A                    dWg dX          dY             ZTe
j=        A                    dWg dX          dZ             ZUe
j=        A                    d[dejV        W                    d           d ddgejV        X                    ddg          g          d\             ZYd] ZZdS )^    )
NamedTupleN)assert_allclose)assert_index_equal)danish_data)Summary)SpecificationWarning)AutoReg)ARDLUECMARDLResultsardl_select_order)DeterministicProcessc                   8    e Zd ZU ej        ed<   ej        ed<   dS )DatasetyxN)__name__
__module____qualname__pdSeries__annotations__	DataFrame     d/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/ardl/tests/test_ardl.pyr   r      s&         	yLLL	|OOOOOr   r   module   )         )scopeparamsc                     | j         S Nparamrequests    r   lagsr*      
    =r   r    )r   r      r   lryiboidec                     | j         S r%   r&   r(   s    r   orderr2   "   s     =r   c                     | j         S r%   r&   r(   s    r   
uecm_orderr4   /   s     =r   c                     | j         S r%   r&   r(   s    r   	uecm_lagsr6   :   r+   r   )ncctc                     | j         S r%   r&   r(   s    r   trendr;   ?   r+   r   TFc                     | j         S r%   r&   r(   s    r   causalr=   D   r+   r   c                     | j         S r%   r&   r(   s    r   maxlagr?   I   r+   r   c                     | j         S r%   r&   r(   s    r   maxorderrA   N   r+   r   c                     | j         S r%   r&   r(   s    r   seasonalrC   S   r+   r   c                     | j         S r%   r&   r(   s    r   	use_numpyrE   X   r+   r   
   c                     | j         S r%   r&   r(   s    r   	hold_backrH   ]   r+   r   )r"   c                  X    t           j        } t           g d         }t          | |          S )Nr-   )	dane_datalrmr   )r   r   s     r   datarL   b   s(    A'''(A1a==r   c                     | j         d S t          j        j        }t          j                            d          }t          j        |	                    dt          j        j
        d         df          |ddg          S )Nr   rF   r    z0z1)indexcolumns)r'   rJ   rK   rP   nprandomdefault_rngr   r   
standard_tshape)r)   rP   gens      r   fixedrX   i   sq    }tME
)


"
"C<rIM/2A677t   r   resc                    | j         }|j        j        \  }}|                    | j                  j        |fk    sJ |                    | j                  j        ||fk    sJ t          |                    | j                  t                    sJ |	                    | j                  j        ||fk    sJ t          |j
        t                    sJ |j        t          |j        t                    sJ t          |j        t                    sJ t          |j        t                     sJ t          |j        t$                    sJ t          |j        t                     sJ t          |j        t                     sJ t          |j        t,                    sJ t          |j        t                     sJ |                                  |                                  |                                  | j        t          | j        t                    sJ | j        | j        | j        z
  k    sJ | j        | j        k    sJ t          | j        t                    sJ d S r%   )model_xrV   scorer#   hessian
isinstanceloglikefloatinformation
exog_nameslistar_lagsrC   boolrH   int
ardl_ordertupledf_modelnobsendog_namesstr
k_constantsummarytest_heteroskedasticitydiagnostic_summarydf_residscalesigma2fpe)rY   r[   r7   ks       r   check_resultsrw   v   s.   )E8>DAq;;sz""(QD0000==$$*q!f4444emmCJ//77777SZ((.1a&8888e&-----= Ju}d$C$C   end+++++eos+++++e&.....enc*****ej#&&&&&e'-----e&,,,,,KKMMM!!!;*S[$"?"?<CHs|344449
""""cgu%%%%%%%r   c                 @   | j         }| j        }|}d }|rt          j        |          }t          j        |          }t	          |t
                    r+d t          |                                          D             }|t          j        |          }|rdnd }|||||fS )Nc                     i | ]\  }}||	S r   r   ).0ivs      r   
<dictcomp>z%_convert_to_numpy.<locals>.<dictcomp>   s    @@@daQ@@@r   r!   )r   r   rR   asarrayr_   dict	enumeratevalues)	rL   rX   r2   rC   rE   r   r   zperiods	            r   _convert_to_numpyr      s    AAAF )JqMMJqMMeT"" 	A@@i&?&?@@@E
5!!A(DaE6!!r   rL   c                 Z   t          | ||||          \  }}	}
}}t          |||	||||
||	  	        }|                                }t          |           |                                 d }|
Qt          j        |
          d d         }t          |
t          j	                  rt          j	        ||
j
                  }d }|	Qt          j        |	          d d         }t          |	t          j	                  rt          j	        ||	j
                  }|                    d||           d S )Nr=   rX   rC   r      )rQ   )exogrX   )r   r
   fitrw   predictrR   arrayr_   r   r   rQ   forecast)rL   r*   r2   r;   r=   rX   rE   rC   r   r   r   r   modrY   	fixed_oosexog_ooss                   r   test_model_initr      s8    /eUHi Aq!UF 		
 
 
C ''))C#KKMMMI}HQKK$	a&& 	CY	BBBIH}8A;;ss#a&& 	A|Hai@@@HLL()L44444r   c           
      $   t          j        t          d          5  t          | j        d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        g d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        dd	
           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        dd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        ddgdddd	           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        ddgdddd	           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        g ddg ddd	           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        g dd	           d d d            d S # 1 swxY w Y   d S )Nlags must be a non-negativematch#All values in lags must be positive)r   r   r    zinteger orders must be at leastr    r   T)r2   r=   Fr=   z)sequence orders must be strictly positiver   r   r-   z)sequence orders must contain non-negativeapplez%sequence orders must contain distinct)r   r   r    r   )r   r   r   r   r   r    )pytestraises
ValueErrorr
   r   r   	TypeErrorrL   s    r   test_ardl_order_exceptionsr      s   	z)F	G	G	G  TVR              	?
 
 
 ! ! 	TVZZZ   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 
z)J	K	K	K 6 6TVQa55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6	z)J	K	K	K 2 2TVQ511112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	E
 
 
 
 
 	FAtv1vaBB4	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
D
 
 
 	
 	
 	FFL155	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 
A
 
 
 	
 	
 	FF LL999==	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 
E
 
 
 8 8 	TVQ			$77778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   >AA$BBB.CC C?D**D.1D.%FFF'%GGG>'H11H58H5!JJ	J	c           
      `   t          j        t          d          5  t          | j        d| j        ddgdddd	           d d d            n# 1 swxY w Y   t          j        t          d
          5  t          | j        d| j        dddgid	           d d d            d S # 1 swxY w Y   d S )Nz,order dictionary contains keys for exogenousr   r    r   r   r!   )r.   r/   otherFr   zexog contains variables thatr.   )r   r   r   r
   r   r   warnsr   r   s    r   test_ardl_order_keys_exceptionsr      sX   	H
 
 
 	
 	
 	FFF1q11	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 
$B
 
 
 ? ? 	TVQA>>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s#   %AAA3#B##B'*B'c           	         t          j        t                    5  t          | j        d| j        dd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        j	        dd          }t          | j        d| j        d|d	
           d d d            d S # 1 swxY w Y   d S )Nr    rC   )deterministiczWhen using deterministic, trendr   Tr   constantr2   r9   )r   r;   )
r   r   r   r
   r   r   r   r   r   rP   )rL   r   s     r   "test_ardl_deterministic_exceptionsr      s[   	y	!	! = =TVQ<<<<= = = = = = = = = = = = = = =	$E
 
 
 L L -FL4q
 
 
 	TVQdKKKKL L L L L L L L L L L L L L L L L Ls#   AA	A	+<B44B8;B8c                     t          j        t          d          5  t          | j        d| j        dd           d d d            d S # 1 swxY w Y   d S )Nzhold_back must be >=r   r    r   rH   r   r   r   r
   r   r   r   s    r   test_ardl_holdback_exceptionsr   
  s    	z)?	@	@	@ 0 0TVQQ////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   AAAc                    t           j                            d          }t          j        t
          d          5  t          | j        d| j        d|           d d d            n# 1 swxY w Y   t           j                            t          j
        j        d         df          }t           j         |d<   t          j        t
          d          5  t          | j        d| j        d|           d d d            d S # 1 swxY w Y   d S )N)r       zfixed must be anr   r    rX   r   )   r   )rR   rS   standard_normalr   r   r   r
   r   r   rJ   rK   rV   inf)rL   rX   s     r   test_ardl_fixed_exceptionsr     sg   I%%h//E	z);	<	<	< 0 0TVQ////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0I%%y}':1'=q&ABBEF7E%L	z);	<	<	< 0 0TVQ////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s#   A&&A*-A*C>>DDc	                 :   t          | ||||          \  }	}
}}}t          |	||
||||||||          }t          |j        t                    sJ t          |j        t          j                  sJ t          |j        t          j                  sJ t          |j	        t          j                  sJ |j
        |k    sJ |j        |k    sJ |j        |k    sJ t          |j        t                    sJ |j        t          |j        t                     sJ d S d S )N)rX   r=   rH   r   rC   glob)r   r   r_   r[   r
   aicr   r   bichqicr   r;   rC   dl_lagsr   re   rd   )rL   r?   rA   r;   r=   rX   rE   rC   rH   r   r   r   r   rY   s                 r   test_ardl_select_orderr     sD    !2eXx! !Aq!Xv 		  C ci&&&&&cgry)))))cgry)))))ch	*****:9<8####ck4(((((;*S[$"?"?r   c           	          t          | j        d | j        d d d dd                                          }|j        j        d         dk    sJ t          |           d S )Nr-   r7   r;   r   r
   r   r   r   r#   rV   rw   rL   rY   s     r   test_ardl_no_regressorsr   ?  sr    
T$//   
cee  :A!#####r   c                     t          | j        d| j        d d                                          }|j        j        d         dk    sJ t          |           d S )Nr   r7   r   r   r   r   s     r   test_ardl_only_y_lagr   K  sY    
tvq$&$c
2
2
2
6
6
8
8C:A!#####r   c           	      V   t          | j        d | j        ddddd                                          }|j        j        d         dk    sJ t          | j        d | j        dddddd	
                                          }|j        j        d         dk    sJ t          |           d S )Nr   r    r   r-   r7   r   r   	   T)r;   r=      r   r   s     r   test_ardl_only_xr   Q  s    
dfa!<<C  	cee  :A!####
!A&&   
cee  :A!#####r   c                     t          | j        d | j        d d                                          }|j        j        d         dk    sJ t          |           d S )Nr8   r   r   r   r   r   s     r   test_ardl_only_trendr   b  sY    
tvtTVT
5
5
5
9
9
;
;C:A!#####r   c                     t          | j        d | j        d dd                                          }|j        j        d         dk    sJ t          |           d S )Nr7   Tr;   rC   r   r!   r   r   s     r   test_ardl_only_seasonalr   h  s[    
tvtTVTt
D
D
D
H
H
J
JC:A!#####r   c                     t          | j        j        dd          }t          | j        d | j        d d|                                          }|j        j        d         dk    sJ t          |           d S )NTr   r   r7   )r;   r   r   r!   )	r   r   rP   r
   r   r   r#   rV   rw   )rL   r   rY   s      r   test_ardl_only_deterministicr   n  s|    (ANNNM
dfd#]  	cee  :A!#####r   c                     t          | j        d | j        d dd                                          }|j        j        d         dk    sJ t          |           d S )Nr9   Tr   r   r,   r   r   s     r   test_ardl_no_endog_exogr   w  s[    
tvtTVT
E
E
E
I
I
K
KC:A!#####r   c                     t          | j        ddg| j        d dd                                          }|j        j        d         dk    sJ t          |           d S )Nr   r!   r9   Tr   r      r   r   s     r   test_ardl_no_exogr   }  s_    
tv1vtvt4$
G
G
G
K
K
M
MC:A!#####r   c           
         t          | j        d| j        ddd          }g d}|j        |k    sJ t          t	          j        | j                  dt	          j        | j                  ddd          }g d}|j        |k    sJ t          t	          j        | j                  dgt	          j        | j                  d dd	dd
          }g d}|j        |k    sJ d S )Nr    Tr8   )r=   r;   )	constlrm.L1zlrm.L2zlry.L1zlry.L2zibo.L1zibo.L2zide.L1zide.L2Fr9   )r   r;   zy.L1y.L2zx0.L0zx0.L1zx0.L2zx1.L0zx1.L1zx1.L2zx2.L0zx2.L1zx2.L2r7   r!   )r=   r;   rC   r   )zs(1,4)zs(2,4)zs(3,4)zs(4,4)r   )r
   r   r   rc   rR   r~   )rL   r   expecteds      r   test_ardl_parameter_namesr     s   
tvq$&!D
<
<
<C
 
 
H >X%%%%


46Arz$&111U$  C  H >X%%%%


46	


46	 	 	C @??H>X%%%%%%r   c           	          dd l }t          | j        d| j        ddddgddd                                          }|                                }t          ||j        j                  sJ d S )	Nr   r    r   r   r-   r9   Tr   )	matplotlib.figurer
   r   r   r   plot_diagnosticsr_   figureFigure)rL   close_figures
matplotlibrY   figs        r   test_diagnostics_plotr     s    
	!QF++   
cee  


 
 Cc:,34444444r   c                    t          | j        d||          }t          | j        d||          }|                                }|                                }t	          |j        |j                   |j        |j        k    sJ |j        |j        k    sJ |j        |j        k    sJ |	                    d          }|	                    d          }t	          ||           t          |j        |j                   |                                }|                                }t	          ||           t          |j        |j                   d S )Nr   r   r   )r	   r   r
   r   r   r#   re   r;   rC   r   r   rP   r   )	rL   r;   rC   arardlar_resardl_resar_fcast
ardl_fcasts	            r   test_against_autoregr     s4   	%(	;	;	;B:::DVVXXFxxzzHFM8?333>X-----8tz!!!!;$-''''r""H""2&&JHj)))x~z'7888~~H!!##JHj)))x~z'788888r   start)Nr   r    r!   endr   dynamicc                 j   t          | j        d||          }t          | j        d||          }|                                }|                                }	|                    |||          }
|	                    |||          }t          |
j        |j                   t          |
|           d S )Nr   r   )r   r   r   )r	   r   r
   r   r   r   rP   r   )rL   r;   rC   r   r   r   r   r   r   r   r   r   s               r   &test_against_autoreg_predict_start_endr     s     
%(	;	;	;B:::DVVXXFxxzzH~~EsG~DDH!!3!HHJx~z'7888Hj)))))r   c                 b   t          j        t          d          5  t          | j        d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        g d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        g d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        d	d
           d d d            d S # 1 swxY w Y   d S )Nr   r   r   r   )r   r   r    )r   r    r    r   zhold_back must be r   r!   r   r   r   s    r   test_invalid_initr     s.   	z)F	G	G	G  TVR              	?
 
 
 ! ! 	TVZZZ   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 
?
 
 
 # # 	TV\\\"""# # # # # # # # # # # # # # # 
z)=	>	>	> 0 0TVQQ////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0sE   >AA$BBB.CCC8D$$D(+D(c                 f   t          | j        d| j        dd                                          }|                    d          }|j        d         dk    sJ t          | j        dg| j        dg                                          }|                    d          }|j        d         dk    sJ d S )Nr    r   Tr   r   r   )r
   r   r   r   r   rV   )rL   rY   vals      r   test_prediction_oos_no_new_datar     s    
tvq$&!D
1
1
1
5
5
7
7C
,,q//C9Q<1
tvsDFQC
(
(
,
,
.
.C
,,q//C9Q<1r   c                    t          | d dd|          \  }}}}}t          |d|dd                                          }t          j        t
          d          5  |                    d           d d d            n# 1 swxY w Y   t          |t          j	                  rt          j        | j                  d d         }	t          j        t          d	          5  |                    d|	
           d d d            n# 1 swxY w Y   t          j        t
          d          5  |                    d| j        j        d dd df         
           d d d            d S # 1 swxY w Y   d S d S )Nr   Fr    r   zexog_oos must ber   r   r   z!exog_oos must be a DataFrame whenr   zmust have the same columns)r   r
   r   r   r   r   r   r_   r   r   rR   r~   r   r   iloc)
rL   rX   rE   r   r   r   r2   _rY   r   s
             r   test_prediction_exceptionsr     s)   )$a	JJAq!UA
q!Q%
(
(
(
,
,
.
.C	z);	<	<	<  Q              !R\"" 8:df%%crc*]@
 
 
 	, 	, LL(L+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, ]:-IJJJ 	8 	8LL$&+crc2A2g"6L777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	88 8s6   A==BBDD	D(.E##E'*E'c                 $   t          | j        d| j        ddg                                          }|                                }|                    | j                  }t          ||           t          |j        |j                   t          | j        d| j        ddg|                                          }|                                }|                    |          }t          ||           t          |j        |j                   d S )Nr!   r   r   r   r   )r
   r   r   r   r   r   r   rP   )rL   rX   rY   directalts        r   test_prediction_replacementsr     s    
tvq$&1a&
)
)
-
-
/
/C[[]]F
++46+
"
"CFC   v|SY///
tvq$&1a&
6
6
6
:
:
<
<C[[]]F
++E+
"
"CFC   v|SY/////r   c                    t          j        | j                  }t          | j        d|ddg                                          }t          j        t          d          5  |	                    t          j        | j                  d d d df                    d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    t          j        | j                  d d                    d d d            n# 1 swxY w Y   t          | j        d| j        ddg                                          }t          j        t          d	          5  |	                    | j        j
        d d d df                    d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    | j        j
        d d                    d d d            d S # 1 swxY w Y   d S )
Nr!   r   r   zexog must have the same numberr   r   z&exog must have the same number of rowszexog must have the same columnsrR   r~   r   r
   r   r   r   r   r   r   r   rL   r   rY   s      r   test_prediction_wrong_shaper     s   

46A
tvq!aV
$
$
(
(
*
*C	z)I	J	J	J 4 4DF++AAArrE23334 4 4 4 4 4 4 4 4 4 4 4 4 4 4	B
 
 
 2 2 	DF++CRC01112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 tvq$&1a&
)
)
-
-
/
/C	z)J	K	K	K - -QQQU+,,,- - - - - - - - - - - - - - -	B
 
 
 + + 	SbS)***+ + + + + + + + + + + + + + + + + +sH    :B&&B*-B*6DDD$-FF!$F!)G99G= G=c                    t          j        | j                  }t          | j        d|                                          }t          j        t          d          5  |	                    t          j        | j                  d d d df                    d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    t          j        | j                  d d                    d d d            n# 1 swxY w Y   t          | j        d| j                                                  }t          j        t          d          5  |	                    | j        j
        d d d df                    d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    | j        j
        d d                    d d d            d S # 1 swxY w Y   d S )Nr!   r   zfixed must have the same numberr   r   z'fixed must have the same number of rowsr   r   r   s      r   !test_prediction_wrong_shape_fixedr  0  s   

46A
tvq
"
"
"
&
&
(
(C	z)J	K	K	K 5 5"*TV,,QQQU34445 5 5 5 5 5 5 5 5 5 5 5 5 5 5	C
 
 
 3 3 	"*TV,,SbS12223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 tvq
'
'
'
+
+
-
-C	z)J	K	K	K . .$&+aaa!e,---. . . . . . . . . . . . . . .	C
 
 
 , , 	$&+crc*+++, , , , , , , , , , , , , , , , , ,sH   :B$$B(+B(
6DDD -FF F?)G55G9<G9c                 h   t          j        | j                  }t          | j        d|                                          }t          j        t          d          5  |	                    d           d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    d|d d                    d d d            n# 1 swxY w Y   t          | j        d| j        dd	
                                          }t          j        t          d          5  |	                    d           d d d            n# 1 swxY w Y   t          j        t          d          5  |	                    d| j        j
        dd                     d d d            d S # 1 swxY w Y   d S )Nr!   r   zfixed_oos must be providedr   r   zfixed_oos must have at least   r   Tr   zexog_oos must be providedzexog_oos must have at leastir   )rR   r~   r   r
   r   r   r   r   r   r   r   r   s      r   test_insuficient_oosr  B  s}   

46A
tvq
"
"
"
&
&
(
(C	z)E	F	F	F  R              	z)G	H	H	H ' 'Rq"v&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '
tvq$&!D
1
1
1
5
5
7
7C	z)D	E	E	E  R              	z)F	G	G	G 1 1Rdfk#$$/0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1sH   B  BB& CCC(E

EE0*F''F+.F+c                     t          j        t          d          5  t          | j        d| j        d           d d d            d S # 1 swxY w Y   d S )NzThe number of regressors \(36\)r   r   r!   r   r   s    r   test_insuficient_datar  P  s    	z)K	L	L	L $ $TVR###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   AA
A
c                     t          | j        d                                          }|                    d          }|                    d          }t	          ||           t          |j        |j                   d S )Nr   r   z
1990-07-01)r
   r   r   r   r   r   rP   )rL   rY   numericdates       r   test_forecast_dater  U  si    
tvq//



Cll2G<<%%DGT"""w}dj11111r   c                 b   t          | j        d                                          }t          | j        d                                          }|                    d          }|                    d          }t          |j        |j                   t          |j        |j                   d S )Nr   z
2020-01-01r   )r
   r   r   r	   get_predictionr   predicted_meanvar_pred_mean)rL   rY   r   predar_preds        r   test_get_predictionr  ]  s    
tvq//



CTVQ##%%F,//D###55GD')?@@@D&(=>>>>>r   r;   rC   c                    ddl m} t          | j        d||          }|                                }|                                }t          ||          sJ |                    d          }t          ||          sJ |                    dd d	          }t          ||          sJ t          |                                t                    sJ d S )
Nr   )r   r   r   d   r  K   F)r   alpha	in_sample)
r   r   r
   r   r   r   r_   plot_predictro   r   )rL   rC   r;   r   r   r   rY   r   s           r   test_ardl_smoke_plotsr  f  s    
 )(((((
		  C ''))C



 
 Cc6"""""


s

#
#Cc6"""""


r

?
?Cc6"""""ckkmmW-------r   c                    t          | ||||          \  }}	}
}}t          |||	||||
||	  	        }|                                }t          |           |                                 t          |||	||||
||	  	        }t          j        |          }|                                }t          |           |                                 d S )Nr   )r   r   r   rw   r   r
   	from_ardl)rL   r6   r4   r;   r=   rX   rE   rC   r   r   r   r   r   rY   r   uecmuecm_ress                    r   test_uecm_model_initr  }  s     #4eZ9# #Aq!Z 		
 
 
C ''))C#KKMMM		
 
 
D >$DxxzzH(r   c                     t          j        t                    5  t          j        t          | j        d| j        ddd d                    }d d d            n# 1 swxY w Y   |j        dk    sJ d S )Nr    r.   r0   r/   )r    r    r    )	r   r   r   r   r  r
   r   r   rh   )rL   r   s     r   test_from_ardl_noner"    s    	*	+	+ 
 
nDFAa$E$EFF
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 >Y&&&&&&s   3AA Ac           	      f   d}t          j        | j        | j        gd          }|8|dd                    |j                  z   z  }t          j        ||gd          }t          j        |||||||          }	|	                                }
t          |
           |

                                 d S )Nzlrm ~ lry + ibo + ider   )axisz | z + )r=   rC   )r   concatr   r   joinrQ   r   from_formular   rw   r   )rL   r6   r4   r;   r=   rX   rC   fmladfr   rY   s              r   test_uecm_model_formular*    s     #D	DFDF#!	,	,	,B

5=1111YE{+++


  C ''))C#KKMMMMMr   c           
         t          j        t          d          5  t          | j        d| j        g d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        ddg| j        d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        dddgi           d d d            n# 1 swxY w Y   t          j        t          d	          5  t          | j        d| j        d            d d d            n# 1 swxY w Y   t          j        t          d
          5  t          | j        d| j        dddd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        dd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          | j        d| j        d           d d d            n# 1 swxY w Y   t          | j        d| j        ddgddd          }t          j        t          d          5  t          j        |           d d d            n# 1 swxY w Y   t          | j        d| j        ddgddd          }t          j        t          d          5  t          j        |           d d d            n# 1 swxY w Y   t          | j        ddg| j        d          }t          j        t          d          5  t          j        |           d d d            n# 1 swxY w Y   t          | j        d| j        d          	                                }t          j        t                    5  |                    d           d d d            n# 1 swxY w Y   t          j        t                    5  |                    d           d d d            n# 1 swxY w Y   t          j        t                    5  |                    d           d d d            d S # 1 swxY w Y   d S )Nzorder must be Noner   r    r   zlags must be anr   zorder values must be positiver/   zModel must containzAll included exogr   r!  zhold_back must ber   r,   r!   r   zThe number ofr   zUECM can only be created fromr  r  T)r      )r   r   r   r   r   r   r   r
   r  r   NotImplementedErrorr   )rL   r   rY   s      r   test_uecm_errorsr.    s<   	y(<	=	=	= + +TVQ			***+ + + + + + + + + + + + + + +	y(9	:	:	: ( (TVaVTVQ'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	y(G	H	H	H 1 1TVQA0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	z)=	>	>	> & &TVQ%%%& & & & & & & & & & & & & & &	z)<	=	=	= @ @TVQ!A > >???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	z)<	=	=	= 0 0TVQQ////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	z	9	9	9 $ $TVR###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $46Aq6!A#F#FGGD	z)H	I	I	I  t              46Aq6!A#F#FGGD	z)H	I	I	I  t              A**D	z)H	I	I	I  t              
tvq$&!
$
$
(
(
*
*C	*	+	+                	*	+	+ " "D!!!" " " " " " " " " " " " " " "	*	+	+    B                                   s   AAA-BBB>!C++C/2C/D::D>D> !FFF3GG"%G"H--H14H15JJJK??LLM$$M(+M(6OO O=P  P$'P$Q((Q,/Q,rE   use_tc                 >   t           j        }t           g d         }| r(t          j        |          }t          j        |          }t	          |d|d          }|                    |          }| r-|j        d d                                         }||d         z  }n1|j        j        d d                                         }||d         z  }t          |j
        |           |j        j        dk    sJ |j        j        dk    sJ |j        j        dk    sJ dt          |                                          v sJ |                                j        d	k    sJ |                                j        d
k    sJ |j        j        t           j        j        k    sJ d S )Nr-   r   )r/  r,   r   r   )r,   zCointegrating Vector)r,   r    )r,   r,   )rJ   rK   rR   r~   r   r   r#   copyr   r   	ci_paramsci_bserV   
ci_tvalues
ci_pvaluesrm   
ci_summaryci_conf_intci_cov_params	ci_resids)rE   r/  r   r   r   rY   r2  s          r   test_uecm_ci_reprr:    s    	A'''(A JqMMJqMM
q!Q

C
'''

C )JrrN''))	Yq\!		JOBQB',,..	Yx((	CM9---:t####>4''''>4''''!S)9)9%:%:::::??"f,,,,$....=)-"5555555r   caser   r    r   r!   r,   c           	         t          t          j        dt          g d         dddd          }|                                }ddddd	d
}|                    |           }t          |j        ||                     dt          |          v sJ d S )Nr   r-   r   r    gy$.?gw@gA`@g;@g<,$@r<  BoundsTestResult)r   rJ   rK   r   bounds_testr   statrm   )r;  r   rY   r   bounds_results        r   test_bounds_testrB  
  s    
	'''(!A&&	 C ''))C H OOD))MM&777]!3!3333333r   c           	         t          t          j        dt          g d         dddd          }|                                }|                    | dg dd          }|j        d	k                                    sJ |j        d
k                                    sJ |j        d	k                                                                    sJ d S )Nr   r-   r   r    F)r   r    r   r!   '  r;  
asymptoticseednsim              ?r   rJ   rK   r   r?  p_valuesall	crit_vals)r;  r   rY   rA  s       r   test_bounds_test_simulationrO    s    
	'''(!A&&	 C ''))COOe,,,V $  M "c)..00000"c)..00000#c)..00446666666r   rG  c           	         t          t          j        dt          g d         dddd          }|                                }|                    dd| d          }|j        dk                                    sJ |j        d	k                                    sJ |j        dk                                                                    sJ d S )
Nr   r-   r   r    FrD  rE  rI  rJ  rK  )rG  r   rY   rA  s       r   test_bounds_test_seedrQ  0  s    
 	'''(!A&&	 C ''))COO5t& $  M "c)..00000"c)..00000#c)..00446666666r   c            	         t          t          j        dt          g d         dddd          } |                                 }|                    d          }dt          |          v sJ |                    dddg d	          }t          |j        |j                   |j        |j        k    	                                sJ d S )
Nr   r-   r   r    r>  FrD  )r   r    r   )rF  rH  rG  )
r   rJ   rK   r   r?  rm   r   r@  rL  rM  )r   rY   rA  bounds_result_sims       r   test_bounds_test_simulate_orderrT  D  s    
	'''(!A&&	 C ''))COOA&&M]!3!33333	e&yyy (   M&(9(>???&)??DDFFFFFFFr   )[typingr   numpyrR   numpy.testingr   pandasr   pandas.testingr   r   statsmodels.datasetsr   statsmodels.iolib.summaryr   statsmodels.tools.sm_exceptionsr   statsmodels.tsa.ar_modelr	   statsmodels.tsa.ardl.modelr
   r   r   r   statsmodels.tsa.deterministicr   load_pandasrL   rJ   r   fixturer*   r2   r4   r6   r;   r=   r?   rA   rC   rE   rH   rX   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   markr   r   r   parametrizer   r   r   r   r   r   r  r  r  r  r  smoker  r  r"  r*  r.  r:  rB  rO  rS   RandomStaterT   rQ  rT  r   r   r   <module>rf     s             ) ) ) ) ) )     - - - - - -  , , , , , , - - - - - - @ @ @ @ @ @ , , , , , ,            ? > > > > >#K#%%*	    j   
 haIII'>???  @? 
			!A&&1#q!f--	     
	!A&&     hay111  21 h'7'7'7888  98 he}555  65 h1v...  /. h1Qq+I+I'JKKK  LK he}555  65 he}555  65 hbz222  32 h    hay111	 	 21	&{ & & & &2" " "  5
 5  5  5  5F(8 (8 (8V? ? ?"	L 	L 	L0 0 0
0 0 0#@
#@ #@ #@ #@L	 	 	    "          ,& ,& ,&^ 5 5 5 9 9 9* ///22r
++RJ//* * 0/ ,+ 32*0 0 0  8 8 80 0 0+ + +$, , ,$1 1 1$ $ $
2 2 2? ? ? "2"2"233dE]33. . 43 43  .&+
+ + + +\' ' '
   8     B tUm444-006 6 10 5460 114 4 214( 117 7 217  
	29  ##QA	0E0Eq!f0M0MN 7 7	 7 G G G G Gr   