SuperAPI AI Directory

a-share-strategy-mainboard-multi-swing-defensive

General & other

View repository

Updated 10-16 08:08

About this skill

Main Board Multi-Swing Defensive · Decision Signals

This skill's core does three things:Stock selection scope、Buy-side signals、Sell-side signals; and optionally uses realtime_quotes.py to batch-fetch for specified codescurrent-price-type snapshots(based on MarketDataProvider.get_quote, Tencent quotes + minute K aggregation). The output isdecision reference(structured list or JSON),does not includehistorical backtest matching,does not includeautomatic order placement; for real orders, please use a broker or separately connect execution channels such as a-share-paper-trading etc. The strategy signal is positioned asconditionally valid: under changes in market structure and trading costs, signal strength may decay and requires continuous review.

Capability boundaries

Does Does not do
Take the top N from main board high-liquidity stocks to form the day's stock pool Minute-level backtesting, hybrid backtesting, return curves
Use daily line trend_pullback to mark entry/exit conditions Guarantee returns or replace investment advisory
Provide two types of "buy reference" lists (see below) Place orders directly to exchanges or paper trading services
Optional: read a holdings list file and mark "strategy exit" targets Save live positions for you (unless you create your own file)
Batch-fetch current prices, change percentages, limit-up/limit-down reference prices, etc. for multiple stocks (realtime_quotes.py) Replace a-share-data 's heavy interfaces such as full-market real-time sectors and capital flows

Strategy logic (and parameters)

Default parameters are in scripts/strategy_lab/strategy_params.py(moving average fast/slow, pullback magnitude, RSI range and exit RSI, etc.). Signal calculation is in scripts/strategy_lab/strategies.py 's trend_pullback. The script additionally applies two layers of filtering:

  • Cost filter: estimate round-trip cost by --roundtrip-cost-bps , and only candidates with edge_after_cost > 0 enter the final buy list.
  • Robustness filter: calculate within the ROBUSTNESS_PARAM_GRID parameter neighborhood entry_consensus_ratio, and candidates below --entry-consensus-min will be filtered out.

Buy reference (two groups, please distinguish the semantics):

  • from_previous_day_close: the previous closed daily line satisfies entry. Consistent with the habit of "signal after the previous day's close, execute the next day",closer to an ex-ante plan。
  • from_last_close: the latest daily line also satisfies entry, leaning towardpattern display; if it duplicates the previous day, please avoid double counting.

Within the list, sort by the strategy's score(moving average strength) descending; by defaulteach buy list retains at most 5 stocks(strategy_params.MAX_BUY_CANDIDATES), consistent with "positions to watch simultaneously should not be too many". When more or all are needed, add --max-buys 0 to indicate no truncation, or --max-buys 10 etc.

Sell reference: For --holdings For the codes in the file, ifthe latest daily barsatisfies exit(conditions within the rules such as breaking below the slow line or RSI being too high), then it is included as a sell reference. File format: one code per line, comment lines allowed (starting with# ).

Risk control reference (documentation and JSON fields only): REFERENCE_INTRADAY_STOP_PCT represents theintraday stop-loss ratio referencehistorically consistent with the strategy document; this scriptdoes notmonitor intraday stop-loss for you, and you need to set it yourself in your order placement software.

Environment and dependencies

pip install akshare pandas numpy requests

Run

SKILL_DIR="<本 skill 绝对路径>"
python3 "$SKILL_DIR/scripts/daily_decisions.py" --json

Common parameters:

  • --top-n: stock pool size, default 120
  • --max-buys: maximum number of entries to keep on the buy side after sorting, default 5; pass 0 for no truncation
  • --holdings: path to the holdings code file
  • --workers: concurrency for fetching daily bars
  • --json: output a JSON file for program consumption (the JSON contains the pre-truncation count *_total)
  • --roundtrip-cost-bps: round-trip transaction cost estimate (in bps), default 45
  • --entry-consensus-min: parameter-neighborhood entry consistency threshold, default 0.67
  • --disable-robust-check: disable parameter-neighborhood consistency filtering (use only when debugging)

Example:

python3 "$SKILL_DIR/scripts/daily_decisions.py" --top-n 120 --holdings "$HOME/my_holdings.txt"

The JSON output will contain both the raw candidates and the filtered candidates:

  • from_previous_day_close_raw / from_last_close_raw: raw candidates that satisfy the signal only
  • from_previous_day_close / from_last_close: candidates after cost and robustness filtering
  • Each candidate is accompanied by entry_consensus_ratio、edge_after_cost、cost_filter_passed、consensus_filter_passed
  • todo_confirm_items: record items for the currently adopted conventions (roundtrip=45bps, consensus=0.67, RSI interval offset)

Real-time quote snapshot (enhanced)

Fora known code listfetch quotes in batch (concurrently), which can be used together with the codes output by daily_decisions :

python3 "$SKILL_DIR/scripts/realtime_quotes.py" 600519 000001 601318 --json
python3 "$SKILL_DIR/scripts/realtime_quotes.py" -f "$HOME/my_holdings.txt" --workers 10
  • --json: output unified JSON (including quotes and per-entry details)
  • --intraday: additionally fetchthe lastminute K (--intraday-freq default 5m), to facilitate checking and time alignment with the daily snapshot
  • Data comes from paper_trading/market_data.py: compared with full-market depth quotes, it is alightweight snapshot, and intraday prices update with the latest minute K

Script layout

Path Purpose
scripts/daily_decisions.py Entry point: fetch pool, compute signals, print or --json
scripts/realtime_quotes.py batch current price snapshot, optionally with the last minute K
scripts/paper_trading/market_data.py Quotes and get_mainboard_universe
scripts/strategy_lab/strategies.py trend_pullback
scripts/strategy_lab/indicators.py moving averages, RSI
scripts/strategy_lab/strategy_params.py default parameters and strategy name

Integration with the execution layer

If you want to put signals into a simulated trading account, you can use in combination within the Agent a-share-paper-trading: first read this skill's output, then call the simulated trading CLI or HTTP API to place orders; this skill does notdepend on the simulated trading process.