AI 托管机器学习模型正在自动优化最佳参数...
+正在对 {activeTicker} 近期 5 天的高频 1m 波动率和突破阻力位进行量化网格搜索。
+AI 智能托管报告 (AI Auto-Pilot Tuning Report)
++ {tuningReport} +
+ + {tuningMetrics && ( +diff --git a/Dockerfile b/Dockerfile index 2b267c91e28009458766205a4ff560540a0811fe..f033dfec108370db80b6a0b3d53c26cec8ac9932 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.12-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ - PORT=8080 \ + PORT=7860 \ DATABASE_URL=sqlite+aiosqlite:////app/inferroute.db \ MOCK_OPENAI=true \ MOCK_GEMINI=true \ @@ -29,9 +29,10 @@ RUN pip install --no-cache-dir -r requirements.txt COPY inferroute/ ./inferroute/ COPY docs/ ./docs/ COPY benchmarks/ ./benchmarks/ +COPY external/ ./external/ -# Expose default port -EXPOSE 8080 +# Expose default port (7860 for Hugging Face Spaces) +EXPOSE 7860 # Command to run uvicorn dynamically binding to PORT environment variable (for Render/Hugging Face compatibility) -CMD ["sh", "-c", "python -m uvicorn inferroute.main:app --host 0.0.0.0 --port ${PORT:-8080}"] +CMD ["sh", "-c", "python -m uvicorn inferroute.main:app --host 0.0.0.0 --port ${PORT:-7860}"] diff --git a/external/Quant.ai/.gitignore b/external/Quant.ai/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6a62034cffc7f941c705b88f368e46c4fc5ae1f7 --- /dev/null +++ b/external/Quant.ai/.gitignore @@ -0,0 +1,31 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# OS Files +.DS_Store +Thumbs.db + +# Virtual Environments +venv/ +.venv/ +env/ +.env + +# PDF and documentation binaries (exclude reading packages) +*.pdf + +# IDE and model temp directories +.gemini/ +.idea/ +.vscode/ +node_modules/ +dist/ +build/ + +# Local cache and databases +backend/data_cache/ +backend/app/experiments.db +*.db + diff --git a/external/Quant.ai/README.md b/external/Quant.ai/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1bebd813689db35e7cbbee2da635f1fd975831ad --- /dev/null +++ b/external/Quant.ai/README.md @@ -0,0 +1,132 @@ +# Quant.ai - Advanced Quant Trading Engine & Backtest Simulator + +
+
+
+
+
+
+
+
+
正在对 {activeTicker} 近期 5 天的高频 1m 波动率和突破阻力位进行量化网格搜索。
++ {tuningReport} +
+ + {tuningMetrics && ( +{errorMsg}
+backend/.env 中添加您的 Alpaca API Key。
+ + {isBotRunning + ? '系统正在后台以 1分钟 频率高频评估行情,满足形态与突破信号时将直接提交订单至您的 Alpaca 账户。' + : '点击右侧按钮启动 AI 托管。开启后无需手动干预,全自动执行买卖与动态风控。'} +
+| 代码 | +持股数 | +建仓均价 | +最新现价 | +浮动盈亏 | +
|---|---|---|---|---|
| {pos.ticker} | +{pos.shares} 股 | +${pos.avg_entry_price.toFixed(2)} | +${pos.current_price.toFixed(2)} | ++ {isUp ? '+' : ''}${pos.unrealized_pnl.toFixed(2)} ({isUp ? '+' : ''}{pos.unrealized_pnl_pct.toFixed(2)}%) + | +
$1')
+ }} />
+ ))}
+ 暂无该公司档案信息。
+| 对比指标 / 参数 | + {comparedExperiments.map((exp) => ( +
+ {exp.name}
+
+ {exp.ticker} ({exp.interval}) | {exp.timestamp}
+
+ |
+ ))}
+
|---|---|
| 核心表现指标 (Metrics) | + {comparedExperiments.map((exp) => ( ++ ))} + |
| 净盈亏 (Net PnL) | + {comparedExperiments.map((exp) => { + const val = exp.metrics.net_pnl; + return ( += 0 ? 'var(--color-green)' : 'var(--color-red)', borderLeft: '1px solid var(--color-border)' }}> + ${val.toLocaleString(undefined, { minimumFractionDigits: 2 })} ({exp.metrics.pnl_pct.toFixed(2)}%) + | + ); + })} +
| 夏普比率 (Sharpe Ratio) | + {comparedExperiments.map((exp) => ( += 1 ? 'var(--color-green)' : 'inherit', borderLeft: '1px solid var(--color-border)' }}> + {exp.metrics.sharpe.toFixed(2)} + | + ))} +
| 卡尔玛比率 (Calmar Ratio) | + {comparedExperiments.map((exp) => ( ++ {exp.metrics.calmar.toFixed(2)} + | + ))} +
| 最大回撤 (Max Drawdown) | + {comparedExperiments.map((exp) => ( ++ {(exp.metrics.max_drawdown * 100).toFixed(2)}% + | + ))} +
| 交易胜率 (Win Rate) | + {comparedExperiments.map((exp) => ( ++ {exp.metrics.win_rate.toFixed(1)}% + | + ))} +
| 盈亏比 (Profit Factor) | + {comparedExperiments.map((exp) => ( ++ {exp.metrics.profit_factor.toFixed(2)} + | + ))} +
| 总交易次数 (Total Trades) | + {comparedExperiments.map((exp) => ( ++ {exp.metrics.round_trips} 笔 + | + ))} +
| 交易手续费 (Commission) | + {comparedExperiments.map((exp) => ( ++ ${exp.metrics.commission.toFixed(2)} + | + ))} +
| 策略回测参数 (Parameters) | + {comparedExperiments.map((exp) => ( ++ ))} + |
| 策略模式 (Strategy Mode) | + {comparedExperiments.map((exp) => ( ++ {exp.strategy_mode} + | + ))} +
| 固定止损比例 (Stop Loss) | + {comparedExperiments.map((exp) => ( ++ {(exp.config.stop_loss_pct * 100).toFixed(2)}% + | + ))} +
| 固定止盈目标 (Profit Target) | + {comparedExperiments.map((exp) => ( ++ {(exp.config.profit_target_pct * 100).toFixed(2)}% + | + ))} +
| 追踪止损 ATR 倍数 | + {comparedExperiments.map((exp) => ( ++ {exp.config.trailing_stop_atr_mult}x + | + ))} +
| RSI 买入阀值 (Buy Threshold) | + {comparedExperiments.map((exp) => ( ++ {exp.config.rsi_threshold_buy} + | + ))} +
| 单笔最大风险 (Risk Per Trade) | + {comparedExperiments.map((exp) => ( ++ {(exp.config.risk_per_trade_pct * 100).toFixed(2)}% + | + ))} +
| 最大仓位上限 (Max Pos Size) | + {comparedExperiments.map((exp) => ( ++ {(exp.config.max_position_size_pct * 100).toFixed(2)}% + | + ))} +
暂无保存的实验。请在 Dashboard 中运行策略回测,系统将自动记录,或点击右上角保存。
+| 选择 | +实验 ID | +实验名称 | +时间戳 | +股票代码 | +K线周期 | +策略路由模式 | +回测收益 PnL | +最大回撤 | +夏普比率 | +操作 | +
|---|---|---|---|---|---|---|---|---|---|---|
| + handleCheckboxChange(exp.id)} + style={{ width: '18px', height: '18px', cursor: 'pointer' }} + /> + | +#{exp.id} | +{exp.name} | +{exp.timestamp} | +{exp.ticker} | +{exp.interval} | ++ + {exp.strategy_mode} + + | += 0 ? 'var(--color-green)' : 'var(--color-red)' }}> + ${exp.metrics.net_pnl.toLocaleString(undefined, { minimumFractionDigits: 2 })} ({exp.metrics.pnl_pct.toFixed(2)}%) + | +{(exp.metrics.max_drawdown * 100).toFixed(2)}% | +{exp.metrics.sharpe.toFixed(2)} | ++ + | +
+ 回测期间系统保持空仓防守,未触发交易信号。 +
+ ) : ( +| 交易时间 | +操作 | +代码 | +股数 | +成交均价 | +( 盘面价格 ) | +交易手续费 | +净收益 PnL | +
|---|---|---|---|---|---|---|---|
| {formatTime(item.timestamp)} | ++ + {item.action === 'BUY' ? 'BUY / 买入' : 'SELL / 平仓'} + + | +{item.ticker} | +{item.shares} | +${item.execution_price.toFixed(2)} | ++ ${item.market_price.toFixed(2)} + | +${item.commission.toFixed(2)} | ++ {pnlText} + | +
+ 回测时段内未识别到明显的标志性 K 线形态(如双底/双顶/锤子线等)。 +
+ ) : ( + patterns.map((item, idx) => { + const isBullish = item.type === 'bullish'; + const badgeColor = isBullish ? 'var(--color-green)' : 'var(--color-red)'; + const bgBadgeColor = isBullish ? 'rgba(0, 200, 5, 0.12)' : 'rgba(255, 59, 48, 0.12)'; + + return ( ++ No regime-specific trade data available for the current backtest. +
+| Regime | +Trades | +Win Rate | +PnL | +W / L | +Commission | +
|---|---|---|---|---|---|
| + + {info.emoji} {info.label} + + | +{item.trade_count} | ++ = 50 ? 'var(--color-green)' : 'var(--color-text-secondary)' }}> + {item.win_rate.toFixed(0)}% + + | ++ + {isPositive ? '+' : ''}${item.total_pnl.toLocaleString(undefined, { minimumFractionDigits: 2 })} + + | ++ {item.wins} + {' / '} + {item.losses} + | ++ ${item.commission.toFixed(2)} + | +
$1');
+};
+
+export const ResearchReportPanel: React.FC+ 你的目标是长期平均每天净赚 500 美元。根据市场统计学,年化净收益率(按 252 个交易日计)与所需本金存在以下动态关系。移动滑块查看您的方案可行性。 +
+ ++ {feasibilityDesc} +
++ 代码必须通过策略底层适配器屏蔽市场交易差异。切换标签对比主要规则: +
+ +
+ {item.formula}
+
+ + 本系统并不是盲目执行单一策略,而是先通过 Regime Classifier 进行环境识别,再将决策权路由给子模块: +
+ ++ 不要主观觉得该买多少股,应当让系统根据最大风险预算和止损距离来反推头寸规模: +
+ ++ 为了防止参数过拟合于历史噪音,我们必须进行样本内外的滑动窗滚动测试: +
+ ++ Quant.ai 项目的后端量化逻辑采用模块化设计。点击直接阅读相关代码: +
+ + ++ 在系统准备进入模拟盘或实盘运行前,您需要手动验证以下各维度的完备性。勾选可保存自查进度: +
+ +| {h} | + ))} +
|---|
| + ))} + |
+ {comp.content}
+
+ + 根据相对成交量 (RVol > 1.2)、波动率 (ATR% > 1.5%) 筛选高确定性日内交易候选者 +
+| 代码 | +公司名 | +板块 | +当前价 | +相对量 (RVol) | +日波动率 (ATR%) | +跳空 (Gap%) | +日成交量 | +AI 研判 | +操作 | +
|---|---|---|---|---|---|---|---|---|---|
| + {row.ticker} + | +{row.name} | +{row.sector.split(' ')[0]} | +${row.price.toFixed(2)} | +1.5 ? 'var(--color-green)' : '#ffffff' }}> + {row.rvol.toFixed(2)}x + | +2.0 ? 'var(--color-green)' : '#ffffff' }}> + {row.atr_pct.toFixed(2)}% + | +0 ? 'var(--color-green)' : row.gap_pct < 0 ? 'var(--color-red)' : 'inherit', + fontWeight: 600 + }}> + {row.gap_pct > 0 ? '+' : ''}{row.gap_pct.toFixed(2)}% + | +{row.volume_m.toFixed(1)}M 股 | ++ + {row.recommended ? '★ 强烈推荐交易' : '不推荐交易'} + + | ++ + | +
+ {aiAutoPilot + ? "机器学习调优中。算法自动分析开盘高频阻力与相对成交量,调配仓位与止损,保护本金并稳健止盈。" + : "开启后,系统将自动基于近期历史特征运行微型 Walk-Forward 调优,代替手动参数设置。" + } +
++ 样本外滚动优化 (Walk-Forward Optimization) 可以避免回测的“后视镜”偏差。系统使用历史的一段区间寻找最佳参数,并在接下来的区间进行真实样本外检验。 +
+ ++ 优化算法检测到训练集平均 Sharpe ({result.summary.avg_is_sharpe}) 表现优秀,但在样本外测试集中表现急剧退化 (平均 Sharpe: {result.summary.avg_oos_sharpe})。 + 且 IS 与 OOS Sharpe 的相关性为 {result.correlation}。这高度说明当前优化的策略参数在过度拟合历史噪声,建议增加过滤器、减少网格参数或放宽滑点控制。 +
+| 窗口 | +训练时间段 (In-Sample) | +测试时间段 (Out-of-Sample) | +最佳优化参数 | +IS Sharpe | +OOS Sharpe | +样本外盈亏 | +样本外最大回撤 | +
|---|---|---|---|---|---|---|---|
| #{row.window} | +{row.train_period} | +{row.test_period} | ++ {row.best_params.strategy_mode} (ATR:{row.best_params.trailing_stop_atr_mult}x, RSI:{row.best_params.rsi_threshold_buy}) + | +{row.is_sharpe.toFixed(2)} | += 0.5 ? 'var(--color-green)' : (row.oos_sharpe < 0 ? 'var(--color-red)' : 'inherit'), fontWeight: 700 }}> + {row.oos_sharpe.toFixed(2)} + | += 0 ? 'var(--color-green)' : 'var(--color-red)' }}> + ${row.net_pnl.toFixed(2)} + | ++ {(row.max_drawdown * 100).toFixed(2)}% + | +
+ Plug InferRoute into any existing AI application in 1 minute. Redirect base_url to gain 35.8% KV-cache prefill acceleration, multi-provider failover, and up to 87.7% cost reduction.
+
+ Matches prompt prefix in Radix Trie cache. Cuts prefill latency by 35.8% by reusing KV-cache states across requests. +
++ Evaluates prompt difficulty. Dispatches lightweight prompts to Gemini 1.5 / vLLM, and complex code/reasoning to GPT-4o. +
++ Monitors provider health. Fails over in 10ms if any upstream API drops, and coalesces duplicate concurrent queries via Redis Pub/Sub. +
++ All applications hosted on Hugging Face Spaces or external servers route their LLM requests through InferRoute. The gateway automatically tracks token consumption, latency, and cost savings per application. +
+ ++ Stock analysis, financial report extraction, and quantitative code generation. Uses Cascade routing to guarantee high-reasoning accuracy. +
++ Facial attribute analysis and multimodal visual description. Automatically routes visual queries to Gemini Flash / Vision nodes. +
++ Autonomous multi-agent orchestration. Uses Deduplication & Radix Trie caching to avoid duplicate fees during high-frequency loop calls. +
++ Our empirical evaluation on 4,682 benchmark queries proves that InferRoute preserves 99.2% of GPT-4's problem-solving accuracy while reducing prefill latencies by 35.8% and cutting API costs by 87.7%. +
++ For every single request routed through InferRoute, the database logs the exact baseline cost if GPT-4 were used vs the actual cost of the routed model: +
+ +100,000 requests @ $0.015 / 1k tokens
+Net Savings: $1,315.80 (87.7% Cost Reduction)
+