Passer au contenu principal
P

dsh-quant

pengpengyi92/dsh-quant

Quantitative R&D toolkit for DeepSeek Harness — 46 tools across six domains covering market data, indicators, factor evaluation, walk-forward ML validation, risk, options, bonds and fund simulation, with an end-to-end research pipeline.

Installer

dsh plugin --profile web add github:pengpengyi92/dsh-quant

README

🐳 dsh-quant — The Everything-Plugin Quant OS

🌐 Site: https://dsh-quant-site.pages.dev · ✅ Listed in awesome-dsh-plugin (one-click install via dsh-market)

npm downloads stars site license ci dsh-plugin

AI-native & DSH-native quant toolkit for every quant aspect — 46 tools · 6 domains (data / alpha / ML / risk / execution / ecosystem) · one end-to-end PDAT→PET research pipeline. Methods open, secrets internal.

🧩 Core Philosophy: Everything is a Plugin (quant edition)

dsh's philosophy is everything is a plugin; dsh-quant brings it to quant — open-sourcing the internal five-team paradigm (PDAT → PAAT → PCPT → PRT → PET) as five pluggable modules:

data plugin   dsh-data      market data / sources / quality  ← plug in Binance or your own data
alpha plugin  dsh-alpha     indicators / factors / eval      ← write your own alpha (internal alpha stays private)
model plugin  dsh-ml        backtests / ML/DL/RL framework   ← train your own models (internal research stays private)
risk plugin   dsh-risk      VaR / drawdown / options / bonds ← set your own risk limits
exec plugin   dsh-execution sim execution / fund / report    ← build your own trading system (paper or live)
  • What's open is the paradigm: how modules compose, how contracts are defined (null alignment / no look-ahead / hand-computed tests), how results are validated — not the internal secrets
  • You fill it in: product power = UI + strategies + data interfaces + DL/RL models + trading-system building, all self-assembled, all pluginized
  • Infinite self-evolution: fill the framework with your modules → run paper/live → feed the ecosystem back — that's dsh-quant

Plugin call for proposals: Issue #27 (five modules × many plugins) — PDAT plugins, PET plugins, anything you can imagine 🐋

🤖 AI-Native Is Deliberate (design statement)

dsh-quant's primary consumer is the agent (the model), not the human — a deliberate choice from day one:

  • Tool schemas are injected into the system prompt — every contract (args / outputs / alignment rules) is written from the model's perspective
  • Equal-length null alignment — outputs match input length; leading window positions are null, so the model aligns by index and never pads
  • Canonical JSON + render separation — machines read structure, humans read prose
  • All isConcurrencySafe — pure functions, no shared state; agents can call all 46 tools in parallel without interference
  • Skill layerskill/quant-research lets the model load the workflow itself

Full statement: Issue #14 "AI-native is deliberate".

🐍 Why Almost No Python?

A common question: a quant project without .py files? Answer: 0 Python files, 21 TypeScript source files, zero runtime dependencies — deliberate:

  • dsh-quant is a dsh plugin running inside the harness's Node runtime: same process as the agent, composable by the Loader, reversible registration (HMR-safe) — TypeScript is the only natural choice
  • Where Python is needed (akshare / tushare / baostock), use the channel knowledge base (quant_data_guide, 15 channels): dsh ships shell / subprocess capabilities, so the agent decides whether to spawn Python — dsh-quant carries no runtime
  • All numerical methods (indicators / backtests / options / bonds) are pure functions with hand-computed baselines: zero deps, offline-verifiable, npm test green anywhere

One goal: build the most usable AI-native quant repo 🐋

46 quant_* tools · 6 domains · 174 unit tests · zero runtime deps. Full positioning: pinned Issue #9.

🤖 For visiting agents

Agents landing on this repo: start at AGENTS.md (root-level, auto-read by Copilot / Claude Code / dsh), then the closed-loop example plugin/CASE_STUDY.md or Discussion #38, and the one-glance contract mcp/AGENT_GUIDE.md.

Quick Install (dsh users)

npm i dsh-quant

Add one line to your cordis.yml:

- name: 'dsh-quant'

46 tools auto-register — indicators / backtests / factors / risk / fund simulation / ecosystem metrics out of the box. One quant_research_pipeline runs the whole PDAT→PET chain. ML/DL knowledge: docs/ML_GUIDE.md; executable demo: npx tsx demos/ml-workflow.ts.

🚀 Product Experience: Three Minutes to a Full Quant Pipeline

Right after install, experience the complete PDAT→PET flow (BTC public data + simple strategy + backtest + paper trading):

data(quant_market_fetch) → quality(quant_data_quality) → factors(quant_factor_evaluate)
→ backtest(quant_backtest) → metrics(quant_metrics) → risk(quant_risk)
→ drawdown(quant_drawdown) → paper sim(quant_execute_sim) → fund sim(quant_fund)
→ report(quant_report)

One-liner: quant_research_pipeline(symbol=BTCUSDT, limit=120) returns everything in one call.

Then plug your own plugins into each module (data sources / alpha / models / risk / execution — everything is a plugin, proposals at Issue #27).

Five-step walkthrough with commentary: docs/ONBOARDING.md · Agent one-glance guide: mcp/AGENT_GUIDE.md

🖥️ UI Workbench (dsh-quant-ui)

dsh-quant UI

dsh-quant-ui: candlesticks + MA overlays + trade markers, equity curves, fund NAV / management-fee / performance-fee cards, metric selector — plus a swimming chibi whale 🐋 (click the title 3 times).

Live demo: https://dsh-quant-ui.pages.dev

Tools

ToolParametersCanonical outputFirst valid index
quant_data_comparedataType (e.g. "financials"/"daily bars"){ dataType, channels: [{ name, cost, covers, bestFor }] } (covering first)
quant_data_advicedataType + budget (free/low/institutional) + purpose (research/backtest/official){ recommendations: [{ rank, name, reason }] } (decision-tree ranked)
quant_series_statsvalues: number[]{ count, mean, std, min, max, median, skew, kurtosis, autocorr1, annualizedVol, totalReturnPct }— (first step after fetching)
quant_var_backtestreturns + varSeries + confidence=0.95{ failures, expected, lrStat, pValue, passed, periods } (Kupiec POF test)— (the ground truth for VaR models)
quant_optionspot + strike + timeToMaturity + riskFreeRate + type + exactly one of volatility/price{ price, impliedVolatility, delta, gamma, vega, theta, rho, … }— (Optiver-inspired: BS pricing + five greeks + IV solve)
quant_volatilityclose: number[] + annualization=252{ annualized, perPeriod, n, logReturns(aligned) }— (realized vol; the RV-vs-IV research entry)
quant_bondcouponRate + periodsToMaturity + paymentsPerYear? + exactly one of ytm/price{ price, yieldToMaturity, macaulayDuration, modifiedDuration, convexity, dv01, … }— (FICC link: pricing/duration/convexity/DV01, textbook discounting)
quant_drawdownequity: number[]{ underwater(aligned), maxDrawdownPct, currentDrawdownPct, periods(peak/trough/recovery/depth/duration), ongoing }— (drawdown episode analysis)
quant_resamplecandles + period (week=7 bars/month=30 bars){ candles } (OHLCV aggregation, 24/7 markets)
quant_reportstrategy/metrics/risk/factor/fund (module outputs){ report } (Markdown research report)— (R&D conclusion assembly)
quant_repo_statsowner + repo{ stars, forks, watchers, openIssues, openPullRequests, topics, latestRelease, … } (public GitHub API, no credentials)— (ecosystem data)
quant_npm_statspkg{ latest, weeklyDownloads, monthlyDownloads, description, … } (npm registry + downloads API)— (ecosystem data)
quant_oss_pulsestars + downloadsWeekly? + starsPrevious? + openIssues? + openPullRequests? + daysSinceRelease?{ score(0-100), grade(A-D), components, suggestions, summary }— (open-source influence score; missing inputs score neutral 50)
quant_riskreturns (decimal series) + benchmarkReturns? + confidence=0.95{ var95, cvar95, downsideDeviation, maxDrawdownPct, beta, alpha, informationRatio, trackingError, periods }— (core risk module)
quant_fundequityCurve + initialCapital=1e8 + managementFeeRate=0.02 + performanceFeeRate=0.2{ initialCapital, finalNavNet, finalAum, peakNav, peakAum, gross/netReturnPct, fees, navNet }— (quant hedge-fund sim: NAV 1.00 start, daily mgmt fee, 20% high-water-mark performance fee)
quant_metricsequityCurve + trades?{ totalReturnPct, maxDrawdownPct, sharpe, annualizedVol, calmar, sortino, winRate, profitFactor, avgPeriodReturnPct, tradeMetrics } (required trio: return/drawdown/sharpe)— (METRIC_CATALOG for UI pickers)
quant_chartkind (candles/series/annotations) + matching datastructured chart data (dsh-chart protocol: candles+overlays+markers / multi-series / annotation views)— (UI-route data plane)
quant_execute_simclose + orders[{index, side, quantity?/valueFraction?}] + initialCash? + feeRate? + slippageBps? + latencyBars?{ fills, equityCurve, finalEquity, totalReturnPct, totalFee, totalSlippageCost, tradeCount, unfilledCount, cash, position }— (execution framework, no live trading)
quant_research_pipelinesymbol? + interval? + limit? + provider? + candles? + strategy/fund params{ candles, quality, stats, metrics, risk, drawdown, fund, factor, report, charts }— (one-call PDAT→PET research)
quant_factor_evaluatefactorValues + forwardReturns (factor[i] predicts ret[i+1]) + quantiles=5 + window=20 + decayHorizons=5{ ic, rankIc, icDecay, icir, icSeries, quantileReturns, longShort, turnover, autocorr1, n } (alphalens set + RankIC/IC decay)
quant_factor_neutralizefactorValues + groups? + styleFactors? + method?{ values(standardized), method, groupCount, styleCount, rSquared }— (group z-score / OLS residual neutralization)
quant_walk_forwardreturns + features[][] + trainWindow + testWindow + step?{ predictions(null-aligned), oosIc, oosRankIc, oosCount, windows, trainR2Mean }— (rolling train / out-of-sample, no look-ahead)
quant_linear_modelX(samples×features) + y + lambda? + predictX? + yTest?{ intercept, weights, lambda, trainR2, n, predictions?, testR2?, testIc? }— (standalone OLS/Ridge fit & predict)
quant_factor_combinefactors: number[][] (equal length) + weights?{ signal(rank 0..1), effectiveWeights, factorCount }— (z-score weighting + cross-sectional ranking)
quant_series_qualityvalues: number[], jumpThreshold=0.2{ count, missingCount, zOutliers, jumps, longestConstantRun, healthy }— (series-level quality)
quant_data_annotatevalues: number[], jumpThreshold=0.2{ count, annotations: [{index, label, severity, detail}], summary }— (point-level labeling, a tribute to Scale AI)
quant_data_qualitycandles (quant_market_fetch output){ count, highBelowLow, nonPositive, timeNotIncreasing, timeGaps, extremeMoves, healthy }— (pre-analysis health check)
quant_data_guidequery (channel name/data type, e.g. "tushare"/"financials") or channel (exact name){ query, results: [{ name, url, cost, dataTypes, setup, tutorialUrls, bestFor, … }] }— (built-in 15-channel data knowledge base: A-shares/US/bonds + dsh ecosystem data plugins)
quant_market_fetchsymbol: string (e.g. BTCUSDT / sh600000 / AAPL), interval: 1m…1M, limit: 1-1000, provider: binance/okx/bybit/sina/tencent/yahoo{ symbol, interval, provider, candles: [{openTime, open, high, low, close, volume}] }
quant_smavalues: number[], window: integer{ values: (number|null)[], window }index window-1
quant_emavalues: number[], window: integer{ values: (number|null)[], window }index window-1 (seed = first-window mean, alpha = 2/(w+1))
quant_rsivalues: number[], window: integer = 14{ values: (number|null)[], window }index window (Wilder smoothing)
quant_macdvalues: number[], fast=12, slow=26, signal=9{ macd, signal, histogram } (equal length)macd: slow-1; signal/histogram: slow+signal-2
quant_bollingervalues: number[], window=20, multiplier=2{ upper, middle, lower, window, multiplier }index window-1 (population std)
quant_atrhigh/low/close: number[], window=14{ values: (number|null)[], window }index window (Wilder smoothing)
quant_kdjhigh/low/close: number[], window=9{ k, d, j } (equal length)index window-1 (RSV method, K/D seeded at 50)
quant_williams_rhigh/low/close: number[], window=14{ values: (number|null)[], window }index window-1 (range -100..0)
quant_ccihigh/low/close: number[], window=20{ values: (number|null)[], window }index window-1 (±100 overbought/oversold)
quant_obvclose/volume: number[]{ values: number[] }everywhere (first value 0, no nulls)
quant_adxhigh/low/close: number[], window=14{ adx, plusDi, minusDi, window }±DI: index window; ADX: index 2*window-1
quant_rocvalues: number[], window=12{ values: (number|null)[], window }index window
quant_backtestclose: number[], fast=10, slow=30, feeRate=0.001, stopLoss?, takeProfit?{ totalReturnPct, maxDrawdownPct, sharpe, position, equityCurve, trades(with exitReason) }first trade one bar after first confirmed cross
quant_backtest_bollingerclose: number[], window=20, multiplier=2, feeRate=0.001, stopLoss?, takeProfit?same (buy on upper-band breakout, sell on mid-band cross-down)one bar after first confirmed breakout
quant_backtest_rsiclose: number[], rsiWindow=14, buyBelow=30, sellAbove=70, feeRate=0.001, stopLoss?, takeProfit?same (buy on RSI cross-up through buyBelow, sell on cross-down through sellAbove)one bar after first confirmed signal
quant_backtest_portfolioassets: [{name, close}], weights?, rebalanceEvery?, feeRate=0.001{ totalReturnPct, maxDrawdownPct, sharpe, equityCurve, assetNames, finalWeights, rebalances }— (multi-asset portfolio)
quant_backtest_gridclose: number[], fastMin=3, fastMax=10, slowMin=10, slowMax=30, feeRate=0.001{ results(sorted by return desc), best, fastRange, slowRange, feeRate }— (grid search; skips fast >= slow)

Typical chain (model's view)

quant_market_fetch(symbol: BTCUSDT, interval: 1d, limit: 100)
  → take close → quant_sma / quant_ema / quant_rsi / quant_macd / … → quant_backtest

Verified live: real Binance daily bars → indicators → backtest (fast 5 / slow 20) end to end.

Backtest contract

  • Dual-MA crossover: buy all-in when fast SMA crosses above slow SMA, liquidate when it crosses below; signals confirm on bar i and fill at bar i+1 close (no look-ahead).
  • Fees are charged on both sides of notional (feeRate per side).
  • Open tail position: the last trade's exitIndex/exitPrice/returnPct are null.
  • position and equityCurve match input length; equity is normalized (starts at 1); Sharpe is annualized assuming daily frequency (√365).

Alignment conventions

  • All outputs are equal-length with inputs; leading unwindowed positions are null — the model aligns by index, no padding needed.
  • Empty series or window > series length is a legal result (all null), not an error.
  • Non-finite numbers (NaN/Infinity) are rejected at the registry's lossless-JSON argument snapshot layer (the model's JSON boundary) and never reach execute.
  • Constraints (window ≥ 1 integer, macd fast < slow, atr arrays equal length, multiplier > 0) are hand-checked in execute; thrown errors become isError results via the registry.

Contract (defineTool)

  • Arguments use the unified schema DSL, validated by defineTool before execute (types / required / integers).
  • execute returns only the canonical JSON value; output.render produces the model-facing prose.
  • Every tool is isConcurrencySafe: true — pure functions, no shared state, no side effects, parallel-schedulable.
  • Registration is a reversible effect: ctx.tools.register returns a disposer; fiber disposal unregisters.

Model Experience

What the model sees

Each tool's name/description/JSON schema is injected into the system-prompt assembly (ctx.systemPrompt.tools()). Descriptions state the alignment rules (which head positions are null), so the model never guesses.

Token impact

Each tool costs one fixed schema block; call results are charged by rendered content. The null-alignment design avoids repeated padding requests from the model.

KV cache impact

The schema prefix is stable (reused as long as the tool set and order are unchanged); results append after the reusable prefix.

Release history (NEWS)

VersionDateNotes
0.35.02026-08-17Core UX: PDAT→PET onboarding (BTC example) + mcp/AGENT_GUIDE
0.34.02026-08-17Quant lineage report (five motherships)
0.33.02026-08-17Macro legends batch (42 firms) + first data analysis report
0.32.02026-08-17Systematic Europe batch (37 firms)
0.31.02026-08-17Market-making & crypto batch incl. Alameda failure case (32 firms)
0.30.02026-08-17QRT/Capula/Winton/DRW/Tower batch (27 firms)
0.29.02026-08-17SIG + quant chronicle timeline (22 firms)
0.28.02026-08-17Balyasny/IMC/XTX/Five Rings + DE Shaw boost (21 firms)
0.27.02026-08-17Man Group/AQR/GSA/Bridgewater batch (17 firms)
0.26.02026-08-17Two Sigma/Virtu/DE Shaw/Renaissance batch (13 firms)
0.25.02026-08-17HRT/Point72/Squarepoint batch (9 firms)
0.24.02026-08-17Millennium/WorldQuant/Jump batch (6 firms)
0.23.02026-08-17quant-history + quant-repo columns (Citadel/Optiver/Jane Street)
0.22.02026-08-17Options & volatility board (Optiver-inspired)
0.21.02026-08-17FICC link: quant_bond + bond data channels
0.20.02026-08-16yahoo US/global klines + 13-channel guide + researchMultiAsset
0.19.02026-08-16quant_linear_model + docs/ML_GUIDE + ml-workflow demo
0.18.02026-08-16Chain completion: A-share klines, RankIC/IC decay, neutralization, walk-forward, drawdown, execution sim, pipeline
0.17.02026-08-16dsh-community domain: quant_repo_stats / quant_npm_stats / quant_oss_pulse
0.16.02026-08-16Domain-driven layout ↔ PDAT/PAAT/PCPT/PRT/PET + exchange fallback chain
0.15.02026-08-16Kupiec VaR backtest + resample + report; 100 unit tests milestone
0.14.02026-08-16quant_risk (VaR/CVaR/Beta/Alpha/IR/TE)
0.13.02026-08-16quant_fund (1e8 capital, NAV 1.00, HWM 20% fee) + UI fund cards
0.12.02026-08-16quant_metrics (9+ metrics) + Jane Street-style UI demo
0.11.02026-08-16quant_chart (dsh-chart protocol)
0.10.02026-08-16quant_factor_evaluate / combine (alphalens methodology)
0.9.02026-08-16series stats + data quality + annotation (tribute to Scale AI)
0.8.02026-08-16channel compare + decision-tree advice
0.7.02026-08-16mcp/tools.json + pure-function re-exports + docs
0.6.02026-08-16data channel guide (8 A-share channels) + rename to dsh-quant
0.5.02026-08-16multi-exchange sources (OKX / Bybit)
0.4.02026-08-16multi-asset portfolio backtest (periodic rebalancing)
0.3.02026-08-16strategy family (Bollinger breakout / RSI reversion) + stop-loss/take-profit
0.2.02026-08-16+6 indicators (KDJ / W%R / CCI / OBV / ADX / ROC)
0.1.02026-08-16Launch: market data + 6 indicators + MA backtest/grid + CI/auto-release

Full records: NEWS.md and CHANGELOG.md.

Known limitations & roadmap

  • Market coverage is crypto-first: Binance / OKX / Bybit public APIs (automatic fallback), no credentials; A-shares go through the channel knowledge base (akshare et al. as future providers).
  • Backtests are a built-in strategy family: dual-MA / Bollinger breakout / RSI reversion / portfolio rebalancing / grid search; custom strategy callbacks are the future route.
  • presentCall/presentResult not customized: indicator results have no file / terminal / diff semantics; UI falls back to generic cards.
  • Market tools need network: live cases live in verify.ts; offline indicator / backtest cases are unaffected.

Domain layout (PDAT→PET pipeline mapping)

src/dsh-data/       data (PDAT): 3 exchanges, 15 channels, quality/annotation, resample
src/dsh-alpha/      alpha (PAAT): 12 indicators + factor eval/combine (alphalens methodology)
src/dsh-ml/         portfolio (PCPT): strategy backtests + portfolio + metric catalog
src/dsh-risk/       risk (PRT): VaR/CVaR/Beta/Alpha/IR + Kupiec test + options + bonds
src/dsh-execution/  delivery (PET): chart data plane, fund sim, research report (no live trading)
src/dsh-community/  ecosystem (unique to the open side): GitHub/npm data + influence pulse

The boundary: data and conclusions stay internal; tools and methods ship to dsh-quant — no alpha, no production strategies, no live-trading engineering, but frameworks, indicators, factor evaluation, UI and demos. See pinned Issue #9.

Quick start (after fork/pull)

npm ci && npm run build && npm test    # offline full tests (174 unit + 4 Loader)
npm run test:verify                    # live market integration (needs network)
npm run gen:tools                      # regenerate mcp/tools.json

Build & use

# build lib/ (tsc, NodeNext ESM; ships .js + .d.ts)
cd quant-indicators && tsc -p tsconfig.json

# use in dsh: add one line to cordis.yml
# - name: 'dsh-quant'
# (the Loader resolves the package exports → lib/index.js from node_modules)

Verification

# pure-function numeric correctness + market parsing + backtests (174 cases, node:test, zero deps)
cd deepseek-harness && pnpm exec tsx --test ../quant-indicators/tests/*.spec.ts

# REAL-composition: cordis.yml booted through the real Loader (registration visible / pipeline / isError / HMR-safety)
cd deepseek-harness && pnpm exec tsx --test ../quant-indicators/tests/loader-composition.spec.ts

# harness integration (schemas → execution pipeline → isError → live fetch→indicators→backtest end-to-end)
cd deepseek-harness && pnpm exec tsx ../quant-indicators/verify.ts

# consumer simulation: built lib loaded through real node_modules resolution (simulates post-install)
cd deepseek-harness && pnpm exec tsx ../quant-indicators/consumer-test/boot.ts

⭐ Support

If dsh-quant helps your research, a ⭐ makes the project visible to more dsh users.

dsh whale trading on a holographic screen

This whale stands for DeepSeek Harness (dsh) — trading on its holographic screen 🐋

Issues / PRs / discussions welcome; share your domain perspective in Discussion #10. 🐋

Ecosystem infrastructure: quant ecosystem directory · ecosystem playbook · ecosystem map Discussion #11

Research columns: quant-history (firm archives) · quant-repo (open-source special)

Plugin library (five slots × external repos & MCPs): plugin/

Plugins associés