# factor-exposure-attribution

> Decompose returns into factor exposures and alpha; detect hidden beta, short-vol and liquidity risk.

factor-exposure-attribution is a paid AI agent skill on Agensi by BanditXBT. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $29 (one-time purchase)
- Creator: [BanditXBT](https://www.agensi.io/creators/banditxbt)
- Version: 1.0
- Last updated: 2026-11-21
- Security: scan passed (2026-11-21); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/factor-exposure-attribution
- Tags: trading-investing, research-analysis, web3-crypto

## 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.

1. **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.
2. **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).
3. **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 is `floor(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.
4. **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)`.
5. **Rolling and regime betas.** `statsmodels.regression.rolling.RollingOLS` with a 60-120 day (or 24-36 month) window and `bse` bands; `RecursiveLS` for expanding estimates; stability tests via `statsmodels.stats.diagnostic` (`breaks_cusumolsresid`, `recursive_olsresiduals`; verify names for your version) or a manual Chow test at a chosen date. Upside/downside beta via a `r_mkt*1[r_mkt<0]` term; timing via Henriksson-Merton or Treynor-Mazuy.
6. **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
```

## Requires

- Python 3
- statsmodels
- pandas

## Known limitations

Educational analysis, not investment advice. Verify statsmodels function names against your installed version.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the factor-exposure-attribution skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does factor-exposure-attribution do?

Decompose returns into factor exposures and alpha; detect hidden beta, short-vol and liquidity risk.

### Which AI agents support factor-exposure-attribution?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use factor-exposure-attribution?

Connect your AI agent to Agensi through MCP, then ask it to use factor-exposure-attribution on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
