Back to skills
extension
Category: Data & AnalyticsAPI key required

融聚汇FIU 回测策略分析

One-command local Python strategy backtesting with FIU (融聚汇) daily market data for US, HK, CN, and JP stocks and indexes. Use when a user asks to backtest, 定投, replay a trading rule (MA crossover, grid, RSI, trailing stop, rebalance), inspect saved strategies, or compare historical runs; do not use for forecasting, suitability advice, order placement, or guaranteed returns.

personAuthor: user_80d9df51hubcommunity

FIU (融聚汇) Strategy Backtest

Turn the user's historical trading rule into a local Python strategy, fetch market evidence from FIU MCP automatically, run the deterministic runtime with real microstructure rules, and produce an archived run with an interactive HTML report and a dense Markdown brief — all in one command.

Architecture boundary

  • FIU MCP is a market-data source. Its fixed URL is https://ai.szfiu.com/api/mcp/v2/.
  • The bundled Python runtime is the numeric replay authority. Do not calculate trades, returns, quantities, or drawdowns in prose.
  • Credentials resolve from FIU_MCP_AUTH env or a .mcp.json found upward from the working directory — never asked from the user, never stored in requests, strategies, or reports (token_persisted: false is part of the result audit metadata).
  • Keep all user strategy source, cached data, requests, and results in the user's project workspace. The Skill installation directory is read-only reusable tooling.

One-command workflow (preferred)

py <skill>/scripts/run_strategy_backtest.py `
  --symbol 00700.hk --strategy ma_crossover.py `
  --start-date 2023-01-01 --end-date 2026-08-26 `
  --initial-cash 500000 --params '{"fast_period": 10, "slow_period": 30}' `
  --benchmark 000300.sh --workspace <project>

The pipeline runs: workspace init → request build (market/currency/fees inferred, catalog defaults merged) → concurrent cursor-paginated evidence collection (daily bars + dividends/splits + dual price channel) → backtest execution → archive → HTML + Markdown report rendering. Prior evidence with the same symbols and date range is reused; pass --force-refresh to re-collect. Portfolio runs pass --symbols AAPL.us,MSFT.us with a PortfolioStrategy preset (e.g. rebalance.py).

Manual steps (debugging / offline)

py <skill>/scripts/init_workspace.py --workspace <project>
py <skill>/scripts/build_backtest_request.py --symbol 00700.hk --strategy dca.py --start-date 2024-01-01 --end-date 2026-08-26 --initial-cash 100000 --strategy-params '{"monthly_amount": 5000}' --output <project>/requests/hstech_dca.json
py <skill>/scripts/collect_backtest_evidence.py --symbols 00700.hk --start-date 2024-01-01 --end-date 2026-08-26 --output-dir <project>/data
py <skill>/scripts/run_backtest.py --workspace <project> --strategy strategies/dca.py --request <request.json> --bars <bars.json> --corporate-actions <actions.json> --output <staging-result.json>
py <skill>/scripts/archive_run.py --workspace <project> --strategy-id hstech_dca --request <request.json> --result <result.json> --strategy-file <project>/strategies/dca.py
py <skill>/scripts/render_backtest_report.py --result <result.json> --request <request.json>
py <skill>/scripts/list_runs.py --workspace <project> --kind all --compare

For offline fixture replays add --offline-fixtures <skill>/tests/fixtures to the pipeline (or --source fixtures to the collector). Offline results are never presented as FIU-backed evidence.

Strategy behavior

  • A local strategy expresses any deterministic, long-only, daily rule. Signals generated in on_bar fill at the next bar open; a final-bar signal stays unfilled with a warning. Stop/take-profit conditionals trigger against the next bar's OHLC with a conservative stop-first tie-break.
  • The runtime enforces real microstructure: CN T+1 (today's buys cannot sell today), CN price-limit interception (no buys at limit-up, no sells at limit-down), whole-lot buys (CN 100, HK board lot, US/JP 1), minimum commissions and sell-side stamp tax, and a union-calendar + forward-fill portfolio timeline (no intersection starvation).
  • The bar carries a dual channel: raw prices for execution, forward adjusted (前复权) prices for indicator math — ex-dividend/split gaps can never fabricate signals. Preset strategies already follow this rule.
  • External cash (ctx.deposit()) is recorded as a cash flow; the engine reports money-weighted XIRR so contributions are never mistaken for performance, and end-of-run virtual close marks open lots to market so unrealized losses cannot inflate the win rate.
  • Metrics: Total Return, CAGR, Max Drawdown (+duration), Sharpe, Sortino, Calmar, XIRR, Win Rate, P/L Ratio, Alpha/Beta/Tracking Error/Information Ratio vs a benchmark when configured. Missing values are null, never fabricated zeros.

Reference documents

Safety and output

  • Execute only strategy code the user asked to create or use inside the selected project. Review third-party strategy source and its license before running it. Do not place orders or call brokerage APIs.
  • Use "historical replay", "under these assumptions", and "observed in the selected period". State that results are not forecasts, personalized investment advice, or guarantees of returns or principal.