SPB Git

Repository Public

job_var_model.json 24.1 KB 2 lines json

1{"job":{"id":"8ea7ab04-bdd7-4a64-b479-bbe92e7fed8e","tool":"var_model","params":{"symbols":["SPY","TLT"],"period_days":1260,"var_on":"returns","lags":0,"max_lags":10,"criterion":"bic","irf_horizon":10,"cumulative":false,"band_level":0.95,"deterministic":"constant","coint_lags":-1,"rank_test":"trace"},"status":"done","startedAt":1795211368532,"finishedAt":1795211373514,"error":null,"progress":1,"engineVersion":"1.0.0","durationMs":4982,"projectId":null,"sessionId":null,"cancellable":false,"code":"import numpy as np, pandas as pd\nfrom statsmodels.tsa.api import VAR\nfrom statsmodels.tsa.stattools import coint\nfrom statsmodels.tsa.vector_ar.vecm import coint_johansen, VECM\n# prices: DataFrame of adjusted daily closes, columns ['SPY', 'TLT'] in this order, 2021-11-12 → 2026-11-20\nlogp = np.log(prices)\ndata = logp.diff().dropna().reset_index(drop=True)\nres = VAR(data).fit(1, trend=\"c\")\nprint(res.summary()); print(\"stable:\", res.is_stable())\nprint(res.test_causality('TLT', ['SPY'], kind=\"f\").summary())\nirf = res.irf(10); print(irf.orth_irfs[:3]); print(res.fevd(11).decomp[:, -1, :])\nj = coint_johansen(logp.values, 0, 1); print(j.lr1, j.cvt, j.lr2, j.cvm)\nprint(coint(logp['SPY'], logp['TLT'], trend=\"c\", autolag=\"aic\"))\n# if rank > 0: VECM(logp.values, k_ar_diff=1, coint_rank=rank, deterministic='co').fit()","result":{"success":true,"schema":"lab/1","engine":"var_model","engineVersion":"1.0.0","title":"SPY · TLT — VAR and cointegration","headline":"VAR(1) on returns of SPY, TLT: 0 significant Granger links out of 2, stable (largest eigenvalue modulus 0.057); no cointegration is found (Johansen).","summary":[{"label":"VAR lags","value":1,"unit":"count","kind":"calculated","note":"Selected by BIC up to 10"},{"label":"Observations","value":1259,"unit":"count","kind":"observed","note":"2021-11-15 → 2026-11-20"},{"label":"Largest eigenvalue modulus","value":0.056716597512517314,"unit":"ratio","kind":"calculated","decimals":4,"note":"Of the companion matrix; below 1 = stable"},{"label":"Significant Granger links (5 %)","value":0,"unit":"count","kind":"calculated","note":"Out of 2 directed pairs"},{"label":"Largest residual correlation","value":0.08474866182009148,"unit":"ratio","kind":"calculated","decimals":3,"note":"Between the innovations of two equations"},{"label":"Cointegration rank (Johansen)","value":0,"unit":"count","kind":"calculated","note":"By the trace test at 5 %; trace → 0, max-eigenvalue → 0"},{"label":"Cointegrated pairs (Engle-Granger, 5 %)","value":0,"unit":"count","kind":"calculated","note":"Out of 2 ordered pairs"}],"tables":[{"id":"integration","title":"Order of integration (ADF, constant)","columns":[{"key":"symbol","label":"Series","align":"left"},{"key":"adf_level_p","label":"ADF p-value, log price","decimals":4},{"key":"adf_diff_p","label":"ADF p-value, return","decimals":4},{"key":"verdict","label":"Reading","align":"left"}],"rows":[{"symbol":"SPY","adf_level_p":0.902092868190957,"adf_diff_p":0,"verdict":"I(1): unit root in the level, stationary return"},{"symbol":"TLT","adf_level_p":0.03376019183656268,"adf_diff_p":0,"verdict":"stationary level"}],"note":"H0 of the ADF test is a unit root. Cointegration tests presuppose that every series is I(1)."},{"id":"lag_selection","title":"Lag selection","columns":[{"key":"lag","label":"Lags","decimals":0},{"key":"aic","label":"AIC","decimals":4},{"key":"bic","label":"BIC","decimals":4},{"key":"hqic","label":"HQ","decimals":4},{"key":"selected","label":"Selected by","align":"left"}],"rows":[{"lag":0,"aic":-18.27968576250852,"bic":-18.271476324380046,"hqic":-18.276599563181684,"selected":"BIC, HQIC"},{"lag":1,"aic":-18.280142255714104,"bic":-18.25551394132868,"hqic":-18.270883657733595,"selected":""},{"lag":2,"aic":-18.28136058212779,"bic":-18.240313391485415,"hqic":-18.26592958549361,"selected":""},{"lag":3,"aic":-18.283360822294387,"bic":-18.225894755395068,"hqic":-18.26175742700654,"selected":"AIC"},{"lag":4,"aic":-18.279291881344154,"bic":-18.20540693818789,"hqic":-18.251516087402635,"selected":""},{"lag":5,"aic":-18.273166521465935,"bic":-18.18286270205272,"hqic":-18.239218328870745,"selected":""},{"lag":6,"aic":-18.26867654005996,"bic":-18.161953844389796,"hqic":-18.2285559488111,"selected":""},{"lag":7,"aic":-18.26339877739549,"bic":-18.140257205468377,"hqic":-18.217105787492958,"selected":""},{"lag":8,"aic":-18.26214232987264,"bic":-18.12258188168858,"hqic":-18.209676941316438,"selected":""},{"lag":9,"aic":-18.25694123098413,"bic":-18.10096190654312,"hqic":-18.198303443774257,"selected":""},{"lag":10,"aic":-18.254657401270457,"bic":-18.082259200572498,"hqic":-18.18984721540691,"selected":""}],"note":"Criteria of the VAR with a constant, all lag lengths estimated on the same sample."},{"id":"coefficients","title":"VAR(1) coefficients","columns":[{"key":"equation","label":"Equation","align":"left"},{"key":"term","label":"Term","align":"left"},{"key":"estimate","label":"Estimate","decimals":5},{"key":"std_error","label":"Std. error","decimals":5},{"key":"t","label":"t","decimals":2},{"key":"p","label":"p-value","decimals":4},{"key":"ci_low","label":"95 % CI low","decimals":5},{"key":"ci_high","label":"95 % CI high","decimals":5}],"rows":[{"equation":"SPY","term":"Constant","estimate":0.0003550329647971071,"std_error":0.00030941168882400076,"t":1.1474452246665334,"p":0.25119765918002124,"ci_low":-0.00025140280169364877,"ci_high":0.000961468731287863},{"equation":"SPY","term":"SPY (t−1)","estimate":-0.020570051381657153,"std_error":0.028431552020707317,"t":-0.723493791920875,"p":0.469376566790383,"ci_low":-0.07629486936682049,"ci_high":0.03515476660350618},{"equation":"SPY","term":"TLT (t−1)","estimate":-0.04523138561711774,"std_error":0.03157587107373072,"t":-1.4324667563881588,"p":0.15201028547793832,"ci_low":-0.10711895570211004,"ci_high":0.016656184467874563},{"equation":"TLT","term":"Constant","estimate":-0.000352309154466696,"std_error":0.0002769666860975874,"t":-1.2720271864846668,"p":0.2033634599873304,"ci_low":-0.0008951538841353779,"ci_high":0.00019053557520198585},{"equation":"TLT","term":"SPY (t−1)","estimate":0.04737384592814142,"std_error":0.025450210926794323,"t":1.8614323497910819,"p":0.06268314576256831,"ci_low":-0.002507650887323201,"ci_high":0.09725534274360605},{"equation":"TLT","term":"TLT (t−1)","estimate":-0.05221123273483406,"std_error":0.028264815738459226,"t":-1.8472164551842998,"p":0.06471577544098904,"ci_low":-0.10760925361187504,"ci_high":0.003186788142206916}],"note":"OLS equation by equation, 1259 observations, 1 lag(s). Dependent variables: log returns (first differences of log prices)."},{"id":"granger","title":"Granger causality (pairwise, within the VAR)","columns":[{"key":"cause","label":"Cause","align":"left"},{"key":"effect","label":"Effect","align":"left"},{"key":"f","label":"F","decimals":3},{"key":"df","label":"df","align":"left"},{"key":"p","label":"p-value","decimals":4},{"key":"causes","label":"Granger-causes at 5 %","align":"left"}],"rows":[{"cause":"SPY","effect":"TLT","f":3.464930392848748,"df":"1, 2512","p":0.06279986842920827,"causes":"no"},{"cause":"TLT","effect":"SPY","f":2.051961008157213,"df":"1, 2512","p":0.15213471017726626,"causes":"no"}],"note":"H0: the 1 lag(s) of the cause have zero coefficients in the equation of the effect, given the lags of all other series. Tested on log returns (first differences of log prices). 2 tests are run: about 0.1 rejection(s) are expected by chance at 5 %."},{"id":"irf","title":"Orthogonalized impulse responses","columns":[{"key":"shock","label":"Shock in","align":"left"},{"key":"response","label":"Response of","align":"left"},{"key":"step","label":"Days after","decimals":0},{"key":"value","label":"Response","decimals":5},{"key":"lower","label":"Lower","decimals":5},{"key":"upper","label":"Upper","decimals":5}],"rows":[{"shock":"SPY","response":"SPY","step":0,"value":0.01096382545944807,"lower":0.010535590280407766,"upper":0.011392060638488374},{"shock":"SPY","response":"SPY","step":1,"value":-0.00026314704917541497,"lower":-0.0008722291504852384,"upper":0.00034593505213440846},{"shock":"SPY","response":"SPY","step":2,"value":-1.6115951352075318e-05,"lower":-6.521976280424926e-05,"upper":3.298786010009862e-05},{"shock":"SPY","response":"SPY","step":5,"value":4.280140677915656e-10,"lower":-2.2239549048108855e-08,"upper":2.3095577183691983e-08},{"shock":"SPY","response":"SPY","step":10,"value":-3.6080429104464965e-15,"lower":-3.183560725503478e-14,"upper":2.4619521434141787e-14},{"shock":"SPY","response":"TLT","step":0,"value":0.000831736539170047,"lower":0.0002905998978901239,"upper":0.00137287318044997},{"shock":"SPY","response":"TLT","step":1,"value":0.0004759725880782545,"lower":-6.977083371409275e-05,"upper":0.0010217160098706017},{"shock":"SPY","response":"TLT","step":2,"value":-3.731740333563621e-05,"lower":-9.317609351649429e-05,"upper":1.8541286845221882e-05},{"shock":"SPY","response":"TLT","step":5,"value":-6.2717559838535575e-09,"lower":-3.0346472623606875e-08,"upper":1.780296065589976e-08},{"shock":"SPY","response":"TLT","step":10,"value":-2.751630575113503e-15,"lower":-3.054477812946206e-14,"upper":2.5041516979235052e-14},{"shock":"TLT","response":"SPY","step":0,"value":0,"lower":0,"upper":0},{"shock":"TLT","response":"SPY","step":1,"value":-0.00044231082819692197,"lower":-0.0010477464856924116,"upper":0.0001631248292985676},{"shock":"TLT","response":"SPY","step":2,"value":3.219195005480071e-05,"lower":-2.3742331611117164e-05,"upper":8.812623172071858e-05},{"shock":"TLT","response":"SPY","step":5,"value":5.6225614844610666e-09,"lower":-1.7417917824435462e-08,"upper":2.8663040793357594e-08},{"shock":"TLT","response":"SPY","step":10,"value":2.209984901140763e-15,"lower":-2.2023022517433367e-14,"upper":2.6442992319714893e-14},{"shock":"TLT","response":"TLT","step":0,"value":0.009778847633390436,"lower":0.009396896408192473,"upper":0.010160798858588399},{"shock":"TLT","response":"TLT","step":1,"value":-0.0005105656896654293,"lower":-0.0010526614262872016,"upper":3.1530046956342885e-05},{"shock":"TLT","response":"TLT","step":2,"value":5.703299022193177e-06,"lower":-5.769791095104516e-05,"upper":6.910450899543152e-05},{"shock":"TLT","response":"TLT","step":5,"value":3.888424742406575e-09,"lower":-1.7891248724235716e-08,"upper":2.5668098209048866e-08},{"shock":"TLT","response":"TLT","step":10,"value":-1.8397630662034164e-15,"lower":-2.962529842572135e-14,"upper":2.5945772293314517e-14}],"note":"Response to a one-standard-deviation orthogonalized innovation, in the units of the modelled series."},{"id":"fevd","title":"Forecast-error variance decomposition","columns":[{"key":"variable","label":"Variable","align":"left"},{"key":"step","label":"Horizon (days)","decimals":0},{"key":"s0","label":"Shock SPY","unit":"percent","decimals":1},{"key":"s1","label":"Shock TLT","unit":"percent","decimals":1}],"rows":[{"variable":"SPY","step":1,"s0":0.9999999999999999,"s1":0},{"variable":"SPY","step":2,"s0":0.9983760413883065,"s1":0.0016239586116933522},{"variable":"SPY","step":5,"s0":0.9983674496831485,"s1":0.0016325503168513257},{"variable":"SPY","step":10,"s0":0.9983674496828859,"s1":0.0016325503171140102},{"variable":"SPY","step":11,"s0":0.9983674496828859,"s1":0.0016325503171140102},{"variable":"TLT","step":1,"s0":0.007182335680296236,"s1":0.9928176643197038},{"variable":"TLT","step":2,"s0":0.0094864601115255,"s1":0.9905135398884745},{"variable":"TLT","step":5,"s0":0.009500719996350071,"s1":0.99049928000365},{"variable":"TLT","step":10,"s0":0.00950071999675229,"s1":0.9904992800032478},{"variable":"TLT","step":11,"s0":0.00950071999675229,"s1":0.9904992800032478}],"note":"Share of the forecast-error variance of each variable attributed to each orthogonalized shock (same Cholesky ordering). Rows sum to 100 %."},{"id":"engle_granger","title":"Engle-Granger cointegration tests (pairs, log prices)","columns":[{"key":"dependent","label":"Dependent","align":"left"},{"key":"regressor","label":"Regressor","align":"left"},{"key":"beta","label":"Hedge ratio β","decimals":4},{"key":"stat","label":"ADF statistic","decimals":3},{"key":"crit5","label":"5 % critical","decimals":3},{"key":"p","label":"p-value","decimals":4},{"key":"half_life","label":"Half-life of the spread (days)","decimals":1},{"key":"cointegrated","label":"Cointegrated at 5 %","align":"left"}],"rows":[{"dependent":"SPY","regressor":"TLT","beta":-0.9965618895606223,"stat":-1.1678935051066217,"crit5":-3.3409835833963215,"p":0.8661086967789133,"half_life":298.69697673140297,"cointegrated":"no"},{"dependent":"TLT","regressor":"SPY","beta":-0.19343303244319104,"stat":-3.1360071398425644,"crit5":-3.3409835833963215,"p":0.08129725825164086,"half_life":70.01908244965333,"cointegrated":"no"}],"note":"Two-step test on levels: OLS of the dependent log price on the regressor, then an ADF test on the residual with MacKinnon critical values. H0: no cointegration. The test is not symmetric, so both directions are shown."},{"id":"johansen","title":"Johansen cointegration test (log prices)","columns":[{"key":"h0","label":"H0","align":"left"},{"key":"eigenvalue","label":"Eigenvalue","decimals":4},{"key":"trace","label":"Trace","decimals":2},{"key":"trace_90","label":"90 %","decimals":2},{"key":"trace_95","label":"95 %","decimals":2},{"key":"trace_99","label":"99 %","decimals":2},{"key":"trace_reject","label":"Trace rejects (5 %)","align":"left"},{"key":"maxeig","label":"Max-eigenvalue","decimals":2},{"key":"maxeig_90","label":"90 %","decimals":2},{"key":"maxeig_95","label":"95 %","decimals":2},{"key":"maxeig_99","label":"99 %","decimals":2},{"key":"maxeig_reject","label":"Max-eig. rejects (5 %)","align":"left"}],"rows":[{"h0":"r = 0","eigenvalue":0.008639272041196903,"trace":11.579460874080294,"trace_90":13.4294,"trace_95":15.4943,"trace_99":19.9349,"trace_reject":"no","maxeig":10.924099875485586,"maxeig_90":12.2971,"maxeig_95":14.2639,"maxeig_99":18.52,"maxeig_reject":"no"},{"h0":"r ≤ 1","eigenvalue":0.0005204054464525709,"trace":0.6553609985947075,"trace_90":2.7055,"trace_95":3.8415,"trace_99":6.6349,"trace_reject":"no","maxeig":0.6553609985947075,"maxeig_90":2.7055,"maxeig_95":3.8415,"maxeig_99":6.6349,"maxeig_reject":"no"}],"note":"On levels, 1 lagged difference(s), deterministic terms: constant. The rank is the first H0 that is not rejected, reading from the top. Trace selects r = 0, maximum eigenvalue r = 0."}],"charts":[{"id":"granger_matrix","title":"Granger causality p-values (row causes column)","type":"heatmap","x":{"label":"Effect","type":"category"},"y":{"label":"Cause"},"series":[],"matrix":{"x":["SPY","TLT"],"y":["SPY","TLT"],"z":[[null,0.06279986842920827],[0.15213471017726626,null]]},"note":"Small p-value = the row series helps predict the column series. The diagonal is empty."},{"id":"irf_1","title":"Responses to a one-standard-deviation shock in SPY","type":"line","x":{"label":"Days after the shock","type":"number"},"y":{"label":"Response (log return)","unit":"percent"},"series":[{"name":"Response of SPY","kind":"calculated","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0.01096382545944807,-0.00026314704917541497,-1.6115951352075318e-05,2.0194238078801534e-06,-9.513490986561088e-08,4.280140677915656e-10,2.7487594203560127e-10,-2.1382647888459242e-11,6.720432181887208e-13,1.9870943879073393e-14,-3.6080429104464965e-15],"lower":[0.010535590280407766,-0.0008722291504852384,-6.521976280424926e-05,-2.2308713287645487e-06,-4.3029244547661263e-07,-2.2239549048108855e-08,-1.299724898156205e-09,-1.2868438644111247e-10,-6.073896637721343e-12,-4.123647513253196e-13,-3.183560725503478e-14],"upper":[0.011392060638488374,0.00034593505213440846,3.298786010009862e-05,6.269718944524855e-06,2.400226257453909e-07,2.3095577183691983e-08,1.8494767822274074e-09,8.591909066419397e-11,7.417983074098785e-12,4.5210663908346634e-13,2.4619521434141787e-14]},{"name":"Response of TLT","kind":"calculated","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0.000831736539170047,0.0004759725880782545,-3.731740333563621e-05,1.1849130342779364e-06,3.38021021349113e-08,-6.2717559838535575e-09,3.4773278383170096e-10,-5.133626778821376e-12,-7.449452840807474e-13,7.073178347738177e-14,-2.751630575113503e-15],"lower":[0.0002905998978901239,-6.977083371409275e-05,-9.317609351649429e-05,-3.380060099296542e-06,-3.0956233285814614e-07,-3.0346472623606875e-08,-1.2651360193248437e-09,-1.1409256362457611e-10,-7.978746080387717e-12,-3.792443290408615e-13,-3.054477812946206e-14],"upper":[0.00137287318044997,0.0010217160098706017,1.8541286845221882e-05,5.749886167852415e-06,3.771665371279687e-07,1.780296065589976e-08,1.9606015869882456e-09,1.0382531006693337e-10,6.488855512226222e-12,5.20707895995625e-13,2.5041516979235052e-14]}],"note":"Orthogonalized (Cholesky) responses; 95% asymptotic bands. Ordering: SPY → TLT."},{"id":"irf_2","title":"Responses to a one-standard-deviation shock in TLT","type":"line","x":{"label":"Days after the shock","type":"number"},"y":{"label":"Response (log return)","unit":"percent"},"series":[{"name":"Response of SPY","kind":"calculated","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0,-0.00044231082819692197,3.219195005480071e-05,-9.201581840655413e-07,-3.658388328698345e-08,5.6225614844610666e-09,-2.915352175988241e-10,3.131806713729683e-12,7.098655371063647e-13,-6.173923484409689e-14,2.209984901140763e-15],"lower":[0,-0.0010477464856924116,-2.3742331611117164e-05,-4.844879763672775e-06,-3.500921711296672e-07,-1.7417917824435462e-08,-1.7356068148594727e-09,-9.168914808756838e-11,-5.888756237539558e-12,-4.714212286137104e-13,-2.2023022517433367e-14],"upper":[0,0.0001631248292985676,8.812623172071858e-05,3.004563395541692e-06,2.7692440455570026e-07,2.8663040793357594e-08,1.1525363796618244e-09,9.795276151502774e-11,7.308487311752287e-12,3.479427589255166e-13,2.6442992319714893e-14]},{"name":"Response of TLT","kind":"calculated","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0.009778847633390436,-0.0005105656896654293,5.703299022193177e-06,1.2272802094184734e-06,-1.0766924468624317e-07,3.888424742406575e-09,6.334291228868384e-11,-1.711835601676053e-11,1.0421361987617802e-12,-2.078215503037231e-14,-1.8397630662034164e-15],"lower":[0.009396896408192473,-0.0010526614262872016,-5.769791095104516e-05,-3.550463447496527e-06,-4.083962554544583e-07,-1.7891248724235716e-08,-1.5809250801317722e-09,-1.217424730662983e-10,-5.100995199600075e-12,-4.3316697860920503e-13,-2.962529842572135e-14],"upper":[0.010160798858588399,3.1530046956342885e-05,6.910450899543152e-05,6.005023866333474e-06,1.9305776608197202e-07,2.5668098209048866e-08,1.70761090470914e-09,8.750576103277726e-11,7.185267597123635e-12,3.9160266854846045e-13,2.5945772293314517e-14]}],"note":"Orthogonalized (Cholesky) responses; 95% asymptotic bands. Ordering: SPY → TLT."},{"id":"fevd","title":"Variance decomposition at 11 days","type":"bar","x":{"label":"Variable","type":"category"},"y":{"label":"Share of forecast-error variance","unit":"percent"},"series":[{"name":"Shock SPY","kind":"calculated","x":["SPY","TLT"],"y":[0.9983674496828859,0.00950071999675229],"style":"bar"},{"name":"Shock TLT","kind":"calculated","x":["SPY","TLT"],"y":[0.0016325503171140102,0.9904992800032478],"style":"bar"}]}],"diagnostics":[{"name":"VAR stability (largest eigenvalue modulus of the companion matrix)","statistic":0.056716597512517314,"pvalue":null,"conclusion":"All eigenvalues are inside the unit circle: the VAR is stable and impulse responses die out.","passed":true},{"name":"Portmanteau test of residual autocorrelation (10 lags)","statistic":38.42001065159008,"pvalue":0.3604370053274638,"conclusion":"No residual autocorrelation detected.","passed":true,"df":36},{"name":"Multivariate Jarque-Bera normality of residuals","statistic":2875.0382481584165,"pvalue":0,"conclusion":"Residuals are not Gaussian (usual for daily returns): asymptotic bands remain valid, small-sample ones are approximate.","passed":false,"df":4},{"name":"Johansen trace test, H0: no cointegration","statistic":11.579460874080294,"pvalue":null,"conclusion":"Not rejected at 5 % (critical value 15.49): no evidence of cointegration.","passed":null}],"assumptions":["VAR, Granger causality, impulse responses and variance decomposition are computed on log returns (first differences of log prices). Engle-Granger, Johansen and the VECM are computed on log price levels.","Impulse responses are identified by a Cholesky decomposition of the residual covariance with the ordering SPY → TLT (the order of the symbols): a series reacts within the day to shocks of the series listed before it, not after it."],"warnings":["The log price of TLT looks stationary (ADF rejects the unit root): cointegration tests presuppose I(1) series, and a stationary series counts as a trivial cointegrating relation in the Johansen rank.","BIC selects 0 lags: the series show no linear dynamics at this horizon. One lag is used so that causality and impulse responses are defined; expect insignificant results."],"methodology":"**VAR(p).** $y_t = c + A_1y_{t-1}+\\dots+A_py_{t-p}+u_t$, $u_t\\sim(0,\\Sigma_u)$, estimated by OLS equation by equation. The lag length minimises $\\text{AIC}=\\ln|\\hat\\Sigma_u|+\\frac{2pk^2}{T}$, $\\text{BIC}=\\ln|\\hat\\Sigma_u|+\\frac{\\ln T}{T}pk^2$ or $\\text{HQ}=\\ln|\\hat\\Sigma_u|+\\frac{2\\ln\\ln T}{T}pk^2$.\n\n**Stability.** The VAR is stable when all eigenvalues of the companion matrix are inside the unit circle.\n\n**Granger causality.** $x$ does not Granger-cause $y$ if all coefficients of the lags of $x$ in the equation of $y$ are zero; tested with a Wald statistic in its $F$ form.\n\n**Impulse responses.** With the moving-average form $y_t=\\mu+\\sum_i\\Phi_iu_{t-i}$ and $\\Sigma_u=PP'$ ($P$ lower triangular, Cholesky), orthogonalized responses are $\\Theta_i=\\Phi_iP$: the response after $i$ days to a one-standard-deviation shock. The ordering of the variables is the order of the symbols. Bands are $\\hat\\Theta_i\\pm z\\,\\widehat{se}$ from the asymptotic distribution.\n\n**Variance decomposition.** Share of the $h$-step forecast-error variance of variable $i$ due to shock $j$: $\\omega_{ij,h}=\\sum_{s<h}\\theta_{ij,s}^2\\big/\\sum_{s<h}\\sum_m\\theta_{im,s}^2$.\n\n**Cointegration (levels).** Engle-Granger: OLS $y_{1t}=a+\\beta y_{2t}+e_t$, then an ADF test on $\\hat e_t$ with MacKinnon critical values. Johansen: in $\\Delta y_t=\\Pi y_{t-1}+\\sum_{i}\\Gamma_i\\Delta y_{t-i}+u_t$ the rank $r$ of $\\Pi=\\alpha\\beta'$ is tested with $\\lambda_{trace}(r)=-T\\sum_{i>r}\\ln(1-\\hat\\lambda_i)$ and $\\lambda_{max}(r)=-T\\ln(1-\\hat\\lambda_{r+1})$ against Osterwald-Lenum critical values.\n\n**VECM.** When $0<r<k$: $\\Delta y_t=\\alpha\\beta'y_{t-1}+\\sum_i\\Gamma_i\\Delta y_{t-i}+u_t$; $\\beta$ holds the long-run relations (normalized with an identity block), $\\alpha$ the speeds of adjustment.","provenance":{"data":[{"symbol":"SPY","provider":"FMP","retrievedAt":"2026-11-20T21:49:32+00:00","start":"2021-11-10","end":"2026-11-20","observations":1263,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"TLT","provider":"FMP","retrievedAt":"2026-11-20T21:49:33+00:00","start":"2021-11-10","end":"2026-11-20","observations":1263,"frequency":"1d","adjusted":"split_div","currency":null}],"spec":{"symbols":["SPY","TLT"],"period_days":1260,"start":null,"end":null,"var_on":"returns","lags":0,"max_lags":10,"criterion":"bic","irf_horizon":10,"cumulative":false,"band_level":0.95,"deterministic":"constant","coint_lags":-1,"rank_test":"trace","lags_used":1,"max_lags_used":10,"coint_lags_used":1,"cointegration_rank":0,"cholesky_order":["SPY","TLT"]},"seed":null,"software":{"python":"3.14.4","numpy":"2.4.6","pandas":"3.0.3","scipy":"1.17.1","statsmodels":"0.14.6","arch":"8.0.0","scikit-learn":"1.8.0"},"computedAt":"2026-11-20T21:49:33+00:00","durationMs":3716,"reproduce":"import numpy as np, pandas as pd\nfrom statsmodels.tsa.api import VAR\nfrom statsmodels.tsa.stattools import coint\nfrom statsmodels.tsa.vector_ar.vecm import coint_johansen, VECM\n# prices: DataFrame of adjusted daily closes, columns ['SPY', 'TLT'] in this order, 2021-11-12 → 2026-11-20\nlogp = np.log(prices)\ndata = logp.diff().dropna().reset_index(drop=True)\nres = VAR(data).fit(1, trend=\"c\")\nprint(res.summary()); print(\"stable:\", res.is_stable())\nprint(res.test_causality('TLT', ['SPY'], kind=\"f\").summary())\nirf = res.irf(10); print(irf.orth_irfs[:3]); print(res.fevd(11).decomp[:, -1, :])\nj = coint_johansen(logp.values, 0, 1); print(j.lr1, j.cvt, j.lr2, j.cvm)\nprint(coint(logp['SPY'], logp['TLT'], trend=\"c\", autolag=\"aic\"))\n# if rank > 0: VECM(logp.values, k_ar_diff=1, coint_rank=rank, deterministic='co').fit()"}}}}2
Files main
Menu

Theme