Draft
Conversation
This commit implements Issue NoFxAiOS#1306 - adding support for small custom quantitative models to the NoFx trading platform. Users can now create, configure, import, and export their own trading models based on technical indicators and rules. Backend Changes: - Add store/quant_model.go: QuantModel, QuantModelConfig types with DB operations - Add api/quant_model.go: Full REST API for CRUD, import, export, clone operations - Add api/server.go: Register 11 new quant-model endpoints - Add kernel/quant_model_engine.go: Model execution engine for indicator/rule-based models - Add market/indicator_calculator.go: RSI, EMA, MACD, ATR, Bollinger calculations - Add api/quant_model_test.go: Unit tests for API handlers - Update store/store.go: Add quantModel store to Store struct with InitTables - Update store/strategy.go: Add QuantModelIntegration to StrategyConfig Frontend Changes: - Add web/src/types/strategy.ts: QuantModel, QuantModelConfig TypeScript interfaces - Add web/src/components/strategy/QuantModelEditor.tsx: Full model editor component - Add web/src/pages/QuantModelsPage.tsx: Standalone quant models management page Features: - Create indicator-based models (RSI, EMA, MACD, ATR, Bollinger) - Create rule-based models with logical conditions - Import/Export models as JSON for sharing - Backtest statistics tracking (win rate, sharpe, drawdown) - Public model gallery for community sharing - Template system with pre-built strategies - Bilingual UI (English/Chinese)
|
|
1 similar comment
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
之前,NoFx 仅依赖 AI 提示词进行交易决策,这存在几个限制:
解决方案概述
新的量化模型系统允许用户:
RSI_14 < 30 AND Close > EMA_20新功能
1. 后端 API (
api/quant_model.go)模型管理的新 REST 端点:
/api/quant-models/api/quant-models/api/quant-models/:id/api/quant-models/:id/api/quant-models/:id/api/quant-models/:id/export/api/quant-models/import/api/quant-models/:id/clone/api/quant-models/:id/backtest-stats/api/quant-models/templates/api/quant-models/public2. 数据层 (
store/quant_model.go)新数据库表
quant_models包含:配置模式:
3. 执行引擎 (
kernel/quant_model_engine.go)QuantModelEngine 实时执行模型:
支持的指标:
规则语法:
4. 前端 UI (
web/src/pages/QuantModelsPage.tsx)新的量化模型管理页面:
模型编辑器 (
web/src/components/strategy/QuantModelEditor.tsx):5. 前端类型 (
web/src/types/strategy.ts)扩展的 StrategyConfig 包含:
使用示例
示例 1:RSI 超卖策略(基于指标)
配置:
{ "type": "indicator_based", "indicators": [ { "name": "RSI", "period": 14, "timeframe": "1h", "weight": 0.4 }, { "name": "EMA", "period": 20, "timeframe": "1h", "weight": 0.3 }, { "name": "MACD", "period": 12, "timeframe": "1h", "weight": 0.3 } ], "parameters": { "lookback_periods": 100, "entry_threshold": 70, "exit_threshold": 30 } }逻辑:
示例 2:突破规则(基于规则)
配置:
{ "type": "rule_based", "rules": [ { "name": "RSI_Oversold_Bounce", "condition": "RSI_14 < 30 AND Close > EMA_20", "action": "buy", "confidence": 80 }, { "name": "ATR_Breakout", "condition": "ATR_14 > ATR_14_SMA * 1.5 AND Close > Upper_Bollinger_20", "action": "buy", "confidence": 70 } ] }导入/导出格式
导出的 JSON 结构:
{ "version": "1.0", "exported_at": "2024-01-15T10:30:00Z", "model": { "id": "original-id", "name": "我的 RSI 策略", "model_type": "indicator_based", "config": { } } }通过以下方式分享模型:
回测集成
模型跟踪性能指标:
win_rate:盈利交易百分比avg_profit_pct:每笔交易平均回报max_drawdown_pct:最大峰谷跌幅sharpe_ratio:风险调整回报指标backtest_count:运行的回测次数用户可以在部署到实盘交易前进行回测:
社区与公共模型
is_public: true未来增强
本 PR 为以下功能奠定基础:
测试
api/quant_model_test.go- 所有 API 处理程序的单元测试迁移说明
quant_models表通过 GORM AutoMigrate 自动创建quant_model_integration字段参考
Issue #1306: 能不能在策略那里加自己的小型量化模型,可以导入导出,这样的话,算力回测才会有用武之地不用单纯的依赖提示词
Summary
Change Type
Scope
Linked Issues
Testing
go build ./...passes (after go mod tidy)api/quant_model_test.go)go test ./...requires go mod tidy first (dependency updates pending)Security Impact
/api/quant-models/*Compatibility
quant_modelstable auto-created by GORM变更文件
api/quant_model.goapi/quant_model_test.goapi/server.gokernel/quant_model_engine.gomarket/indicator_calculator.gostore/quant_model.gostore/store.gostore/strategy.goweb/src/components/strategy/QuantModelEditor.tsxweb/src/pages/QuantModelsPage.tsxweb/src/types/strategy.ts建议补充验证
go mod tidy后重跑测试quant_model_integration的保存与读取一致性