Install
$ agentstack add skill-brainbytes-dev-everything-claude-trading-benchmark-tracking ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →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(portexposures - indexexp, 'inf') 3 }
for stock in deletions: currentweight = currentweights.get(stock, 0) trades[stock] = { 'action': 'SELL', 'currentweight': currentweight, '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
# 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
# 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
- Source: brainbytes-dev/everything-claude-trading
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.