SPB Git

Repository Public

job_panel.json 15.3 KB 2 lines json

1{"job":{"id":"3a9f5cb9-a613-4931-b7fe-a2ac658fee99","tool":"panel","params":{"symbols":["AAPL","MSFT","NVDA","GOOGL","AMZN","JPM"],"frequency":"weekly","data_period":1260,"return_type":"log","dependent":"return","x_lagged_return":true,"x_momentum":true,"momentum_window":12,"x_volatility":true,"vol_window":12,"x_volume_change":false,"x_illiquidity":false,"x_market_return":false,"market":"SPY","estimator":"fe_entity","covariance":"cluster_time","confidence":0.95},"status":"done","startedAt":1795211381088,"finishedAt":1795211394536,"error":null,"progress":1,"engineVersion":"1.0.0","durationMs":13448,"projectId":null,"sessionId":null,"cancellable":false,"code":"import numpy as np, pandas as pd\nfrom linearmodels.panel import PanelOLS, PooledOLS, RandomEffects, FamaMacBeth\n# bars: long table of weekly adjusted bars with columns symbol, date, close, volume (date = last session of the period)\nbars = pd.read_csv(\"bars.csv\", parse_dates=[\"date\"])\ndef features(g):\n    g = g.set_index(\"date\").sort_index(); r = np.log(g.close / g.close.shift(1))\n    f = pd.DataFrame({\"y\": r})\n    f[\"ret[t-1]\"] = r.shift(1)\n    f[\"mom12[t-2]\"] = np.log(g.close.shift(2) / g.close.shift(14))\n    f[\"vol12[t-1]\"] = r.rolling(12).std().shift(1)\n    return f\nd = bars.groupby(\"symbol\").apply(features).replace([np.inf, -np.inf], np.nan).dropna()   # index: (symbol, date)\nd = d[d.index.get_level_values(\"date\") >= \"2021-11-10\"]\nX = d[['ret[t-1]', 'mom12[t-2]', 'vol12[t-1]']]\nres = PanelOLS(d.y, X, entity_effects=True).fit(cov_type=\"clustered\", cluster_time=True)\nprint(res)","result":{"success":true,"schema":"lab/1","engine":"panel","engineVersion":"1.0.0","title":"Panel of 6 symbols — entity fixed effects","headline":"Weekly log return of 6 symbols over 263 periods (2021-11-12 → 2026-11-20, 1578 observations), entity fixed effects: ret[t-1] -0.0274 (t = -0.58); mom12[t-2] 0.0019 (t = 0.13); vol12[t-1] 0.0936 (t = 0.75).","summary":[{"label":"Observations","value":1578,"unit":"count","kind":"observed"},{"label":"Entities","value":6,"unit":"count","kind":"observed"},{"label":"Periods","value":263,"unit":"count","kind":"observed"},{"label":"β ret[t-1]","value":-0.027444695219840453,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.0473, p = 0.562"},{"label":"β mom12[t-2]","value":0.0019089168239280162,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.0151, p = 0.900"},{"label":"β vol12[t-1]","value":0.09360652074584255,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.1247, p = 0.453"},{"label":"R² within","value":0.001334711234759478,"unit":"ratio","kind":"calculated","decimals":4},{"label":"R² overall","value":0.004535367222930242,"unit":"ratio","kind":"calculated","decimals":4},{"label":"Hausman p-value","value":0.8621380830804675,"unit":"ratio","kind":"calculated","decimals":4}],"tables":[{"id":"coefficients","title":"Coefficients (entity fixed effects)","columns":[{"key":"term","label":"Term"},{"key":"estimate","label":"Estimate","decimals":6},{"key":"std_error","label":"Std. error","decimals":6},{"key":"t","label":"t","decimals":3},{"key":"p_value","label":"p-value","decimals":4},{"key":"ci_low","label":"95% CI low","decimals":6},{"key":"ci_high","label":"95% CI high","decimals":6}],"rows":[{"term":"ret[t-1]","estimate":-0.027444695219840453,"std_error":0.04731454785262584,"t":-0.5800477118649532,"p_value":0.5619657286340558,"ci_low":-0.12025109711937054,"ci_high":0.06536170667968963},{"term":"mom12[t-2]","estimate":0.0019089168239280162,"std_error":0.015133160676898846,"t":0.12614131738137335,"p_value":0.8996362235678736,"ci_low":-0.027774431227182973,"ci_high":0.03159226487503901},{"term":"vol12[t-1]","estimate":0.09360652074584255,"std_error":0.1247369332921866,"t":0.7504314742657375,"p_value":0.4531073999525844,"ci_low":-0.15106211687672075,"ci_high":0.3382751583684058}],"note":"Standard errors: clustered by time (arbitrary correlation across symbols on the same date)."},{"id":"fit","title":"Fit statistics","columns":[{"key":"statistic","label":"Statistic"},{"key":"value","label":"Value","decimals":5}],"rows":[{"statistic":"Observations","value":1578},{"statistic":"Entities","value":6},{"statistic":"Periods","value":263},{"statistic":"Observations per entity, minimum","value":263},{"statistic":"Observations per entity, maximum","value":263},{"statistic":"R² of the estimated model","value":0.001334711234759478},{"statistic":"R² within","value":0.001334711234759478},{"statistic":"R² between","value":0.7294261776356346},{"statistic":"R² overall","value":0.004535367222930242},{"statistic":"F / Wald statistic (all slopes = 0)","value":0.2615699775556156},{"statistic":"p-value","value":0.8531077775191703}],"note":"Within: variation around each entity's mean; between: across entity means; overall: pooled. For returns, within ≈ overall because entity means are tiny relative to period-to-period variation."},{"id":"comparison","title":"Slope estimates across estimators","columns":[{"key":"term","label":"Term"},{"key":"pooled","label":"Pooled ols","decimals":6},{"key":"fe_entity","label":"Entity fixed effects","decimals":6},{"key":"random_effects","label":"Random effects (gls)","decimals":6},{"key":"fe_twoway","label":"Two-way fixed effects","decimals":6}],"rows":[{"term":"ret[t-1]","pooled":-0.026895487668068457,"fe_entity":-0.027444695219840453,"random_effects":-0.026895487668068457,"fe_twoway":-0.0008027212146423488},{"term":"mom12[t-2]","pooled":0.002629030760421831,"fe_entity":0.0019089168239280162,"random_effects":0.002629030760421831,"fe_twoway":0.0007277923189666973},{"term":"vol12[t-1]","pooled":0.09527193948187768,"fe_entity":0.09360652074584255,"random_effects":0.09527193948187768,"fe_twoway":0.06992776700959091}],"note":"Large differences between pooled / random effects and fixed effects point to entity effects correlated with the regressors."}],"charts":[{"id":"coefficients","title":"Slopes with 95% confidence intervals","type":"bar","x":{"label":"Term","type":"category"},"y":{"label":"Coefficient"},"series":[{"name":"Entity fixed effects","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.027444695219840453,0.0019089168239280162,0.09360652074584255],"lower":[-0.12025109711937054,-0.027774431227182973,-0.15106211687672075],"upper":[0.06536170667968963,0.03159226487503901,0.3382751583684058],"style":"bar"}],"note":"Coefficients are on the scales of their regressors and are not directly comparable with each other."},{"id":"comparison","title":"Slopes across estimators","type":"bar","x":{"label":"Term","type":"category"},"y":{"label":"Coefficient"},"series":[{"name":"Pooled ols","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.026895487668068457,0.002629030760421831,0.09527193948187768],"style":"bar"},{"name":"Entity fixed effects","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.027444695219840453,0.0019089168239280162,0.09360652074584255],"style":"bar"},{"name":"Random effects (gls)","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.026895487668068457,0.002629030760421831,0.09527193948187768],"style":"bar"},{"name":"Two-way fixed effects","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.0008027212146423488,0.0007277923189666973,0.06992776700959091],"style":"bar"}]},{"id":"entity_effects","title":"Estimated entity effects","type":"bar","x":{"label":"Symbol","type":"category"},"y":{"label":"Mean of y − x'b"},"series":[{"name":"Entity mean of y − x'b","kind":"calculated","x":["AMZN","GOOGL","MSFT","NVDA","JPM","AAPL"],"y":[-0.0029117826866612035,-0.0018861439681759047,-0.0018000836547952853,-0.00036148001779368044,-0.00025962705520202694,-0.00021603386538297196],"style":"bar"}],"note":"Each entity's average of the dependent variable net of the slopes. With fixed effects these are the estimated entity intercepts."}],"diagnostics":[{"name":"F-test for poolability (entity effects jointly zero)","statistic":0.15070667564268989,"pvalue":0.979869801475164,"conclusion":"Fails to reject equal intercepts across entities at the 5% level: no evidence that entity effects are needed (pooled OLS is not contradicted).","passed":true,"df":"5, 1569"},{"name":"F-test for poolability (entity and time effects jointly zero)","statistic":5.507753394662521,"pvalue":9.29670480310104e-98,"conclusion":"Rejects the absence of entity and time effects at the 5% level: common date shocks matter (expected for asset returns).","passed":false,"df":"267, 1307"},{"name":"Hausman test (fixed vs random effects)","statistic":0.7468280108403011,"pvalue":0.8621380830804675,"conclusion":"Fails to reject at the 5% level that the entity effects are uncorrelated with the regressors: random effects are not contradicted and are more efficient; fixed effects remain consistent.","passed":true,"df":3}],"assumptions":["Panel of 6 symbols × 263 weekly periods (balanced), built from adjusted closes and volumes.","Alignment: every regressor except `mkt` is known at the end of period t-1 (lagged return, momentum ending at t-2, volatility, volume change and illiquidity up to t-1). The regression is predictive in that sense.","What a panel of returns can identify: whether a characteristic observable in advance is associated with later returns across assets and time, on average, in this sample of symbols.","What it cannot identify: a causal effect (the regressors are not randomly assigned), nor a relation valid outside the chosen symbols — a hand-picked list of surviving, liquid names carries selection and survivorship bias.","Entity fixed effects remove each symbol's average level: slopes are identified from variation over time within a symbol. Unconditional differences in mean returns across symbols are absorbed, not explained.","Standard errors: clustered by time (arbitrary correlation across symbols on the same date). p-values use the normal approximation.","Fixed effects with a lagged dependent variable are biased of order 1/T (Nickell): negligible here with T = 263."],"warnings":["A cross-section of 6 symbols is small: between-entity comparisons (random effects, Hausman, between R²) rest on very few entity means."],"methodology":"**Model.** $y_{it} = \\alpha_i + \\gamma_t + x_{it}'\\beta + \\varepsilon_{it}$ for symbol $i$ and period $t$; pooled OLS sets $\\alpha_i=\\alpha$, $\\gamma_t=0$.\n\n**Fixed effects.** Entity effects: OLS on $\\ddot y_{it} = y_{it}-\\bar y_i$, $\\ddot x_{it} = x_{it}-\\bar x_i$ (within transformation), $\\hat\\beta_{FE} = (\\ddot X'\\ddot X)^{-1}\\ddot X'\\ddot y$, $\\hat\\sigma^2 = \\mathrm{RSS}/(n-N-k)$. Time effects demean by date; two-way effects remove both.\n\n**Random effects.** $\\alpha_i \\sim (0,\\sigma_\\alpha^2)$ uncorrelated with $x$; GLS by quasi-demeaning $y_{it}-\\theta_i\\bar y_i$ with $\\theta_i = 1-\\sqrt{\\sigma_\\varepsilon^2/(\\sigma_\\varepsilon^2+T_i\\sigma_\\alpha^2)}$.\n\n**Fama-MacBeth.** For each $t$: $y_{it} = \\lambda_{0t} + x_{it}'\\lambda_t + u_{it}$ across $i$; $\\hat\\lambda = \\frac1T\\sum_t\\hat\\lambda_t$, $\\widehat{\\mathrm{se}}(\\hat\\lambda) = \\mathrm{sd}(\\hat\\lambda_t)/\\sqrt T$.\n\n**Covariance.** Clustered: $\\frac{n}{n-k}(X'X)^{-1}\\big(\\sum_g X_g'\\hat u_g\\hat u_g'X_g\\big)(X'X)^{-1}$ with groups = symbols or dates (no $G/(G-1)$ factor; linearmodels defaults); two-way = entity + time − intersection. Driscoll-Kraay: Newey-West applied to the cross-sectional sums of scores $h_t=\\sum_i x_{it}\\hat u_{it}$, Bartlett bandwidth $\\lfloor 4(T/100)^{2/9}\\rfloor = 4$.\n\n**Poolability.** F-test of $\\alpha_1=\\dots=\\alpha_N$ (and $\\gamma_t$ equal when time effects are included) comparing the restricted pooled model with the fixed-effects model, classical errors.\n\n**Hausman.** $H = (\\hat\\beta_{FE}-\\hat\\beta_{RE})'[\\hat V_{FE}-\\hat V_{RE}]^{-1}(\\hat\\beta_{FE}-\\hat\\beta_{RE}) \\sim \\chi^2_k$ under $H_0$: $E[\\alpha_i\\mid x]=0$, with classical covariances built on the same error variance, the within estimate $\\hat\\sigma^2_\\varepsilon = \\mathrm{RSS}_{FE}/(n-N-k)$, for both estimators (this keeps $\\hat V_{FE}-\\hat V_{RE}$ positive semi-definite). The test assumes RE is efficient under $H_0$; it is not robust to heteroskedasticity or cross-sectional dependence.\n\n**R².** Within: fit of the demeaned model; between: fit of entity means; overall: fit of the pooled data, all evaluated at the reported slopes.\n\n**Variables.** Returns are log returns on adjusted closes. `ret[t-1]` $= r_{i,t-1}$; `mom k[t-2]` $=$ return from $t-k-2$ to $t-2$; `vol w[t-1]` $=$ standard deviation of $r_{i,t-w},\\dots,r_{i,t-1}$; `dlogvol[t-1]` $= \\ln(V_{i,t-1}/V_{i,t-2})$; `illiq w[t-1]` $= \\ln$ of the mean of $10^6|r|/(P\\cdot V)$ over $t-w,\\dots,t-1$ (Amihud); `mkt` $=$ market return in $t$.","provenance":{"data":[{"symbol":"AAPL","provider":"FMP","retrievedAt":"2026-11-20T21:49:45+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"MSFT","provider":"FMP","retrievedAt":"2026-11-20T21:49:46+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"NVDA","provider":"FMP","retrievedAt":"2026-11-20T21:49:47+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"GOOGL","provider":"FMP","retrievedAt":"2026-11-20T21:49:50+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"AMZN","provider":"FMP","retrievedAt":"2026-11-20T21:49:53+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null},{"symbol":"JPM","provider":"FMP","retrievedAt":"2026-11-20T21:49:54+00:00","start":"2021-07-08","end":"2026-11-20","observations":1351,"frequency":"1d","adjusted":"split_div","currency":null}],"spec":{"symbols":["AAPL","MSFT","NVDA","GOOGL","AMZN","JPM"],"frequency":"weekly","data_period":1260,"start":null,"end":null,"return_type":"log","dependent":"return","x_lagged_return":true,"x_momentum":true,"momentum_window":12,"x_volatility":true,"vol_window":12,"x_volume_change":false,"x_illiquidity":false,"x_market_return":false,"market":"SPY","estimator":"fe_entity","covariance":"cluster_time","confidence":0.95,"regressors_used":["ret[t-1]","mom12[t-2]","vol12[t-1]"]},"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","linearmodels":"7.1","scikit-learn":"1.8.0"},"computedAt":"2026-11-20T21:49:54+00:00","durationMs":12367,"reproduce":"import numpy as np, pandas as pd\nfrom linearmodels.panel import PanelOLS, PooledOLS, RandomEffects, FamaMacBeth\n# bars: long table of weekly adjusted bars with columns symbol, date, close, volume (date = last session of the period)\nbars = pd.read_csv(\"bars.csv\", parse_dates=[\"date\"])\ndef features(g):\n    g = g.set_index(\"date\").sort_index(); r = np.log(g.close / g.close.shift(1))\n    f = pd.DataFrame({\"y\": r})\n    f[\"ret[t-1]\"] = r.shift(1)\n    f[\"mom12[t-2]\"] = np.log(g.close.shift(2) / g.close.shift(14))\n    f[\"vol12[t-1]\"] = r.rolling(12).std().shift(1)\n    return f\nd = bars.groupby(\"symbol\").apply(features).replace([np.inf, -np.inf], np.nan).dropna()   # index: (symbol, date)\nd = d[d.index.get_level_values(\"date\") >= \"2021-11-10\"]\nX = d[['ret[t-1]', 'mom12[t-2]', 'vol12[t-1]']]\nres = PanelOLS(d.y, X, entity_effects=True).fit(cov_type=\"clustered\", cluster_time=True)\nprint(res)"}}}}2
Files main
Menu

Theme