io.github.arhancanli/canli-quant-mcp·Other

Canli Quant

235 quant tools and 399 strategy sleeves, checked against QuantLib, statsmodels, arch or TA-Lib.

Stars
0
Version
0.1.2
License
MIT
Review
Passed
Language
HTML
Last commit
2h ago
Forks
1
Open issues
25
Registry update
Oct 13, 2026
ai-agentsalgorithmic-tradingbacktest-overfittingbacktestingclaudeclaude-codedeflated-sharpe-ratiofinancefinancial-datafintechinvestment-researchmcp

Connect

npm
Terminal
$claude mcp add canli-quant-mcp \  -e CANLI_TOOLSETS=<canli-toolsets> \  -- npx -y [email protected]

Environment variables

  • CANLI_TOOLSETS

    Toolsets to list directly (comma-separated, or all). Default: three discovery tools that reach every tool.

Security review

Review passed

Reviewed 48m ago.

metadata
scanned
packages
1 checked

No findings.

Tools

This server runs on your machine, so its tool list is not fetched before install — the README below describes what it offers.

canli-quant-mcp

Computed NaN and Infinity values are refused with a tool error naming the affected fields. They do not become unexplained nulls or receive a success receipt. Check the input scale and the calculation's domain. Ordinary finite answers and null warm-up positions are preserved.

235 quant finance tools in one MCP server: performance and risk, options and exotics, fixed income, portfolio construction, econometrics, technical indicators, execution, sizing, crypto and FX, valuation, strategy backtests, a library of 399 strategy sleeves, data checks, and data annotation and ML labeling. Every tool computes on the data you send, and every tool's results are checked in the test suite against an independent implementation (QuantLib, statsmodels, arch, TA-Lib, numpy-financial, scikit-learn, empyrical, scipy, pandas, dcor): 465 reference cases, plus planted-defect tests for the data checks.

Local stdio, no key, no account, no network calls: your data never leaves your machine (see Privacy, enforced by tests).

Three tools in context, 235 behind them

Listing 238 tools directly costs 83,944 tokens of context (o200k) on every request. By default this server lists three, 680 tokens:

toolwhat it does
find_toolSearch the catalog in plain words ("cornish fisher var", "barrier option", "kpss").
describe_toolOne tool's description and exact input schema.
run_toolRun any tool by name. receipt: true adds a calculation receipt.

find_tool ranks with BM25 over each tool's name, title, keywords and description, with stemming and finance abbreviations (cvar, npv, irr, ytm...). On 110 test requests it returns the right tool first 94% of the time and in the top three 99% (test/search.test.mjs), so a model rarely needs a second search. run_tool takes digits (3-10 significant figures; default 10) to cut output tokens when full precision is not needed: 9-19% fewer tokens at 4-6 digits on the results we measured.

Measured on an Apple-silicon laptop (Node 24): connect and initialize 140 ms; a typical tool call 0.26 ms median over stdio; find_tool 1 ms; a full 399-sleeve tournament on 1,200 days of six assets about 2 s.

The tool list is byte-identical across launches, so providers can cache it. To list toolsets directly instead, set CANLI_TOOLSETS to a comma-separated list (e.g. performance,options, 8,053 tokens for performance alone) or all.

Quick start

npx -y canli-quant-mcp

Claude Code:

claude mcp add canli-quant -- npx -y canli-quant-mcp

Claude Desktop, Cursor or any MCP client:

{ "mcpServers": { "canli-quant": { "command": "npx", "args": ["-y", "canli-quant-mcp"] } } }

Then ask, for example:

  • "Here are my strategy's daily returns. I tried 40 variants. Does the edge survive deflation?"
  • "Price a 6-month down-and-out call, strike 100, barrier 90, vol 25%, and compare it with the vanilla."
  • "Is this spread mean-reverting? Run ADF, KPSS and the variance ratio, then backtest it with costs."
  • "Check this option chain for arbitrage before I fit a surface to it."
  • "Which of the 399 sleeves hold up on these ETF prices after correcting for trying them all?"
  • "Is this market in a calm or a turbulent regime right now, and how long do regimes last?"

Toolsets

toolsettoolschecked against
performance23numpy, scipy, statsmodels and empyrical-reloaded
options12QuantLib (analytic engines; finite differences for American options); an independent implementation of the CBOE VIX method; the lognormal density for Breeden-Litzenberger
indicators30TA-Lib's C library, bar for bar; pandas for indicators TA-Lib lacks
econometrics27statsmodels (OLS, HAC, ADF, KPSS, Engle-Granger and Johansen cointegration, Granger, ARCH LM, Markov switching, recursive least squares and CUSUM), arch (GARCH, variance ratio), scipy and dcor (rank and distance correlation)
exotics9QuantLib (barrier, Asian, Heston, SABR, Kirk, Margrabe, lookback and chooser engines)
rates15QuantLib bonds and short-rate models; numpy and scipy for curves and swaps; scipy fsolve for Merton
risk7numpy and scipy re-derivations; scipy's generalized Pareto likelihood for EVT
returns4pandas resampling and closed forms
portfolio15numpy closed forms, scipy SLSQP, scikit-learn Ledoit-Wolf, the HRP paper's code
execution7closed forms (Almgren-Chriss kappa solved numerically), statsmodels OLS
sizing7scipy and closed forms
crypto_fx9closed forms and simulated pool reserves
strategies20an independent pandas implementation of every recipe and of the costed engine
sleeves8an independent numpy and pandas port of every recipe and the engine; arch's Reality Check and an independent re-studentized SPA and StepM on the same bootstrap draws; scipy average linkage; numpy CSCV; plus no-lookahead and warm-up checks on every sleeve
data_checks10planted-defect tests: each check must find what was planted and stay quiet on clean data
labeling7pandas ports of the snippets in Advances in Financial Machine Learning (ewm volatility, CUSUM filter, triple barrier, uniqueness, purged k-fold) and statsmodels OLS t-values
tvm15numpy-financial and closed forms
valuation10published formulas re-derived independently

Workflows (prompts)

Prompts chain the tools for common jobs: analyze_strategy, audit_backtest, value_company, price_option, test_mean_reversion, build_portfolio, analyze_trade_log, sleeve_tournament, build_sleeve_book, label_dataset, check_dataset.

Resources: canli-quant://catalog (every tool), canli-quant://methods (what each toolset is checked against), canli-quant://tools/{name} (one tool's schema), canli-quant://sleeves (the sleeve library), canli-quant://sleeves/{id} (one sleeve's spec) and canli-quant://privacy.

Sleeve library

399 strategy sleeves in 18 families, each a published idea with its usual parameters swept on a plain grid: moving-average crossovers, time-series momentum, multi-horizon trend, channel breakouts, MACD, z-score and RSI reversion, volatility targeting, cross-sectional momentum, dual momentum, risk parity, equal weight, minimum variance, low volatility, short-term reversal, trend-filtered allocation, 52-week-high momentum and pairs. Every sleeve has a fixed rule, a stated warm-up, references, known risks and a SHA-256 of its spec. None was picked because it backtested well: they are definitions, not track records.

Running many strategies and keeping the best is how backtests overfit, so the tools that run many sleeves at once correct for it:

toolwhat it answers
sleeve_tournamentWhich sleeves lead on your prices, and does the best survive the deflated Sharpe ratio (counting all sleeves and the effective number of independent ones), White's Reality Check, Hansen's SPA test and Romano-Wolf StepM (re-studentized in every resample) and the probability of backtest overfitting (CSCV)?
sleeve_walk_forwardIf you had kept picking the top sleeves by trailing Sharpe, what would you have earned out of sample, and how much of their in-sample Sharpe was luck?
sleeve_clustersHow many genuinely different bets do the sleeves make on this data?
sleeve_regime_mapWhich sleeves held up in calm, turbulent, rising and falling markets?
combine_sleevesWhat does a book of chosen sleeves look like, and what asset weights does it want as of the latest close?

The tests check that no sleeve looks ahead (rewriting future prices never changes an earlier target), that none trades before its warm-up, and that the tournament's statistics match arch's Reality Check and an independent re-studentized SPA and StepM on the same bootstrap draws, scipy's clustering and an independent numpy CSCV. run_sleeve and combine_sleeves return target_weights by symbol, which a paper broker such as canli-paper-trading-mcp can rebalance to.

Data annotation and ML labels

The labeling toolset annotates your own data and turns it into training labels without leakage:

toolwhat it does
annotate_price_seriesTags every period: outlier moves, stale prices, drawdown episodes, new highs, causal volatility regime.
cusum_filter_eventsPicks the periods worth labeling (CUSUM filter on log prices).
triple_barrier_labelsLabels by which of a volatility-scaled profit-take, stop-loss or time limit is hit first; with a side, meta-labels.
fixed_horizon_labelsLabels by the forward return over a horizon, with a fixed or volatility-scaled dead zone.
trend_scanning_labelsLabels by the strongest forward trend's t-statistic.
sample_weightsUniqueness, return-attribution and time-decay weights for overlapping labels.
purged_cv_splitsK-fold splits that purge overlapping labels and embargo the periods after each test fold.

Each label says which future periods it used, so purging and embargoing are exact. The methods follow Lopez de Prado's Advances in Financial Machine Learning, checked against pandas ports of its code.

Privacy

Your data stays on your machine. The server is a local stdio process with no network code, writes nothing to disk, logs nothing, starts no processes, and keeps arguments only for the duration of a call. test/privacy.test.mjs holds the code to that with a static scan of every source file and by running the server under Node's permission model, with reads limited to its own package and writes, child processes and workers denied. For the same lockdown in use:

npm i -g canli-quant-mcp
node --permission --allow-fs-read="$(npm root -g)/canli-quant-mcp" "$(npm root -g)/canli-quant-mcp/src/server.mjs"

canli-quant://privacy states the guarantees from inside the server. Calculation receipts carry hashes, never the data.

Calculation receipts

run_tool with receipt: true returns the SHA-256 of the tool name and arguments, the SHA-256 of the result, and the server version. Anyone can run the same tool with the same arguments on that version and compare the output hash. Results are deterministic: no clock, no network, and the only randomness is the sleeve bootstrap, drawn from a stated seed.

Conventions

  • Returns are simple fractions (0.01 = 1%), oldest first. Tools refuse returns of -100% or below and series that look like percents.
  • Rates are annual; options use continuous compounding; bond yields compound at the coupon frequency.
  • Results are rounded to 10 significant figures.
  • Strategy backtests decide weights at the close of period t and earn period t+1's return; weights drift between rebalances and costs are charged on turnover.

All tools

performance: Performance and risk (23)
toolwhat it does
return_statsSummarize a return series: periods, annualized geometric return (CAGR) and volatility, Sharpe, max drawdown, skew, excess kurtosis, best and worst period, share positive.
sharpe_ratioCompute the annualized Sharpe ratio with its standard error and 95% interval, under iid normal returns (Lo 2002) and allowing skew and fat tails (Mertens 2002). For the probability it beats luck across many trials, use canli-validation-mcp.
sortino_ratioCompute the annualized Sortino ratio: mean return above a target over downside deviation below it, with the downside deviation itself.
max_drawdownFind the maximum drawdown and the worst drawdown episodes: depth, peak, trough, recovery and length in periods, plus time under water.
calmar_ratioCompute the Calmar ratio: annualized geometric return over the absolute maximum drawdown of the whole series.
omega_ratioCompute the Omega ratio at a threshold: the sum of gains above it over the sum of losses below it.
value_at_riskEstimate value at risk as a positive loss fraction: historical, Gaussian and Cornish-Fisher (skew and kurtosis adjusted), over one or more periods.
expected_shortfallEstimate expected shortfall (CVaR): the average loss beyond value at risk, historical and Gaussian, as a positive loss fraction.
capm_regressionRegress excess returns on benchmark excess returns: beta, alpha (annualized), their t-stats and p-values, R-squared, correlation and residual (idiosyncratic) volatility.
information_ratioCompute active return, tracking error and the information ratio of a strategy against its benchmark, annualized.
treynor_ratioCompute the Treynor ratio: annualized excess return per unit of beta to the benchmark.
m2_measureCompute Modigliani's M-squared: the return the strategy would have earned levered to the benchmark's volatility, and its difference from the benchmark.
capture_ratiosCompute up-market and down-market capture: the strategy's annualized return in benchmark up periods and down periods, relative to the benchmark's.
ulcer_indexCompute the Ulcer index (root-mean-square drawdown), the Martin (ulcer performance) ratio, and the pain index and pain ratio (mean drawdown).
drawdown_at_riskEstimate drawdown at risk (a drawdown quantile across periods) and conditional drawdown at risk (the mean drawdown beyond it), as positive fractions.
tail_ratioCompute the tail ratio (95th percentile return over the absolute 5th) and the Rachev ratio (mean of the best tail over the mean loss of the worst tail).
gain_to_painCompute Schwager's gain-to-pain ratio: the sum of returns over the absolute sum of losing returns.
trade_statsSummarize closed-trade results: win rate, profit factor, payoff ratio, expectancy, largest win and loss, and longest winning and losing streaks.
kelly_fractionCompute the growth-optimal (Kelly) fraction: from a return series (continuous, (mean - rf) / variance), or from a win probability and payoff odds. Also gives half Kelly.
autocorrelationTest a return series for serial correlation: autocorrelations at each lag and the Ljung-Box Q statistic with its p-value.
normality_testTest whether returns are normal with the Jarque-Bera test, with skew and excess kurtosis.
autocorrelation_adjusted_sharpeAnnualize a Sharpe ratio allowing for serial correlation (Lo 2002): smoothed or autocorrelated returns overstate the usual sqrt(time) Sharpe.
rolling_sharpeSummarize the rolling Sharpe ratio over a window: latest, min, max, median and the share of windows below zero; shows whether performance is stable or decaying.
options: Options and derivatives (12)
toolwhat it does
black_scholesPrice a European option under Black-Scholes-Merton with a dividend yield, with delta, gamma, vega, theta, rho, vanna, volga, charm, speed and the risk-neutral probability of finishing in the money.
implied_volatilitySolve for the Black-Scholes-Merton implied volatility of a European option from its price, refusing prices outside no-arbitrage bounds.
black76Price a European option on a futures or forward with Black-76, with delta, gamma and vega; also used for caps, floors and swaptions on a forward rate.
bachelierPrice a European option under the Bachelier normal model, which allows negative forwards (rates, spreads), with delta, gamma and vega.
american_optionPrice an American option with a dividend yield (binomial Black-Scholes with Richardson extrapolation), with the European price and the early-exercise premium.
digital_optionPrice a European cash-or-nothing or asset-or-nothing digital option under Black-Scholes-Merton, with delta.
put_call_parityCheck put-call parity for a European pair: the parity gap, the implied forward and the implied rate-minus-yield, to spot mispricing or stale quotes.
option_strategy_payoffEvaluate a multi-leg options position at expiry (calls, puts, underlying): net premium, payoff and profit at chosen prices, breakevens, and maximum profit and loss.
option_portfolio_greeksAggregate Black-Scholes-Merton Greeks across many option positions on one underlying: net delta, gamma, vega, theta, rho and the dollar delta and gamma.
volatility_conversionsConvert volatility between periods and forms: annual to daily, weekly or monthly, the expected move over a horizon, and lognormal to approximate normal (basis point) volatility.
vix_style_indexCompute a VIX-style model-free implied volatility from option chains with the CBOE method: forward from put-call parity, out-of-the-money strips with the two-zero-bid cutoff, per-expiry variance, and interpolation to a constant maturity (30 days by default).
risk_neutral_densityRecover the market's risk-neutral distribution from call prices across strikes (Breeden-Litzenberger): density and cumulative probability at each strike, its mean, volatility, skewness and kurtosis, probabilities beyond chosen levels, and strikes where the density is negative (butterfly arbitrage).
indicators: Technical indicators (30)
toolwhat it does
smaCompute the simple moving average of closing prices over a lookback.
emaCompute the exponential moving average (seeded with the simple average, as TA-Lib does).
wmaCompute the linearly weighted moving average (latest price weighted most).
demaCompute the double exponential moving average (2 EMA - EMA of EMA), which lags less than an EMA.
temaCompute the triple exponential moving average (3 EMA - 3 EMA2 + EMA3).
hull_moving_averageCompute the Hull moving average, WMA(2 WMA(n/2) - WMA(n), sqrt n), a fast, smooth trend line.
kamaCompute Kaufman's adaptive moving average, which speeds up in trends and slows in noise (efficiency ratio, fast 2, slow 30).
rsiCompute Wilder's relative strength index (0-100): above 70 often read as overbought, below 30 as oversold.
macdCompute MACD (fast EMA - slow EMA), its signal line and histogram, as TA-Lib does.
bollinger_bandsCompute Bollinger Bands: a moving average with bands k population standard deviations above and below, plus %B and bandwidth.
stochasticCompute the slow stochastic oscillator: %K (smoothed position of the close in the high-low range) and %D.
williams_rCompute Williams %R (-100 to 0): where the close sits in the recent high-low range.
cciCompute the commodity channel index: typical price's distance from its average in units of mean absolute deviation.
atrCompute Wilder's average true range and its percent of price (NATR), the standard volatility measure for stops and sizing.
adxCompute Wilder's ADX trend strength with +DI and -DI (TA-Lib's smoothing): ADX above 25 is usually read as trending.
obvCompute on-balance volume, the running sum of volume signed by the close's direction.
money_flow_indexCompute the money flow index (volume-weighted RSI, 0-100) from typical price and volume.
rate_of_changeCompute rate of change (percent change over n bars) and momentum (price difference over n bars).
trixCompute TRIX, the one-bar percent change of a triple-smoothed EMA, a filtered momentum oscillator.
aroonCompute Aroon up and down (0-100: how recently the highest high and lowest low occurred) and the Aroon oscillator.
chande_momentumCompute the Chande momentum oscillator (-100 to 100) with Wilder smoothing, as TA-Lib does.
ultimate_oscillatorCompute Williams' ultimate oscillator, blending buying pressure over three horizons (7, 14, 28 by default).
accumulation_distributionCompute the Chaikin accumulation/distribution line and the Chaikin oscillator (fast EMA - slow EMA of the line).
donchian_channelsCompute Donchian channels: the highest high and lowest low over a lookback and their midpoint (breakout systems).
keltner_channelsCompute Keltner channels: an EMA of the close with bands a multiple of ATR above and below.
vwapCompute the cumulative volume-weighted average price from typical price, or a rolling VWAP over a window.
ichimoku_cloudCompute the Ichimoku lines: conversion (tenkan), base (kijun), leading spans A and B (shown at the bar they are computed, not shifted forward) and lagging span.
rolling_zscoreCompute each price's z-score against its rolling mean and sample standard deviation, the basic mean-reversion signal.
stochastic_rsiCompute the stochastic RSI: where RSI sits in its own recent range (%K, unsmoothed by default as in TA-Lib) and its moving average %D.
parabolic_sarCompute Wilder's parabolic stop-and-reverse trailing stop with its trend direction (acceleration 0.02 step, 0.2 max by default).
econometrics: Statistics and econometrics (27)
toolwhat it does
linear_regressionFit ordinary least squares of y on several regressors with classical, heteroskedasticity-robust (HC1) or Newey-West HAC standard errors, R-squared, F-test and AIC.
factor_regressionRegress a strategy's excess returns on factor returns (e.g. Fama-French market, size, value, momentum) with Newey-West errors: annualized alpha, its t-stat, factor betas and R-squared.
adf_testTest a price, spread or rate series for a unit root (non-stationarity) with the Augmented Dickey-Fuller test: statistic, MacKinnon p-value, critical values and the AIC-chosen lag.
kpss_testTest the null that a series is level- or trend-stationary with the KPSS test (Hobijn lag rule), complementing ADF; p-values are table-interpolated within 0.01-0.10.
variance_ratio_testTest the random-walk hypothesis on prices with the Lo-MacKinlay variance ratio at one or more horizons (overlapping, de-biased, heteroskedasticity-robust): above 1 means trending, below 1 mean-reverting.
cointegration_testTest whether two or more price series are cointegrated (Engle-Granger): hedge ratios, ADF on the residual spread with MacKinnon p-value and critical values, and the spread's half-life.
mean_reversion_fitFit an AR(1) / Ornstein-Uhlenbeck model to a spread or price series: half-life, mean, speed of reversion, equilibrium volatility and the current z-score.
garch_volatilityFit a GARCH(1,1) model with constant mean by maximum likelihood: omega, alpha, beta, persistence, long-run volatility, volatility half-life and the next-period volatility forecast.
ewma_volatilityCompute exponentially weighted volatility (RiskMetrics, lambda 0.94 by default): the current annualized estimate and optionally the full series.
range_volatilityEstimate volatility from open, high, low and close prices with close-to-close, Parkinson, Garman-Klass, Rogers-Satchell and Yang-Zhang estimators, annualized.
probabilistic_sharpe_ratioCompute the probability that the true Sharpe ratio exceeds a benchmark given the track record's length, skewness and kurtosis (Bailey and López de Prado), and the minimum track record length needed.
deflated_sharpe_ratioDeflate a backtest's Sharpe ratio for the number of strategies tried (Bailey and López de Prado 2014): the expected maximum Sharpe under the null and the probability the result beats it.
pca_factorsRun principal component analysis on asset returns (correlation or covariance): explained variance per component, cumulative share and each component's loadings.
rolling_betaCompute a rolling-window beta (and correlation) of returns against a benchmark: latest, average, minimum and maximum, optionally the full series.
granger_causalityTest whether past values of x help predict y beyond y's own past (Granger causality), with the F-test at each lag up to a maximum.
arch_effects_testTest demeaned returns for volatility clustering with Engle's ARCH Lagrange multiplier test: LM statistic, chi-squared p-value, and the F version.
mean_return_testTest whether a strategy's mean return differs from zero (or a target) with a one-sample t-test and a Newey-West t-statistic robust to autocorrelation.
compare_sharpe_ratiosTest whether two strategies' Sharpe ratios differ (Jobson-Korkie with Memmel's correction) using their returns over the same periods.
welch_t_testTest whether two samples (e.g. returns in two regimes, before and after a change) have different means, without assuming equal variances (Welch).
markov_regime_switchingFit a Hamilton Markov-switching model with a mean and volatility per regime (2 or 3 regimes) by maximum likelihood: regime means and volatilities, transition probabilities, expected durations, the current regime probabilities and how much time was spent in each.
johansen_cointegrationTest how many cointegrating relationships tie several price series together (Johansen trace and maximum-eigenvalue tests with Osterwald-Lenum critical values), with the rank chosen at 5% and the normalized cointegrating vectors.
recursive_stability_testCheck whether a regression's coefficients stayed stable over time: recursive least squares coefficient paths, and the CUSUM and CUSUM-of-squares tests of Brown, Durbin and Evans with 5% bounds and the first period each one crosses.
chow_break_testTest for a structural break in a regression at a known period (Chow F-test), or scan every candidate break inside a trimmed range for the largest F statistic and where it falls.
har_rv_forecastFit Corsi's heterogeneous autoregressive (HAR) model of realized variance on its daily, weekly and monthly averages, with Newey-West errors, and forecast variance and volatility over the next horizon.
realized_volatility_measuresFrom intraday returns per day, compute realized variance, bipower variation, the jump component and the Barndorff-Nielsen-Shephard jump test (tripower quarticity), realized semivariances, realized skewness and kurtosis, and the daily series for HAR forecasts.
dependence_measuresMeasure how two series move together: Pearson, Spearman and Kendall correlations with p-values, distance correlation (catches nonlinear dependence), and empirical lower and upper tail dependence (do they crash together?).
bootstrap_confidence_intervalPut a confidence interval on a performance statistic (Sharpe, Sortino, CAGR, volatility, max drawdown, Calmar, mean) with the stationary block bootstrap, which keeps autocorrelation and volatility clustering; also gives the bootstrap standard error and the share of resamples at or below zero.
exotics: Exotic options and volatility models (9)
toolwhat it does
barrier_optionPrice a continuously monitored single-barrier option (down/up, in/out, call/put, with rebate) in closed form (Reiner-Rubinstein), with the vanilla price and the barrier discount.
asian_option_geometricPrice a continuously averaged geometric-average-price Asian option in closed form (Kemna-Vorst); a lower bound and control variate for the arithmetic Asian.
heston_optionPrice a European option under the Heston stochastic-volatility model by Fourier integration of its characteristic function, with delta, in-the-money probability and the Feller condition.
sabr_volatilityCompute the Black implied volatility of a strike under the SABR model (Hagan et al. 2002) from alpha, beta, nu and rho, optionally across several strikes for a smile.
spread_optionPrice a European option on the spread between two futures (F1 - F2 - K) with Kirk's approximation, as used for crack and spark spreads.
exchange_optionPrice the option to exchange one asset for another, max(Q1 S1 - Q2 S2, 0), in closed form (Margrabe), with dividend yields on both.
lookback_optionPrice a continuously monitored floating-strike lookback option (Goldman-Sosin-Gatto): a call pays the final price minus the minimum, a put the maximum minus the final price.
chooser_optionPrice a simple chooser option, which lets the holder decide at a choice date whether it is a call or a put with the same strike and expiry (Rubinstein).
jump_diffusion_optionPrice a European option under Merton's jump-diffusion model (lognormal jumps) as a Poisson-weighted sum of Black-Scholes prices.
rates: Fixed income and rates (15)
toolwhat it does
bond_pricePrice a fixed-rate bond from its yield on real dates and a day count: clean and dirty price, accrued interest, Macaulay and modified duration, convexity and DV01.
bond_yieldSolve a fixed-rate bond's yield to maturity from its clean price, with duration, convexity and DV01 at that yield.
zero_coupon_bondPrice a zero-coupon bond from its yield or solve the yield from its price, under annual, periodic or continuous compounding, with duration and convexity.
bootstrap_zero_curveBootstrap discount factors, zero rates (continuous and periodic) and period forward rates from par yields, interpolating par yields linearly onto the coupon grid.
forward_rateCompute the forward rate between two maturities implied by their zero rates, under continuous, periodic or simple compounding, with the forward discount factor.
nelson_siegel_fitFit a Nelson-Siegel curve (level, slope, curvature, decay tau) to observed yields by least squares, with fitted yields and RMSE; tau is searched when not given.
interest_rate_swapValue a spot-starting fixed-for-floating swap on a zero curve (single curve): par swap rate, value to the fixed payer, fixed-leg annuity and DV01s.
forward_rate_agreementValue a forward rate agreement on a zero curve: the simple forward rate for the period and the value to the party that pays the fixed rate.
z_spreadSolve a fixed-rate bond's z-spread: the constant spread over a continuously compounded zero curve that reprices its cash flows to the market dirty price.
credit_hazard_rateConvert a credit spread and recovery rate into a constant hazard rate (credit triangle), survival and default probabilities over a horizon, and the reverse.
short_rate_bond_pricePrice a zero-coupon bond and its yield under the Vasicek or Cox-Ingersoll-Ross short-rate model in closed form.
treasury_bill_yieldsConvert a T-bill's price or bank discount rate into the discount yield, bond-equivalent (investment) yield, money-market yield and effective annual yield.
key_rate_durationsMeasure a fixed-rate bond's sensitivity to each pillar of a zero curve: bump one pillar by 1 bp (triangular bump, linear in between) and reprice, giving key rate DV01s and durations that sum to the parallel figure.
breakeven_inflationCompute breakeven inflation from a nominal and a real (inflation-linked) yield of the same maturity, exactly (Fisher) and approximately, and the real yield implied by an inflation view.
merton_credit_riskBack out a firm's asset value and asset volatility from its equity value and equity volatility with Merton's model (equity as a call on assets), then the distance to default, default probability, the implied credit spread and the value of the debt.
risk: Portfolio risk and stress (7)
toolwhat it does
portfolio_varCompute a positions portfolio's historical and parametric (normal) value at risk and expected shortfall from asset return history, with each position's contribution and the diversification benefit.
stress_testApply named scenarios (a return shock per position, or a market shock passed through each position's beta) to a portfolio and report the P&L of each scenario and the worst position.
option_scenario_gridRevalue a book of European options and stock under a grid of spot moves and volatility shifts (full Black-Scholes revaluation), with P&L per cell and the book's current Greeks.
exposure_and_hedgeSummarize a long/short book's gross, net and beta-adjusted exposure and size an index hedge (futures contracts or ETF shares) that neutralizes the beta.
concentration_metricsMeasure how concentrated a portfolio is: Herfindahl index, effective number of positions, largest and top-k shares, and the Gini coefficient of weights.
liquidation_horizonEstimate how many days each position takes to exit at a maximum share of average daily volume, and how much of the book can be liquidated within 1, 5 and 20 days.
extreme_value_tailModel the loss tail with extreme value theory: fit a generalized Pareto distribution to losses beyond a high threshold (peaks over threshold) and estimate value at risk and expected shortfall far into the tail, with the Hill tail index.
returns: Returns transforms and attribution (4)
toolwhat it does
convert_returnsConvert between prices, simple returns and log returns, or rebase a price series to start at 100; returns the converted series.
resample_returnsCompound periodic returns into calendar weeks (ISO), months, quarters or years using their dates.
monthly_returns_tableBuild the year-by-month return table from periodic returns and dates, with each year's compounded total, the best and worst months and the share of positive months.
brinson_attributionAttribute active return to allocation, selection and interaction effects by segment (Brinson-Fachler) from portfolio and benchmark weights and returns.
portfolio: Portfolio construction and risk (15)
toolwhat it does
portfolio_riskDecompose a portfolio's volatility into each asset's risk contribution, with marginal risk, diversification ratio, effective number of assets, parametric VaR and ex-ante tracking error to a benchmark.
min_variance_portfolioFind the fully invested minimum-variance portfolio, long-only with an optional weight cap (exact active-set solution) or unconstrained (closed form).
max_sharpe_portfolioFind the portfolio with the highest Sharpe ratio, long-only (exact) or unconstrained (closed form tangency), with its expected return, volatility and Sharpe.
mean_variance_portfolioFind the minimum-variance portfolio that reaches a target expected return, or the utility-maximizing portfolio for a risk aversion, long-only or unconstrained.
risk_parity_portfolioFind long-only weights where every asset contributes equally (or by a given budget) to portfolio volatility, solved by Newton's method.
inverse_volatility_weightsWeight assets in proportion to the inverse of their volatility (or variance), the simple risk-balancing heuristic.
hierarchical_risk_parityAllocate with López de Prado's hierarchical risk parity: single-linkage clustering on correlation distance, quasi-diagonal ordering and recursive bisection.
efficient_frontierTrace the efficient frontier: minimum volatility at evenly spaced target returns from the minimum-variance portfolio to the highest-return asset, with weights.
black_littermanBlend market-implied equilibrium returns with your views (absolute or relative, with confidence) into Black-Litterman posterior returns and the unconstrained optimal weights.
covariance_shrinkageEstimate a well-conditioned covariance matrix by Ledoit-Wolf shrinkage toward a scaled identity, with the shrinkage intensity and condition numbers before and after.
correlation_matrixCompute Pearson or Spearman rank correlations between assets, with the average pairwise correlation and the largest eigenvalue's share (how much one factor drives everything).
rebalance_tradesTurn current holdings and target weights into the share trades that rebalance the portfolio, with turnover, optional no-trade bands, and cash left over.
kelly_portfolioCompute growth-optimal (Kelly) weights across assets, inverse covariance times excess returns, with half-Kelly and the implied leverage and growth rate.
max_diversification_portfolioFind the long-only portfolio with the highest diversification ratio (weighted average volatility over portfolio volatility), Choueifaty and Coignard's most-diversified portfolio.
index_tracking_portfolioFind long-only weights in a subset of assets that minimize ex-ante tracking error to a benchmark's weights, with an optional per-asset cap.
execution: Execution and microstructure (7)
toolwhat it does
almgren_chriss_scheduleCompute the Almgren-Chriss optimal liquidation schedule for a block: holdings and trades per period, expected impact cost and its standard deviation for a given risk aversion.
market_impact_estimateEstimate the cost of an order with the square-root impact law (cost = Y x volatility x sqrt(order / daily volume)) plus half the spread, in basis points and currency.
implementation_shortfallMeasure an executed order's implementation shortfall against the decision price, split into delay, execution (impact), opportunity cost of unfilled shares and fees.
execution_scheduleSplit an order across time buckets evenly (TWAP) or by an expected volume profile (VWAP), capped at a maximum participation rate, with what cannot be done within the horizon.
spread_estimatorsEstimate the effective bid-ask spread from trade prices alone (Roll 1984) and from daily highs and lows (Corwin-Schultz 2012) when quotes are not available.
liquidity_measuresMeasure price impact per unit of trading: Amihud illiquidity (|return| per currency traded) and Kyle's lambda (price change per signed volume, by regression).
order_book_analysisAnalyze an order book snapshot: mid, spread, microprice, depth imbalance, and the average fill price and slippage of a market order of a given size walking the book.
sizing: Position sizing and trade risk (7)
toolwhat it does
position_size_from_stopSize a trade so that hitting the stop loses a fixed fraction of equity: shares, notional, capital at risk and leverage, optionally capped by a maximum position weight.
volatility_target_sizeScale a position so its expected volatility matches a target: the weight (leverage) from the asset's volatility, shares for a given equity, optionally capped.
optimal_fFind the fraction f of the largest loss to risk per trade that maximizes terminal wealth over a list of trade results (Vince's optimal f), with the geometric mean and the f-based position size.
trade_expectancyCompute a trading rule's expectancy per trade after costs, the break-even win rate for its payoff, and the payoff needed at its win rate.
drawdown_probabilityEstimate the probability that a strategy with a given return and volatility ever falls a given fraction below its starting equity (drifted Brownian motion, continuous), and within a horizon.
leverage_and_marginCompute leverage, initial and maintenance margin, free margin, and the adverse price move that triggers a margin call for a leveraged position.
var_position_limitFind the largest position whose one-day (or n-day) parametric value at risk stays within a budget, given the asset's volatility.
crypto_fx: Crypto and FX (9)
toolwhat it does
funding_rate_carryAnnualize perpetual-futures funding rates (simple APR and compounded APY) and compute the funding a position pays or earns over a holding period; accepts one rate or a history.
futures_basisCompute a dated future's basis to spot, its annualized carry (simple and compounded) and the implied financing rate, for cash-and-carry trades.
liquidation_priceEstimate a leveraged position's liquidation price under isolated margin: initial margin = 1/leverage, liquidated when equity falls to the maintenance rate (exchange formulas add fees and tiers).
fx_forwardPrice an FX forward from spot and the two currencies' money-market rates (covered interest parity, ACT/360 or ACT/365), with forward points in pips, or back out the implied rate from a quoted forward.
fx_cross_rateDerive a cross rate's bid and ask from two quotes against a common currency (e.g. EURJPY from EURUSD and USDJPY), handling which side each leg is quoted on.
triangular_arbitrageCheck three currency (or crypto) quotes for triangular arbitrage after spreads and fees: the return of each direction around the triangle.
pip_valueCompute the value of one pip for a lot size in the account currency, and the lot size that risks a given amount over a stop distance in pips.
carry_trade_returnDecompose a carry trade's return into the interest differential and the spot move, and find the break-even depreciation of the high-yield currency.
impermanent_lossCompute impermanent (divergence) loss of a liquidity position versus holding, for a constant-product pool or a concentrated range (Uniswap v3 style), given the price change.
strategies: Strategy backtests (20)
toolwhat it does
backtest_ma_crossoverBacktest a fast/slow moving-average crossover on your prices with costs and no lookahead: CAGR, Sharpe, drawdown, turnover, cost drag and buy-and-hold for comparison.
backtest_time_series_momentumBacktest time-series (absolute) momentum: hold the asset when its trailing return is positive, optionally volatility-targeted, with costs and no lookahead.
backtest_breakoutBacktest a Donchian channel breakout (turtle-style entries on new highs, exits on shorter lows) with costs and no lookahead.
backtest_zscore_reversionBacktest mean reversion on a rolling z-score of price: buy stretched lows (and short stretched highs), exit near the mean, with costs.
backtest_rsi_reversionBacktest a classic RSI oversold strategy: buy when RSI is below a threshold, sell when it recovers, with costs and no lookahead.
backtest_volatility_targetBacktest holding an asset scaled to a constant volatility target with trailing realized volatility, leverage cap and rebalance frequency.
backtest_cross_sectional_momentumBacktest cross-sectional (relative) momentum across a universe: periodically hold the top assets by trailing return (skipping the latest month), optionally short the bottom.
backtest_dual_momentumBacktest dual momentum (Antonacci): hold the best-performing risky asset when it beats cash or a safe asset, otherwise move to safety.
backtest_risk_parity_rebalanceBacktest a multi-asset inverse-volatility (naive risk parity) portfolio rebalanced periodically, optionally scaled to a volatility target.
backtest_trend_ensembleBacktest a multi-horizon trend signal: the average of time-series momentum signs over several lookbacks, optionally volatility-targeted, with costs and no lookahead.
backtest_macd_trendBacktest the MACD line against its signal line (long above, flat or short below) with costs and no lookahead.
backtest_equal_weight_rebalanceBacktest equal weights across a universe rebalanced on a fixed schedule; the 1/N benchmark that optimized portfolios must beat.
backtest_min_variance_rebalanceBacktest the long-only minimum-variance portfolio re-estimated from trailing sample covariance on a fixed schedule, with costs.
backtest_low_volatilityBacktest holding the lowest-volatility fraction of a universe, re-ranked on a schedule, with costs and no lookahead.
backtest_short_term_reversalBacktest buying the recent biggest losers in a universe (and optionally shorting the winners), re-ranked on a schedule, with costs.
backtest_trend_filter_allocationBacktest tactical asset allocation where each asset is held only while above its moving average (Faber-style), equal or inverse-volatility weighted.
backtest_high_proximityBacktest holding the assets trading closest to their trailing high (George-Hwang 52-week-high momentum), re-ranked on a schedule.
backtest_pairs_tradingBacktest a pairs trade on two price series: rolling hedge ratio, z-score of the residual spread, market-neutral entries and exits, with costs.
backtest_weightsBacktest any strategy from your own target weights per period (decided at each close, applied to the next period) with the same costed, drift-aware engine; null rows mean hold.
strategy_sweepRun one strategy recipe over a parameter grid (up to 400 variants), rank the variants by Sharpe, and deflate the best one for the number tried, so tuning cannot pass off luck as skill.
sleeves: Strategy sleeve library (8)
toolwhat it does
list_sleevesBrowse the library of 399 pre-defined strategy sleeves (18 families: trend, momentum, reversion, volatility, allocation, pairs). Each is a fixed rule with a spec hash; filter by family, data shape or words.
describe_sleeveOne sleeve's exact rule, parameters, warm-up, rationale, published references, known risks and spec SHA-256.
run_sleeveBacktest one library sleeve on your prices with costs and no lookahead: CAGR, Sharpe, drawdown, turnover, cost drag, and the target weights as of the latest close (ready for a paper rebalance).
sleeve_tournamentRun all library sleeves that fit your prices (up to 399) on a common window and rank them, then correct for the search: deflated Sharpe (raw and effective number of trials), White's Reality Check, re-studentized Hansen SPA and Romano-Wolf StepM against a benchmark, and the probability of backtest overfitting (CSCV).
sleeve_walk_forwardTest the selection process itself: at each refit pick the top sleeves by trailing Sharpe, hold them for the next window, repeat. Compares the out-of-sample result with what the picks showed in sample, with holding every sleeve, and with the benchmark.
combine_sleevesBlend chosen sleeves (equal or trailing inverse-volatility weights, no lookahead) into one book: its statistics, each sleeve's, their correlations, the diversification ratio, and the book's combined asset target weights as of the latest close.
sleeve_clustersGroup the sleeves that ran on your prices by return correlation (average linkage on sqrt((1 - rho) / 2)), to see how many genuinely different bets the library makes on this data and the best sleeve of each group.
sleeve_regime_mapScore every sleeve that fits your prices in each regime of the benchmark: calm, normal and turbulent volatility (terciles of trailing volatility) and up or down trend (above or below its moving average). Finds sleeves that held up in every regime.
data_checks: Data quality checks (10)
toolwhat it does
check_price_seriesCheck a price series for errors before using it: non-positive or missing values, unadjusted splits, outlier returns, stale runs, duplicate, unsorted or gapped timestamps.
check_ohlc_barsCheck open-high-low-close-volume bars for impossible values: high below open/close, low above them, negative volume, zero-range bars, and extreme overnight gaps.
check_option_chainCheck one expiry of an option chain: crossed or negative quotes, prices outside no-arbitrage bounds, non-monotone or non-convex prices across strikes, put-call parity breaks, and quotes with no implied volatility.
check_yield_curveCheck a zero curve for problems: unsorted tenors, discount factors that rise with maturity, negative or jumpy implied forward rates, and kinks far from neighbouring points.
check_funding_ratesCheck a perpetual-futures funding history: irregular intervals, rates beyond the venue's cap, outliers, and long one-sided runs, with the annualized range.
check_cross_venue_pricesCompare the same instrument's prices across venues at the same times: deviation of each venue from the cross-venue median, venues that stop updating, and the worst divergences.
check_timestampsCheck a column of timestamps: unparseable values, duplicates, out-of-order rows, mixed time-zone offsets, dates in the future and weekend entries, with the spacing distribution.
check_returns_seriesCheck a returns series for the usual mistakes: percents instead of fractions, impossible simple returns below -100%, constant or zero-filled stretches, extreme values and smoothing (high lag-1 autocorrelation).
check_fundamentalsCheck reported fundamentals against accounting identities: assets = liabilities + equity, current within total, gross profit = revenue - cost of revenue, cash-flow sections summing to the change in cash, and EPS x shares close to net income.
check_corporate_actionsDetect splits and dividends by comparing raw and adjusted close series: each change in the adjustment factor, classified as a split (ratio) or a dividend (percent), with mismatches flagged.
labeling: Data annotation and ML labels (7)
toolwhat it does
cusum_filter_eventsSample the periods worth labeling with the symmetric CUSUM filter on log prices: an event fires when the cumulative up or down move since the last event exceeds a threshold (fixed, or a multiple of recent volatility), so labels concentrate on meaningful moves instead of every bar.
triple_barrier_labelsLabel events with the triple-barrier method: a profit-take and a stop-loss set as multiples of recent volatility, and a time limit; each label is which barrier was touched first (+1, -1, or the sign at the time limit), with the touch period so overlapping labels can be purged. With a side per period it produces meta-labels (1 = the bet paid).
fixed_horizon_labelsLabel each period by its forward return over a fixed horizon: +1 above a threshold, -1 below minus the threshold, 0 between; the threshold can be fixed or scaled by recent volatility. Includes the class balance and the forward span each label covers.
trend_scanning_labelsLabel each period by the strongest forward trend: regress prices on time over every forward window in a range, keep the window with the largest |t-statistic| of the slope, and label by its sign with the t-statistic as confidence (Lopez de Prado's trend scanning).
sample_weightsWeight labels whose spans overlap so a model does not over-count the same information: concurrency per period, each label's average uniqueness, return-attribution weights, and optional time decay (Lopez de Prado, chapter 4).
purged_cv_splitsBuild k-fold cross-validation splits for labels that span time without leakage: training labels whose spans overlap a test fold are purged, and labels starting just after a test fold are embargoed. Reports what each fold removed, and optionally the indices.
annotate_price_seriesAnnotate every period of a price series and list the notable ones: robust-z outlier moves, stale (repeated) prices, gaps (jumps across a period), drawdown episodes with peak, trough and recovery, new all-time highs, and the causal volatility regime (calm, normal, turbulent). Gives per-period tags for joining onto your own data.
tvm: Time value and corporate finance (15)
toolwhat it does
net_present_valueCompute the NPV of periodic cash flows (first at time 0), with the profitability index, discounted payback and the IRR when one exists.
internal_rate_of_returnSolve the IRR of periodic cash flows, warning when sign changes allow several IRRs, with the NPV profile at a few rates.
modified_irrCompute the MIRR: negative flows discounted at a finance rate, positive flows compounded at a reinvestment rate, one unambiguous return.
xnpv_xirrCompute NPV and IRR for cash flows on irregular dates (ACT/365 from the first date), as spreadsheet XNPV and XIRR do.
time_value_solverSolve for any one of rate, number of periods, payment, present value or future value given the other four (loans, savings, annuities), payments at period end or start.
amortization_scheduleBuild a level-payment loan schedule: payment, interest and principal per period, remaining balance, and total interest.
rate_conversionConvert a nominal rate between compounding frequencies, to effective annual and continuous rates, and remove inflation (exact Fisher real rate).
growing_annuityValue a growing annuity (present and future value) or a growing perpetuity whose first payment arrives in one period.
payback_periodCompute simple and discounted payback periods, interpolated within the period that recovers the investment.
equivalent_annual_annuityConvert a project's NPV into an equivalent level annual amount, to compare projects with different lives.
waccCompute WACC from market values and costs of equity, debt and preferred, with after-tax cost of debt; cost of equity can come from CAPM.
levered_betaUnlever an observed equity beta to an asset beta and relever it at a target debt-to-equity ratio (Hamada), for comparable-company cost of equity.
break_evenCompute break-even units and revenue, contribution margin, margin of safety and degree of operating leverage from price, variable cost and fixed costs.
loan_true_costFind a loan's true annual cost when upfront fees reduce the cash received: the payment, the nominal APR and effective annual rate implied by the fees, and the total cost.
retirement_projectionProject a savings balance with yearly contributions growing with salary, then sustainable inflation-adjusted withdrawals; reports the balance at retirement, how long withdrawals last and the safe level spending.
valuation: Valuation and fundamental scores (10)
toolwhat it does
dcf_valuationValue a business from forecast free cash flows with a Gordon-growth or exit-multiple terminal value: enterprise and equity value, per-share value and a discount-rate by growth sensitivity grid.
reverse_dcfSolve the free-cash-flow growth rate the current share price implies over a forecast horizon, given a discount rate and terminal growth.
dividend_discount_modelValue a share with the Gordon growth, two-stage or H-model dividend discount model, or back out the required return the price implies (Gordon).
residual_income_valuationValue equity as book value plus discounted residual income (earnings above the cost of equity on opening book), with clean-surplus book values and a terminal value.
enterprise_value_multiplesBuild enterprise value from market cap, debt, preferred, minority interest and cash, then EV/EBITDA, EV/EBIT, EV/sales, P/E, P/B, earnings yield and FCF yield.
altman_z_scoreCompute the Altman Z-score bankruptcy predictor (public manufacturing, private-firm Z', or non-manufacturing Z'') with its five ratios and zone.
piotroski_f_scoreScore a company's financial strength 0-9 from two years of statements: profitability, leverage and liquidity, and operating efficiency signals, each shown.
beneish_m_scoreCompute the eight-variable Beneish M-score earnings-manipulation screen from two years of statements, with every index; above -1.78 flags likely manipulation.
dupont_analysisDecompose return on equity into margin, asset turnover and leverage (three-step), and into tax burden, interest burden, operating margin, turnover and leverage (five-step).
graham_valuationCompute Benjamin Graham's number (sqrt 22.5 x EPS x book value per share) and his revised growth formula value, with margin of safety against a price.

What a result does not establish

A number from a correct formula on bad inputs is still wrong. Run the data_checks tools on unfamiliar data first. A backtest of one parameter set says little if many were tried: count them, and use strategy_sweep, sleeve_tournament or deflated_sharpe_ratio. A sleeve that survives every correction on one history is still a backtest: forward results are the evidence. Closed-form models (Black-Scholes, Heston, SABR, Kirk) carry their assumptions; the result names the model.

Development

npm ci && npm test

Reference fixtures are regenerated by the Python scripts in scripts/reference/ (each script's docstring gives its exact uv run command). The tests never call Python; they compare against the committed fixtures.

Related

  • canli-validation-mcp: backtest overfitting tests (deflated Sharpe, CSCV/PBO, White's Reality Check, Hansen's SPA) with a trial ledger.
  • canli-backtest-mcp: point-in-time factor backtests from SEC filings.

MIT licence.

From the server's repository — third-party content, read it before running anything it suggests.

More in Other

Listing from the official MCP Registry · repository facts from GitHub, 1h ago.