Single-asset bar-loop backtester with honest next-open fills, an AGPL-3.0 licence, and an indicator API that computes over the entire series before slicing. TRIGGER - from backtesting import Backtest, Strategy; pip install backtesting, bt = Backtest(df, MyStrategy), bt.run(), bt.optimize(), self.I(), self.buy(), self.sell(), self.data.Close, trade_on_close, exclusive_orders, finalize_trades, commission, spread, backtesting.lib crossover, _OutOfMoneyError, "kernc"; wanting a portfolio, a universe or a second instrument inside it. Memory is stale here: it is alive at 0.6.6 (2026-07-22), it is AGPL-3.0-or-later rather than MIT, and trade_on_close fills at data.Close[-2] rather than the current bar's close. SKIP for multi-asset or cross-sectional work and for engine choice generally (backtesting-engines). SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill.
Ships in fin-libraries. 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.
A small, honest bar loop with pessimistic fill logic — and two things people reliably get wrong: the
licence, and what trade_on_close actually does.
| pip / import | pip install backtesting · import backtesting |
| Version | 0.6.6 (2026-07-22) · >=3.9 · pure-Python py3-none-any wheel, no compiler |
| Licence | 🚨 AGPL-3.0-or-later (declared and classified) |
| Status | ✅ Active. 8,931★ kernc/backtesting.py, pushed 2026-08-05. 🚨 Single asset. Full stop |
🚨 Strategy.I computes the indicator over the FULL series in init(), then slices it in
next(). For a causal indicator (SMA, EMA, RSI) that is just an optimisation and is fine. For a
non-causal one it is a silent, total leak:
scipy.signal.filtfilt or any zero-phase filter.shift(-1), .rolling(...).mean().shift(-n), a forward-looking argmaxThe framework cannot detect any of these. No warning, no assertion, no diagnostic — the equity curve simply comes out beautiful.
⚠️ Related residual risk: the loop slices to i+1 before calling next(), so self.data.High[-1], Low[-1] and Close[-1] are all readable inside next(). Market-order timing protects your fills; it does not stop you reading the current bar's high in a signal.
Not MIT, not BSD. AGPL is network copyleft: if you build a hosted service on it — a web app, a Discord bot, an internal dashboard other people hit over a network — you must offer the complete corresponding source of your derived work to its users. Running it privately on your own machine is unaffected; shipping a SaaS on top of it is a licensing decision, not a detail.
For each bar i: data._set_length(i+1) → broker.next() (process the order queue) →
strategy.next() (documented as "next tick, a moment before bar close"). Orders placed inside
next() are processed at the start of the following iteration — that is what makes it causal.
✅ Fills, verified in _process_orders:
price = max(price, stop_price) for longs, min(...) for shorts. A gap straight through your stop fills you at the open, not at the stop — which is what actually happens.commission is folded into the fill price by _adjusted_price — longs marked up, shorts marked down. spread is a separate constant-bps parameter.Where the bar is ambiguous, it resolves against you. That is why this library punches above its size.
trade_on_close=True does not mean "fill at this bar's close"✅ Verified in backtesting/backtesting.py. The fill price is data.Close[-2]:
prev_close = data.Close[-2]
price = prev_close if self._trade_on_close and not order.is_contingent else open
and the fill is timestamped at self._i - 1. Meanwhile the Backtest docstring says market orders
fill "with respect to the current bar's closing price". Both are true in different frames:
broker.next() at iteration i, data is already sliced to i+1, so Close[-1] is bar
i and Close[-2] is bar i-1.strategy.next() of iteration i-1.Consequences: it is effectively a market-on-close fill at the signal bar's close, legitimate only
if you can actually trade that close (an MOC order, an auction). ✅ It applies only to
non-contingent market orders — SL/TP ignore it. Leave it False unless you can name the live
order type that produces the fill.
Multiple assets · volume or liquidity limits · market impact · partial fills · corporate actions ·
borrow · funding · margin beyond a simple margin ratio and an _OutOfMoneyError. An order for a
million shares of a stock that traded 900 shares that bar fills instantly at one price.
from backtesting import Backtest, Strategy
bt = Backtest(
df, MyStrategy,
cash=10_000,
commission=0.002, # folded into the fill price, not charged separately
spread=0.0, # constant bps; the only other cost model that exists
trade_on_close=False, # 🚨 keep False: True fills at Close[-2], an MOC-style fill
exclusive_orders=False,
finalize_trades=True, # else the last open trade stays unrealised
)
stats = bt.run()
# 🚨 bt.optimize(...) reports the grid MAXIMUM. That is not an expectation —
# the grid size is your trial count.
../../../fin-core/skills/backtesting-engines/SKILL.md — engine choice and timing table../../../fin-core/skills/backtesting-engines/references/backtesting-py.md — the source card../../../fin-core/skills/backtesting-engines/references/execution-realism.md — fill realism, ranked../../../fin-core/skills/research-integrity-guards/references/leakage-checklist.md — the portable defence against Strategy.I leaksThis file is the deep dive on one library and assumes the choice is already made.
For which library to pick, how it compares with the alternatives, and the traps that span
several of them, the entry point is the domain skill backtesting-engines (../../../fin-core/skills/backtesting-engines/SKILL.md).
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
24 skills in this plugin
/lib-akshareakshare is the widest free Chinese-market scraper (1,103 public interfaces) and it purges its own PyPI history, so you cannot pin it. TRIGGER - akshare, "import akshare as ak", pip install akshare, stock_zh_a_hist, stock_zh_a_daily, index_stock_cons_csindex, stock_zt_pool_em, stock_zh_a_stop_em, adjust="qfq"/"hfq", 复权, 前复权, 后复权, 涨跌停, 东方财富, 新浪财经, A股数据, 沪深300成分股, "No matching distribution found for akshare==", akshare 报错, akshare 封 IP. akshare ships roughly 2.3 releases a week and deletes the old ones, so any signature, column name or version pin you remember is probably already gone. SKIP for lib-tushare, which is the skill for point-in-time fundamentals and dated index membership. SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill./lib-alpaca-pyAlpaca's current Python SDK, which defaults to the paper host but lets url_override silently send live orders from a client that believes it is in the sandbox. TRIGGER - import alpaca, pip install alpaca-py, TradingClient, StockHistoricalDataClient, CryptoHistoricalDataClient, submit_order, LimitOrderRequest, MarketOrderRequest, OrderSide, TimeInForce, client_order_id, url_override, paper=True, BaseURL.TRADING_PAPER, paper-api.alpaca.markets, bracket OCO OTO orders, trail_percent, IEX vs SIP feed, Algo Trader Plus, alpaca-trade-api, APCA_API_BASE_URL; an order rejected asynchronously for time-in-force or price precision. Memory is stale here: alpaca-trade-api was deprecated in 2024 and defaulted to LIVE, whereas alpaca-py 0.44.0 (2026-08-11) declares paper=True - the widely repeated warning is inverted. SKIP for Interactive Brokers and for the general order-safety patterns (broker-execution-apis). SKIP for choosing between libraries, or when no library is named - the domain skill's job./lib-alphalensalphalens-reloaded scores cross-sectional factors, and its forward return starts at date t's OWN price - it never lags your factor. TRIGGER - alphalens, alphalens-reloaded, "import alphalens as al", get_clean_factor_and_forward_returns, compute_forward_returns, factor_information_coefficient, mean_return_by_quantile, factor_returns, quantile_turnover, factor_rank_autocorrelation, create_full_tear_sheet, MaxLossExceededError, max_loss=0.35, cumulative_returns, information coefficient, IC decay, quantile spread, "pip install alphalens". The original quantopian package is dead at 0.4.0 (2020-04-27) and most snippets you recall target it or its removed pandas internals. SKIP for lib-qlib, which is the skill for the feature pipeline and model. SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill./lib-archThe reference GARCH implementation in Python, and the home of SPA/StepM/MCS - which all take LOSSES, so passing returns silently inverts the test and names your worst strategy as the best. TRIGGER - arch, arch_model, arch.bootstrap, arch.univariate, SPA, RealityCheck, StepM, MCS, optimal_block_length, StationaryBootstrap, superior_models, spa.pvalues, mcs.included, arch.unitroot, GARCH, EGARCH, GJR-GARCH, TARCH, APARCH, FIGARCH, HARCH, HAR-RV, skewt, conditional_volatility, or a GARCH fit emitting convergence warnings. Memory is stale on licence and version - it is 8.0.0 (2025-10-21) under NCSA, not one of the three usual permissive licences. SKIP for PSR and DSR (backtest-validation), for PBO and CPCV (lib-purgedcv) and for reporting Sharpe (lib-quantstats). SKIP for choosing between libraries, or when no library is named - the domain skill's job./lib-ccxtThe unified MIT client for 100+ crypto venues - and not a backtester, with an OHLCV endpoint that silently truncates and returns an unclosed final bar. TRIGGER - import ccxt, import ccxt.pro, import ccxt.async_support, pip install ccxt, fetch_ohlcv, fetchOHLCV, load_markets, fetch_markets, create_order, watchOrderBook, watchTicker, watchMyTrades, set_sandbox_mode, enableRateLimit, amount_to_precision, price_to_precision, exchange.has, options defaultType, parse8601, implicit methods like fapiPrivateGetPositionRisk, CCXT Pro subscription expiry, funding rate history; an order rejected on precision or min-notional, fewer candles returned than requested. Memory is stale here: CCXT Pro was merged into the free MIT package at v1.95, prediction markets landed at 4.5.66, and 4.5.77 shipped 2026-09-01. SKIP for equity and futures brokers (broker-execution-apis). SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill./lib-edgartoolsedgartools is the default free SEC EDGAR client - typed objects for 20+ form types, XBRL statements, no API key - and it 403s on every request until you call set_identity(). TRIGGER - edgartools, "from edgar import Company, set_identity", set_identity, Company("AAPL"), get_filings, filing.xbrl(), get_facts, get_financials, accession number, CIK, ticker-to-CIK, 10-K, 10-Q, 8-K, 13F, Forms 3/4/5, EDGAR full-text search, "HTTP 403" from sec.gov, SEC User-Agent required, SEC 10 requests per second, edgartools MCP server, edgartools[ai]. 442 releases have moved the API repeatedly and the classifier is still Beta, so any snippet recalled from memory is probably wrong for the installed version. SKIP for lib-fredapi, which is the skill for macro series and revisions. SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill./fin-libraries:lib-backtesting-pyfrom fin-libraries
npx claudepluginhub howard-lynn-ye/fin-rsi --plugin fin-libraries