Module Expr Str ImportFrom alias Import alias identifier ImportFrom alias ImportFrom alias alias FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr For NameStore Call NameLoad NameLoad NameLoad body Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice BinOpAdd NameLoad Call AttributeLoad Call AttributeLoad BinOpMult SubscriptLoad NameLoad ExtSlice Slice BinOpSub NameLoad NameLoad NameLoad Slice Index AttributeLoad NameLoad attr NameLoad attr keyword Num attr keyword Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Num body Expr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad For NameStore Call NameLoad NameLoad NameLoad body Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice BinOpAdd BinOpAdd NameLoad Call AttributeLoad Call AttributeLoad BinOpMult SubscriptLoad NameLoad ExtSlice Slice BinOpSub NameLoad NameLoad NameLoad Slice Index AttributeLoad NameLoad attr NameLoad attr keyword Num attr keyword Num Call AttributeLoad Call AttributeLoad BinOpMult SubscriptLoad NameLoad ExtSlice Slice BinOpSub NameLoad NameLoad NameLoad Slice Index AttributeLoad NameLoad attr NameLoad attr keyword Num attr keyword Num Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice BinOpSub SubscriptLoad NameLoad ExtSlice Index NameLoad Slice SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Return TupleLoad NameLoad NameLoad decorator_list If CompareEq NameLoad Str body Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr BinOpMult ListLoad Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad NameLoad Assign SubscriptStore NameLoad ExtSlice Slice Slice Index Num ListLoad ListLoad Num Num ListLoad Num Num ListLoad Num Num Assign NameStore Call NameLoad NameLoad NameLoad Expr Call NameLoad Call AttributeLoad NameLoad attr CompareEq SubscriptLoad NameLoad ExtSlice Slice NameLoad Index Num BinOpMult Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Num Index Num Call AttributeLoad NameLoad attr NameLoad Num Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr BinOpMult ListLoad Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad NameLoad Assign SubscriptStore NameLoad ExtSlice Slice Slice Index Num ListLoad ListLoad Num Num ListLoad Num Num ListLoad Num Num Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad keyword NameLoad Expr Call NameLoad Call AttributeLoad NameLoad attr CompareEq NameLoad NameLoad Expr Call NameLoad Call AttributeLoad NameLoad attr CompareEq SubscriptLoad NameLoad ExtSlice Slice NameLoad Index Num BinOpAdd BinOpMult Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Num Index Num Call AttributeLoad NameLoad attr NameLoad Num NameLoad Assign SubscriptStore NameLoad Index TupleLoad Num Num Num Num Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index TupleLoad Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad Assign SubscriptStore NameLoad Index TupleLoad Num Num Num Num Assign SubscriptStore NameLoad ExtSlice Slice Slice Index Num ListLoad ListLoad Num Num ListLoad Num Num ListLoad Num Num Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr ListLoad Call AttributeLoad NameLoad attr NameLoad BinOpMult Num Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad ExtSlice Slice Slice Index Num Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad Assign SubscriptStore NameLoad ExtSlice Slice Slice Index Num Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad Assign SubscriptStore NameLoad Index TupleLoad Num Num Num Num Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad ExtSlice Slice Slice Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad ExtSlice Slice Slice Index Num Expr Call NameLoad Call AttributeLoad NameLoad attr CompareEq SubscriptLoad Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad ExtSlice Slice Slice Index Num Str ExtSlice Slice Num Index Num SubscriptLoad NameLoad ExtSlice Slice NameLoad Index Num Expr Call NameLoad Call AttributeLoad NameLoad attr CompareEq SubscriptLoad Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad ExtSlice Slice Slice Index Num Str ExtSlice Slice Num Index Num SubscriptLoad NameLoad ExtSlice Slice NameLoad Index Num ImportFrom alias alias Assign NameStore Call NameLoad SubscriptLoad NameLoad ExtSlice Slice Index Num Expr Call NameLoad CompareEq SubscriptLoad NameLoad Index Num Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index Num Assign NameStore Call NameLoad SubscriptLoad NameLoad ExtSlice Slice Index Num
N/A N/A VAR and VARMA process

this doesn't actually do much, trying out a version for a time loop

alternative representation:
* textbook, different blocks in matrices
* Kalman filter
* VAR, VARX and ARX could be calculated with signal.lfilter
  only tried some examples, not implemented

TODO: try minimizing sum of squares of (Y-Yhat)

Note: filter has smallest lag at end of array and largest lag at beginning,
    be careful for asymmetric lags coefficients
    check this again if it is consistently used


changes
2009-09-08 : separated from movstat.py

Author : josefpkt
License : BSD
 __future__ print_function N/A numpy np scipy signal numpy.testing assert_array_equal assert_array_almost_equal VAR N/A N/A x B const N/A 0 N/A N/A  multivariate linear filter

    Parameters
    ----------
    x: (TxK) array
        columns are variables, rows are observations for time period
    B: (PxKxK) array
        b_t-1 is bottom "row", b_t-P is top "row" when printing
        B(:,:,0) is lag polynomial matrix for variable 1
        B(:,:,k) is lag polynomial matrix for variable k
        B(p,:,k) is pth lag for variable k
        B[p,:,:].T corresponds to A_p in Wikipedia
    const: float or array (not tested)
        constant added to autoregression

    Returns
    -------
    xhat: (TxK) array
        filtered, predicted values of x array

    Notes
    -----
    xhat(t,i) = sum{_p}sum{_k} { x(t-P:t,:) .* B(:,:,i) }  for all i = 0,K-1, for all t=p..T

    xhat does not include the forecasting observation, xhat(T+1),
    xhat is 1 row shorter than signal.correlate

    References
    ----------
    http://en.wikipedia.org/wiki/Vector_Autoregression
    http://en.wikipedia.org/wiki/General_matrix_notation_of_a_VAR(p)
     N/A p N/A N/A B shape N/A 0 N/A T N/A N/A x shape N/A 0 N/A xhat N/A N/A np zeros N/A x shape N/A t N/A range p T N/A N/A N/A xhat N/A N/A t N/A N/A const N/A N/A N/A N/A N/A N/A x N/A N/A N/A t p t N/A N/A N/A np newaxis B sum axis 1 sum axis 0 N/A xhat N/A VARMA N/A N/A x B C const N/A 0 N/A N/A  multivariate linear filter

    x (TxK)
    B (PxKxK)

    xhat(t,i) = sum{_p}sum{_k} { x(t-P:t,:) .* B(:,:,i) } +
                sum{_q}sum{_k} { e(t-Q:t,:) .* C(:,:,i) }for all i = 0,K-1

     N/A P N/A N/A B shape N/A 0 N/A Q N/A N/A C shape N/A 0 N/A T N/A N/A x shape N/A 0 N/A xhat N/A N/A np zeros N/A x shape N/A e N/A N/A np zeros N/A x shape N/A start N/A max P Q N/A t N/A range start T N/A N/A N/A xhat N/A N/A t N/A N/A N/A const N/A N/A N/A N/A N/A N/A x N/A N/A N/A t P t N/A N/A N/A np newaxis B sum axis 1 sum axis 0 N/A N/A N/A N/A N/A N/A e N/A N/A N/A t Q t N/A N/A N/A np newaxis C sum axis 1 sum axis 0 N/A N/A e N/A N/A t N/A N/A N/A x N/A N/A t N/A N/A xhat N/A N/A t N/A N/A N/A xhat e N/A N/A N/A __name__ __main__ N/A N/A T 20 N/A K 2 N/A P 3 N/A x N/A N/A np column_stack N/A N/A N/A N/A np arange T K N/A B N/A N/A np ones N/A P K K N/A N/A B N/A N/A N/A N/A 1 N/A N/A 0 0 N/A 0 0 N/A 0 1 N/A xhat N/A VAR x B N/A N/A print N/A N/A np all N/A N/A xhat N/A N/A P N/A 0 N/A N/A N/A np correlate N/A x N/A N/A -1 N/A 0 N/A N/A np ones P 2 N/A T 20 N/A K 2 N/A Q 2 N/A P 3 N/A const 1 N/A x N/A N/A np column_stack N/A N/A N/A N/A np arange T K N/A B N/A N/A np ones N/A P K K N/A N/A B N/A N/A N/A N/A 1 N/A N/A 0 0 N/A 0 0 N/A 0 1 N/A C N/A N/A np zeros N/A Q K K N/A xhat1 N/A VAR x B const const N/A N/A xhat2 err2 N/A VARMA x B C const const N/A N/A print N/A N/A np all N/A xhat2 xhat1 N/A N/A print N/A N/A np all N/A N/A xhat2 N/A N/A P N/A 0 N/A N/A N/A N/A np correlate N/A x N/A N/A -1 N/A 0 N/A N/A np ones P 2 const N/A N/A C N/A N/A 1 1 1 0.5 N/A N/A xhat3 err3 N/A VARMA x B C N/A x N/A N/A np r_ N/A N/A N/A N/A np zeros N/A P K x N/A N/A xhat4 err4 N/A VARMA x B C N/A N/A C N/A N/A 1 1 1 1 N/A N/A B N/A N/A N/A N/A 1 N/A N/A 0 0 N/A 0 0 N/A 0 1 N/A N/A xhat5 err5 N/A VARMA x B C N/A x0 N/A N/A np column_stack N/A N/A N/A np arange T N/A 2 N/A N/A np arange T N/A N/A B N/A N/A N/A N/A 0 N/A N/A np ones N/A P K N/A N/A B N/A N/A N/A N/A 1 N/A N/A np ones N/A P K N/A N/A B N/A N/A 1 1 1 0 N/A xhat0 N/A VAR x0 B N/A xcorr00 N/A N/A signal correlate x0 N/A B N/A N/A N/A N/A 0 N/A xcorr01 N/A N/A signal correlate x0 N/A B N/A N/A N/A N/A 1 N/A N/A print N/A N/A np all N/A N/A N/A N/A signal correlate x0 N/A B N/A N/A N/A N/A 0 valid N/A N/A -1 N/A 0 N/A xhat0 N/A N/A P N/A 0 N/A N/A print N/A N/A np all N/A N/A N/A N/A signal correlate x0 N/A B N/A N/A N/A N/A 1 valid N/A N/A -1 N/A 0 N/A xhat0 N/A N/A P N/A 1 statsmodels.tsa.stattools acovf acf N/A aav N/A acovf N/A x N/A N/A N/A 0 N/A N/A print N/A N/A aav N/A 0 N/A N/A np var N/A x N/A N/A N/A 0 N/A aac N/A acf N/A x N/A N/A N/A 0