# Benchmark Tracking

> A Claude skill from brainbytes-dev/everything-claude-trading.

- **Type:** Skill
- **Install:** `agentstack add skill-brainbytes-dev-everything-claude-trading-benchmark-tracking`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [brainbytes-dev](https://agentstack.voostack.com/s/brainbytes-dev)
- **Installs:** 0
- **Category:** [Finance & Payments](https://agentstack.voostack.com/c/finance-and-payments)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [brainbytes-dev](https://github.com/brainbytes-dev)
- **Source:** https://github.com/brainbytes-dev/everything-claude-trading/tree/main/skills/portfolio/benchmark-tracking

## Install

```sh
agentstack add skill-brainbytes-dev-everything-claude-trading-benchmark-tracking
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Benchmark Tracking

> Index tracking and replication strategies — full replication, sampling, and optimization.

## When to Activate

- User is building an index-tracking portfolio or ETF
- Minimizing tracking error against a benchmark with fewer securities
- Understanding ETF creation/redemption mechanics
- Handling index reconstitution and rebalancing events
- Evaluating tracking error sources and budgeting

## Core Concepts

### Replication Methods

| Method | Holdings | Tracking Error | Cost | When to Use |
|--------|----------|---------------|------|-------------|
| **Full Replication** | All index constituents | Lowest (~1-10 bps) | Highest trading cost | Liquid indices (S&P 500) |
| **Stratified Sampling** | Subset matching factor exposures | Low-moderate (5-30 bps) | Lower trading cost | Large/illiquid indices |
| **Optimization-Based** | Optimized subset | Lowest for given # holdings | Model risk | Broad indices (Russell 3000, MSCI ACWI) |
| **Synthetic (Swaps)** | Swap contract | Near zero (counterparty risk) | Swap fees | European ETFs, tax optimization |

### Tracking Error

The standard deviation of the difference between portfolio and benchmark returns:

```
TE = std(R_p - R_b) * sqrt(252)    (annualized, from daily returns)
```

Sources of tracking error:
- **Sampling error**: not holding all index constituents
- **Cash drag**: uninvested cash from dividends, inflows
- **Transaction costs**: rebalancing, reconstitution trading
- **Corporate actions**: dividends, splits, mergers handled differently
- **Fair value pricing**: NAV vs market price differences
- **Securities lending**: income offsets costs but introduces risk
- **Withholding taxes**: cross-border dividend taxation

### ETF Creation/Redemption

The authorized participant (AP) mechanism keeps ETF prices close to NAV:

**Creation**: AP delivers a basket of underlying securities to the ETF issuer, receives ETF shares in return. Occurs when ETF trades at a premium (ETF price > NAV).

**Redemption**: AP delivers ETF shares to the issuer, receives underlying securities. Occurs when ETF trades at a discount (ETF price = 0,
        w = 0,
        # Match factor exposures within tolerance
        cp.norm(port_exposures - index_exp, 'inf')  3
        }

    for stock in deletions:
        current_weight = current_weights.get(stock, 0)
        trades[stock] = {
            'action': 'SELL', 'current_weight': current_weight,
            'est_days': 1,  # deletions typically liquid enough
        }

    # Pre-trade: can start buying additions before effective date
    # Post-trade: sell deletions after effective date to reduce impact
    return trades
```

### Step 5: Tracking Error Budget

```python
def te_budget_analysis(portfolio_weights, benchmark_weights, sigma,
                       factor_exposures, factor_cov, specific_risk):
    """
    Decompose tracking error into components for budgeting.
    """
    active_weights = portfolio_weights - benchmark_weights

    # Total ex-ante tracking error
    te_total = np.sqrt(active_weights @ sigma @ active_weights) * np.sqrt(252)

    # Factor tracking error
    active_factor_exp = factor_exposures.T @ active_weights
    te_factor = np.sqrt(active_factor_exp @ factor_cov @ active_factor_exp) * np.sqrt(252)

    # Specific (idiosyncratic) tracking error
    te_specific = np.sqrt((active_weights ** 2) @ (specific_risk ** 2)) * np.sqrt(252)

    budget = {
        'total_te': te_total,
        'factor_te': te_factor,
        'specific_te': te_specific,
        'sector_te': compute_sector_te(active_weights, sigma),  # sector contribution
        'cash_drag_te': estimate_cash_drag_te(avg_cash_pct=0.005),
    }

    return budget

def estimate_cash_drag_te(avg_cash_pct, benchmark_vol=0.15):
    """Cash drag TE approximately equals cash_pct * benchmark_vol."""
    return avg_cash_pct * benchmark_vol
```

## Examples

### Tracking S&P 500 with 200 Stocks

```python
# Top 200 by market cap covers ~85% of index weight
# Optimization reduces TE from ~50 bps (naive) to ~15 bps
sp500 = load_sp500_constituents()
sample = stratified_sample(sp500, target_holdings=200)

# Expected TE sources:
# Sampling: ~10-15 bps
# Cash drag: ~5-8 bps (0.5% average cash * 15% vol)
# Rebalancing: ~3-5 bps
# Total: ~15-25 bps annualized
```

### Securities Lending Revenue

```python
# ETFs offset costs through securities lending
lending_revenue = {
    'US Large Cap': 0.01,       # 1 bp (low demand)
    'US Small Cap': 0.05,       # 5 bps
    'Emerging Markets': 0.10,   # 10 bps
    'High Yield Bonds': 0.08,   # 8 bps
}
# Lending revenue partially offsets expense ratio and trading costs
```

## Quality Gate

- [ ] Tracking error measured correctly (annualized std of daily return differences)
- [ ] Replication method appropriate for index size and liquidity
- [ ] Stratified sampling matches key dimensions (sector, size, factor exposures)
- [ ] Cash drag estimated and managed (dividend reinvestment, flow management)
- [ ] Reconstitution costs estimated — pre-positioning considered for predictable changes
- [ ] Tracking error budget decomposed into factor, specific, and cash components
- [ ] Securities lending terms reviewed (counterparty risk, collateral, revenue split)
- [ ] Synthetic replication counterparty risk assessed (swap provider creditworthiness)
- [ ] Corporate action handling procedures documented and tested
- [ ] Realized TE compared to ex-ante TE estimate — persistent gaps indicate model issues

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [brainbytes-dev](https://github.com/brainbytes-dev)
- **Source:** [brainbytes-dev/everything-claude-trading](https://github.com/brainbytes-dev/everything-claude-trading)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-brainbytes-dev-everything-claude-trading-benchmark-tracking
- Seller: https://agentstack.voostack.com/s/brainbytes-dev
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
