Introduction¶
In DSH (DeepSeek Harness), letting an agent analyze a stock usually only yields a qualitative description. To know “how high the probability of rising in the next N days is,” “what state the current trend is in,” or “how high the holding risk is,” one either has to open a quantitative script themselves or switch back to market software to manually monitor indicators.
dsh-bayes-predict turns this into a DSH plugin: using the Bayes theorem as the core, it fuses multiple technical indicators into a posterior probability estimate for “future N-day rise,” and outputs the results directly through two entry points: the chat interface and the browser panel. Below is an introduction to its positioning, core features, and installation usage.
What is it¶
dsh-bayes-predict is a DSH stock prediction plugin based on the Bayes theorem, covering A-shares and US stocks, providing three types of outputs: rise probability estimation based on multi-indicator signal fusion, trend state recognition, and holding risk measurement. Maintainer is pg527322814, license MIT.
It is necessary to clarify platform dependencies first: the plugin depends on the DSH host environment (e.g., dsh web, the cordis plugin system, window.__ModuleLoader__, etc.). This platform is not publicly released with the repository; cloning the repository separately will not allow direct execution. The code is provided for learning, reference, and porting.
Core Features¶
Multi-Indicator Signal Fusion Scoring¶
For the scoring, assuming Hypothesis H is “Future N-day Rise,” the process is as follows:
- The prior is taken as the weighted historical win rate, shrunk towards 0.5;
- Signals such as MACD golden cross, RSI, moving average arrangement, Bollinger Band position, volume, momentum, and the recent 5-day trend are used as evidence;
- For each signal, calculate the bidirectional empirical likelihood ratio (LR_bull for bullish signals, LR_bear for bearish signals), applying time decay weighting and sample shrinkage;
- Perform Bayesian update via odds multiplication, outputting the posterior rise probability (including 95% confidence interval), 0-100 score, and rating.
To reduce bias caused by insufficient single-stock samples, the plugin enables a hierarchical prior: upon startup, it loads a general market LR table from market-prior.json. It mixes the single-stock LR with this, with a weight of w = n/(n+80).
Multi-Window Comparison and Trend State Recognition¶
- Multi-window comparison: Simultaneously outputs a comparison table of posterior probabilities for 2/5/10/20 days;
- Trend state: Performs three-state classification in the style of Bayesian t-tests, outputting P(rise), P(fall), and P(consolidation). The threshold δ = max(0.5·SE, annualized 5% economic equivalent) is used to avoid misjudging tiny trends as clear directions when dealing with large samples.
Position Risk Estimation and Signal Attribution¶
- Volatility is calculated using EWMA (RiskMetrics λ=0.94);
- VaR/CVaR are primarily output using empirical quantiles, with normal estimation as a control, and historical maximum drawdown is also attached;
- Signal attribution outputs the top 3 signals by absolute contribution value, explaining “why it is bullish/bearish.”
Host Side and Browser Side¶
The plugin has a dual-face structure, with entry points on both sides:
- Host side: Registers the
bayes_stock_predictglobal tool, with aGET /bayes-predict/analyzeroute, capable of generating markdown reports; - Browser side: A React visualization panel, mounted under the sidebar entry “📊 Bayesian Stock Analysis,” with the dashboard and trend charts drawn using SVG.
Market Data Acquisition and Data Safeguarding¶
Data sources are free and do not require a key:
- Code normalization: Formats like
600519,sh600519,000001,AAPLare all recognized; - A-share daily K-lines: Use Tencent fqkline adjusted forward (hfq) (max ~700 candles, auto-switches between primary/secondary domains, with Eastmoney adjusted forward as a fallback); US stock daily K-lines use Sina full history;
- Real-time snapshots: A-shares use Tencent, US stocks use the Tencent
usprefix; - In-memory TTL cache: 30 minutes.
Regarding the rolling baseline issue of Tencent adjusted forward data, fetchKlines includes gap protection: if the last day of hfq has |daily change| > 8%, it pulls the unadjusted sequence for verification. If deemed a gap, the last day is discarded (preferring missing data to erroneous data).
Note on data definition: Scoring and single-stock analysis both use adjusted forward (hfq). The return sequence includes dividend reinvestment and is clean, but the price is not the real stock price; if real price data is required, use unadjusted data.
Installation and Enablement¶
There is no command of the form dsh plugin add for installation; manual copying of the plugin package and configuration modification are required, totaling three steps.
-
Copy the plugin package to
%USERPROFILE%\.dsh\profiles\web\node_modules\dsh-bayes-predict(create the directory if it doesn’t exist; the profile’s baseUrl is anchored atprofiles\web, and node resolution will look upward fornode_modules). -
Append to
%USERPROFILE%\.dsh\profiles\web\cordis.patch.yml:
- insert:
- id: bayes-predict
name: 'dsh-bayes-predict'
- Restart
dsh web. Plugin set changes take effect after a restart; client bundle HMR is only available when rebuilding viapnpm run dev:web.
If you want to modify the client code yourself, note a contract: The factory in lib/client.js must export an inject array (e.g., exports.inject = ["slots"]). If missing, accessing ctx.slots inside apply(ctx) will directly throw cannot get property "slots" without inject.
The project has zero third-party dependencies and requires Node 18+; npm test will run test/smoke.mjs (Bayesian core + synthetic K-line end-to-end) and test/normalize.test.mjs (code normalization unit tests).
Typical Usage¶
Chat interface method (open a new session after restarting so the agent sees the new tool):
分析一下 600519
用贝叶斯方法评估一下 300750 未来 5 天的上涨概率
Visualization panel method: Click the shortcut button “📊 Bayesian Stock Analysis” at the bottom of the sidebar, enter the code in the centered panel that pops up, and click “Bayesian Analysis”.
Suitable Scenarios and Precautions¶
Suitable for two types of people: those using dsh web who want the agent to directly provide structured probability conclusions and risk metrics; and those who want to reference the Bayesian implementation of “bidirectional LR 2x2 table + time decay + hierarchical prior.” The code structure is clear (bayes.js core calculation, market.js market data, client.js panel), making it easy to port.
Before use, there are a few points you must know:
- The plugin runs with the permissions of the current dsh process and requires manual placement in
node_modulesand modification ofcordis.patch.yml; it is recommended to check the source code and license before installation (this project is MIT); - All outputs are generated by the Bayesian statistical model based on historical market data and are for reference only and do not constitute investment advice;
- Uninstallation requires three steps: delete the
bayes-predictinsert line incordis.patch.yml, deletenode_modules\dsh-bayes-predict, and restartdsh web.
Conclusion¶
The value of dsh-bayes-predict lies in encapsulating a complete Bayesian scoring process (signals → likelihood ratios → posterior probabilities → risk metrics) into a DSH plugin, allowing quantitative conclusions like “rise probability” to be directly obtained in the chat and panel, without relying on any paid data sources.
- GitHub: https://github.com/pg527322814/dsh-bayes-predict
- Plugin Directory: https://www.skillhub.cn/plugins/pg527322814/dsh-bayes-predict