/jquantstats:portfolio-diagnosticsfrom jquantstats
Diagnoses wrong, null or surprising jquantstats results including null propagation, misinferred periods_per_year, lost date axis, benchmark misalignment, or JQuantStatsError. Use when metrics return null/NaN, disagree with QuantStats, or show implausible Sharpe/volatility.
Ships in jquantstats. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Metrics here fail quietly more often than loudly. A wrong number that looks plausible is the failure mode to hunt.
Read ${CLAUDE_PLUGIN_ROOT}/reference/portfolio-context.md, then rebuild and
re-read the digest — it already carries the evidence:
bash "${CLAUDE_PLUGIN_ROOT}/scripts/jqs.sh" jqs_load.py show
bash "${CLAUDE_PLUGIN_ROOT}/scripts/jqs.sh" jqs_load.py check # inputs still match?
check reporting STALE explains a whole class of "the number changed" reports:
the inputs moved after the digest was written. Work through the digest's
warnings, nulls, nans and shape blocks before touching the metric that
was complained about.
Polars keeps null (missing) and NaN (IEEE-754) distinct, and
null_strategy acts on null only. Handling then varies by metric:
aggregations skip nulls, which shrinks the effective sample without saying so,
while cumulative and rolling paths can propagate them.
frame.null_count() # nulls per column
frame.select(pl.col(c).is_nan().sum() for c in numeric) # NaNs are separate
Fix by making the sample explicit at construction:
Data.from_returns(..., null_strategy="drop"). Options are None (default,
pass through), "drop", "forward_fill", "raise". Use "raise" while
debugging — turning a silent failure loud is usually the fastest route. When
reproducing QuantStats numbers, "drop" is what matches pandas.
NullsInReturnsError is the loud version of this, raised where a null cannot be
tolerated at all.
date naming trapThe Portfolio → Data bridge keeps the date column only when it is named
exactly date (lowercase). Under any other name the dates are dropped and
replaced by a positional integer index. Nothing is raised.
The consequences are not cosmetic: periods_per_year falls back to a default
instead of being inferred, so every annualised metric shifts, and date-axis
charts lose their x-axis. On identical data, renaming date → Date moved
Sharpe from 100.33 to 83.36 in testing.
pf.data.index.columns # ['date'] good — ['index'] means the axis was dropped
The plugin's loader normalises Portfolio inputs to date and reports having
done so. If a portfolio was built by hand, check this first.
periods_per_year inferred wronglyAnnualisation of sharpe, sortino and volatility runs off this number.
pf.stats.periods_per_year # what the library will use
The digest also reports periods_per_year_empirical — observations per calendar
year measured from the span. A mismatch means the annualisation is wrong by
roughly its square root: business-daily should land near 252, weekly near 52,
monthly near 12. If the inference is off, pass periods= (or
periods_per_year=, depending on the metric — the two kwarg names are not used
consistently) explicitly rather than accepting the default.
The benchmark is passed once at construction and aligned to the returns.
BenchmarkAlignmentWarning is emitted when that alignment drops rows — do not
suppress it. beta, alpha, r_squared, information_ratio and the capture
ratios then describe only the overlap, which may be much shorter than the
portfolio.
data.benchmark.height, data.returns.height # compare
NoBenchmarkError means a benchmark-dependent statistic was requested on a
context built without one — rebuild with --benchmark, don't work around it.
Same metric name, different convention from QuantStats:
conditional_value_at_risk accepts confidence=0.95 or alpha=0.05, never
both (that raises ValueError); omitting both gives alpha=0.05.value_at_risk takes alpha only — no confidence parameter, on the same
object as its CVaR sibling that has one.information_ratio is raw and non-annualised by default; pass
annualise=True to scale it.volatility annualises by default — and spells it annualize, with a z.The library uses typed domain errors, so the class names the problem:
| Exception | Cause |
|---|---|
MissingDateColumnError | no date column where one is required — check date_col |
InvalidPricesTypeError, InvalidCashPositionTypeError | a pandas object or Series was passed; both must be pl.DataFrame |
RowCountMismatchError | prices and positions have different row counts — align before constructing, don't truncate blindly |
NonPositiveAumError | aum must be strictly positive |
NoAssetColumnsError | no numeric asset columns — usually the date column was not excluded, or everything parsed as string |
PositionExprColumnError | a position expression names columns absent from prices |
NegativeCostBpsError, NegativeAnnualFeeError, InvalidMaxBpsError | invalid cost inputs |
UncleanSeriesError | a derived series hit null or non-finite values — trace back to the input nulls |
NonPositiveWindowError, NonPositivePeriodsPerYearError | invalid rolling window or annualisation factor |
IntegerIndexBoundError | truncate received a non-integer where a row index was expected |
All subclass JQuantStatsError, so except JQuantStatsError catches the domain
set without swallowing real bugs.
When numbers disagree with a QuantStats reference, work in this order — the common cause is upstream of the metric:
null_strategy="drop" to match pandas' silent NaN dropping.periods_per_year matches what the other tool assumed.The repo's own tests/test_jquantstats/test_migration/ validates metrics against
the quantstats reference implementation and is the authority on which
differences are intentional.
bash "${CLAUDE_PLUGIN_ROOT}/scripts/jqs.sh" jqs_api.py --show value_at_risk
bash "${CLAUDE_PLUGIN_ROOT}/scripts/jqs.sh" jqs_api.py --grep sortino
A missing name is usually a QuantStats alias that was never ported (cvar,
ror, upi, r2, ghpr, win_loss_ratio). Report that rather than wrapping it.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub jebel-quant/jquantstats --plugin jquantstats4 skills in this plugin
/portfolio-analysisAnalyse a jquantstats Portfolio or Data object — pick the right metric or chart for the question, and get the call shape right. Use when asked about performance, risk-adjusted returns, drawdowns, benchmark comparison, turnover, trading costs, execution delay, tilt/timing attribution, or for a tearsheet or report from prices, positions or a return series./portfolio-robustnessStress-test a jquantstats result rather than just computing it — is this Sharpe real, does it survive execution delay, trading costs, autocorrelation, outliers, or a different sub-period? Use when asked whether a backtest holds up, how sensitive it is to costs or lag, whether performance is luck, or for Monte Carlo, probabilistic Sharpe, or lead/lag analysis./Other plugins' skills for the same job