Works with the AI Agents you already use
Factor Exposure Attribution
by BanditXBT
Decompose returns into factor exposures and alpha; detect hidden beta, short-vol and liquidity risk.
$29
About this skill
Alpha is the intercept left after charging the strategy for every systematic risk it carries. Educational analysis, not investment advice; state assumptions and data sources.
- Align data. Net strategy returns (excess of risk-free if factors are excess) on the same frequency and timestamps as the factors. Daily factors beat monthly for power. For 24/7 crypto, use one UTC cut-off for strategy and factors.
- Choose the model.
- Equities: CAPM; Fama-French 3 (1993: Mkt-RF, SMB, HML); Carhart 4 (1997: adds UMD); Fama-French 5 (2015: adds RMW, CMA), optionally plus momentum; Hou-Xue-Zhang q-factor (2015, RFS: MKT, ME, I/A, ROE) and the q5 model (Hou, Mo, Xue, Zhang 2021, Review of Finance: adds expected growth). Kenneth French's Data Library has FF factors (incl. daily) and momentum; q-factors are at global-q.org.
- Crypto: Liu, Tsyvinski, Wu (J. Finance 2022, "Common Risk Factors in Cryptocurrency") find a three-factor model (crypto market, size, momentum) accounts for the long-short strategy returns they study. Beyond that, add BTC and ETH returns separately, a liquidity/volume factor, perp funding or basis, and sector (L1, DeFi, memecoin) factors. There is no standard library like French's: state your factor construction.
- Multi-asset/trend: equity beta, rates duration, credit spread, USD, commodities, short-vol proxy; for hedge-fund-style returns consider trend-following lookback factors (Fung and Hsieh).
- Regression.
r_t - rf_t = alpha + sum_k b_k f_{k,t} + e_t. OLS with Newey-West (HAC) errors (Hansen-Hodrick for overlapping returns); a common automatic lag isfloor(4*(T/100)^(2/9)), longer for illiquid assets. Report adjusted R2, annualized alpha with t-stat, betas with t-stats. For several portfolios, a GRS test checks whether all alphas are jointly zero. - Attribution. Contribution_k = b_k * mean(f_k); alpha contribution = a; the sum equals mean excess return. Risk attribution: factor variance share
b'Sigma_f b / Var(r). - Rolling and regime betas.
statsmodels.regression.rolling.RollingOLSwith a 60-120 day (or 24-36 month) window andbsebands;RecursiveLSfor expanding estimates; stability tests viastatsmodels.stats.diagnostic(breaks_cusumolsresid,recursive_olsresiduals; verify names for your version) or a manual Chow test at a chosen date. Upside/downside beta via ar_mkt*1[r_mkt<0]term; timing via Henriksson-Merton or Treynor-Mazuy. - Hidden-beta detection, in order.
- Add the obvious: market, momentum, size, low-vol/BAB; re-check alpha.
- Nonlinear: add squared market and a put-payoff proxy; negative convexity with positive alpha signals short-vol or sold insurance (alpha vanishes in drawdowns).
- Dimson betas: contemporaneous plus a few market lags, to catch stale prices in illiquid assets (understated beta).
- Residual correlation with excluded factors and funding/liquidity proxies (crypto: BTC dominance changes, stablecoin supply, funding rates).
- Compare alpha under sparse vs rich factor sets; unstable alpha means model dependence.
- Tail check: regress on worst-5% market days only (few observations; read cautiously).
def attribute(r_excess, F, lags=None): X = sm.add_constant(F) m = sm.OLS(r_excess, X, missing="drop").fit(cov_type="HAC", cov_kwds={"maxlags": lags or int(4*(len(r_excess)/100)**(2/9))}) contrib = m.params.drop("const") * F.mean() return m, contrib
roll = RollingOLS(r_excess, sm.add_constant(F), window=90).fit() betas = roll.params # inspect drift; roll.bse gives bands
Educational analysis, not investment advice. Verify statsmodels function names against your installed version.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 13 days ago
- Software
Python 3statsmodelspandas
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse All Claude Skills.