SPB Git

Repository Public

job_panel.json 15.5 KB 2 lines json

1{"job":{"id":"c21aa2e8-2494-478b-8b9b-f5143f8b3525","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":1795217753649,"finishedAt":1795217761360,"error":null,"progress":1,"engineVersion":"1.0.0","durationMs":7711,"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.0274493903926275,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.0473, p = 0.562"},{"label":"β mom12[t-2]","value":0.00191138302614376,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.0151, p = 0.900"},{"label":"β vol12[t-1]","value":0.0936382544812017,"unit":"ratio","kind":"calculated","decimals":4,"note":"std. error 0.1247, p = 0.453"},{"label":"R² within","value":0.0013353042351094135,"unit":"ratio","kind":"calculated","decimals":4},{"label":"R² overall","value":0.004533375907687653,"unit":"ratio","kind":"calculated","decimals":4},{"label":"Hausman p-value","value":0.8622682400353308,"unit":"ratio","kind":"calculated","decimals":4}],"tables":[{"id":"coefficients","title":"Coefficients (entity fixed effects)","columns":[{"key":"term","label":"Term","type":"text"},{"key":"estimate","label":"Estimate","decimals":6,"type":"number"},{"key":"std_error","label":"Std. error","decimals":6,"type":"number"},{"key":"t","label":"t","decimals":3,"type":"number"},{"key":"p_value","label":"p-value","decimals":4,"type":"number"},{"key":"ci_low","label":"95% CI low","decimals":6,"type":"number"},{"key":"ci_high","label":"95% CI high","decimals":6,"type":"number"}],"rows":[{"term":"ret[t-1]","estimate":-0.0274493903926275,"std_error":0.04731369007698718,"t":-0.5801574628392504,"p_value":0.5618917397736819,"ci_low":-0.12025410978488922,"ci_high":0.06535532899963421},{"term":"mom12[t-2]","estimate":0.00191138302614376,"std_error":0.015133819963763605,"t":0.12629878184889026,"p_value":0.8995116024157731,"ci_low":-0.027773258201051854,"ci_high":0.03159602425333938},{"term":"vol12[t-1]","estimate":0.0936382544812017,"std_error":0.12474500782186643,"t":0.7506372889479905,"p_value":0.45298352834418704,"ci_low":-0.151046221146386,"ci_high":0.3383227301087894}],"note":"Standard errors: clustered by time (arbitrary correlation across symbols on the same date)."},{"id":"fit","title":"Fit statistics","columns":[{"key":"statistic","label":"Statistic","type":"text"},{"key":"value","label":"Value","decimals":5,"type":"number"}],"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.0013353042351094135},{"statistic":"R² within","value":0.0013353042351094135},{"statistic":"R² between","value":0.7289918754753768},{"statistic":"R² overall","value":0.004533375907687653},{"statistic":"F / Wald statistic (all slopes = 0)","value":0.2617094121109736},{"statistic":"p-value","value":0.8530079396092984}],"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","type":"text"},{"key":"pooled","label":"Pooled ols","decimals":6,"type":"number"},{"key":"fe_entity","label":"Entity fixed effects","decimals":6,"type":"number"},{"key":"random_effects","label":"Random effects (gls)","decimals":6,"type":"number"},{"key":"fe_twoway","label":"Two-way fixed effects","decimals":6,"type":"number"}],"rows":[{"term":"ret[t-1]","pooled":-0.02690038446639301,"fe_entity":-0.0274493903926275,"random_effects":-0.02690038446639301,"fe_twoway":-0.0008136720920507643},{"term":"mom12[t-2]","pooled":0.002631143230292324,"fe_entity":0.00191138302614376,"random_effects":0.002631143230292324,"fe_twoway":0.0007285118336223031},{"term":"vol12[t-1]","pooled":0.09530124629692938,"fe_entity":0.0936382544812017,"random_effects":0.09530124629692938,"fe_twoway":0.06994303807165007}],"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.0274493903926275,0.00191138302614376,0.0936382544812017],"lower":[-0.12025410978488922,-0.027773258201051854,-0.151046221146386],"upper":[0.06535532899963421,0.03159602425333938,0.3383227301087894],"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.02690038446639301,0.002631143230292324,0.09530124629692938],"style":"bar"},{"name":"Entity fixed effects","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.0274493903926275,0.00191138302614376,0.0936382544812017],"style":"bar"},{"name":"Random effects (gls)","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.02690038446639301,0.002631143230292324,0.09530124629692938],"style":"bar"},{"name":"Two-way fixed effects","kind":"calculated","x":["ret[t-1]","mom12[t-2]","vol12[t-1]"],"y":[-0.0008136720920507643,0.0007285118336223031,0.06994303807165007],"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.0029132485910969563,-0.0018876250816096095,-0.0018012782149309328,-0.0003636893141179956,-0.00026259068276101016,-0.00021727746896391668],"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.15060552517344902,"pvalue":0.9799000110242977,"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.508093118752311,"pvalue":9.135347904148025e-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.7462795585403149,"pvalue":0.8622682400353308,"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-20T23:35:56+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-20T23:35:57+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-20T23:35:58+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-20T23:35:59+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-20T23:36:00+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-20T23:36:00+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-20T23:36:01+00:00","durationMs":6633,"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