quantnodes 3.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- QuantNodes/__init__.py +15 -0
- QuantNodes/__main__.py +14 -0
- QuantNodes/agent/__init__.py +158 -0
- QuantNodes/agent/agents/__init__.py +13 -0
- QuantNodes/agent/agents/definition.py +180 -0
- QuantNodes/agent/agents/manager.py +73 -0
- QuantNodes/agent/config/__init__.py +34 -0
- QuantNodes/agent/config/executor.py +958 -0
- QuantNodes/agent/config/loader.py +427 -0
- QuantNodes/agent/config/templates/bollinger_bands.yaml +84 -0
- QuantNodes/agent/config/templates/dual_ma.yaml +72 -0
- QuantNodes/agent/config/templates/empty.yaml +56 -0
- QuantNodes/agent/config/templates/mean_reversion.yaml +47 -0
- QuantNodes/agent/config/templates/mean_reversion_zscore.yaml +90 -0
- QuantNodes/agent/config/templates/momentum.yaml +81 -0
- QuantNodes/agent/config/templates/momentum_breakout.yaml +84 -0
- QuantNodes/agent/config/templates/rsi_strategy.yaml +72 -0
- QuantNodes/agent/config/templates/volume_price.yaml +86 -0
- QuantNodes/agent/config/types.py +156 -0
- QuantNodes/agent/config_mapper.py +293 -0
- QuantNodes/agent/core/__init__.py +19 -0
- QuantNodes/agent/core/dream.py +47 -0
- QuantNodes/agent/core/quant_dream.py +274 -0
- QuantNodes/agent/cron_jobs.py +314 -0
- QuantNodes/agent/nanobot_bridge.py +242 -0
- QuantNodes/agent/permission/__init__.py +30 -0
- QuantNodes/agent/permission/defaults.py +36 -0
- QuantNodes/agent/permission/evaluate.py +41 -0
- QuantNodes/agent/permission/models.py +59 -0
- QuantNodes/agent/permission/service.py +133 -0
- QuantNodes/agent/providers/__init__.py +11 -0
- QuantNodes/agent/providers/base.py +102 -0
- QuantNodes/agent/providers/quantnodes.py +610 -0
- QuantNodes/agent/providers/rate_limiter.py +326 -0
- QuantNodes/agent/providers/registry.py +163 -0
- QuantNodes/agent/skills/__init__.py +20 -0
- QuantNodes/agent/skills/base.py +118 -0
- QuantNodes/agent/skills/bridge.py +73 -0
- QuantNodes/agent/skills/factor/__init__.py +14 -0
- QuantNodes/agent/skills/factor/correlation.py +99 -0
- QuantNodes/agent/skills/factor/group_backtest.py +114 -0
- QuantNodes/agent/skills/factor/ic_analysis.py +106 -0
- QuantNodes/agent/skills/loader.py +107 -0
- QuantNodes/agent/skills/registry.py +105 -0
- QuantNodes/agent/skills/strategy/__init__.py +16 -0
- QuantNodes/agent/skills/strategy/bollinger.py +86 -0
- QuantNodes/agent/skills/strategy/dual_ma.py +82 -0
- QuantNodes/agent/skills/strategy/momentum.py +74 -0
- QuantNodes/agent/skills/strategy/rsi_reversal.py +99 -0
- QuantNodes/agent/skills_quant/__init__.py +14 -0
- QuantNodes/agent/skills_quant/backtest-analyze/SKILL.md +42 -0
- QuantNodes/agent/skills_quant/config-driven/SKILL.md +72 -0
- QuantNodes/agent/skills_quant/factor-research/SKILL.md +40 -0
- QuantNodes/agent/skills_quant/quant-dream/SKILL.md +55 -0
- QuantNodes/agent/skills_quant/risk-management/SKILL.md +45 -0
- QuantNodes/agent/skills_quant/strategy-design/SKILL.md +43 -0
- QuantNodes/agent/templates/__init__.py +4 -0
- QuantNodes/agent/tools/__init__.py +173 -0
- QuantNodes/agent/tools/_workspace.py +51 -0
- QuantNodes/agent/tools/alpha_backtest.py +328 -0
- QuantNodes/agent/tools/alpha_evaluate.py +493 -0
- QuantNodes/agent/tools/backtest.py +226 -0
- QuantNodes/agent/tools/base.py +133 -0
- QuantNodes/agent/tools/code_search.py +207 -0
- QuantNodes/agent/tools/config_backtest.py +401 -0
- QuantNodes/agent/tools/context.py +97 -0
- QuantNodes/agent/tools/dream_skill.py +77 -0
- QuantNodes/agent/tools/echo.py +38 -0
- QuantNodes/agent/tools/factor.py +231 -0
- QuantNodes/agent/tools/file_ops.py +201 -0
- QuantNodes/agent/tools/git_ops.py +190 -0
- QuantNodes/agent/tools/operator_lookup.py +218 -0
- QuantNodes/agent/tools/output_truncation.py +77 -0
- QuantNodes/agent/tools/path_check.py +43 -0
- QuantNodes/agent/tools/pipeline.py +62 -0
- QuantNodes/agent/tools/registry.py +150 -0
- QuantNodes/agent/tools/sandbox.py +62 -0
- QuantNodes/agent/tools/shell_safety.py +63 -0
- QuantNodes/agent/tools/strategy.py +106 -0
- QuantNodes/agent/tools/task.py +171 -0
- QuantNodes/agent/tools/web_fetch.py +142 -0
- QuantNodes/agent/tools/web_search.py +114 -0
- QuantNodes/agent/tools/wiki.py +370 -0
- QuantNodes/agent/utils/__init__.py +11 -0
- QuantNodes/agent/utils/helpers.py +43 -0
- QuantNodes/agent/utils/prompt_templates.py +30 -0
- QuantNodes/agent/workflows/__init__.py +20 -0
- QuantNodes/agent/workflows/implementations/__init__.py +8 -0
- QuantNodes/agent/workflows/implementations/alpha_gpt.py +508 -0
- QuantNodes/agent/workflows/implementations/mcts.py +442 -0
- QuantNodes/agent/workflows/parsers.py +44 -0
- QuantNodes/agent/workflows/registry.py +119 -0
- QuantNodes/agent/workflows/step_agent.py +219 -0
- QuantNodes/agent/workflows/tool.py +198 -0
- QuantNodes/ai/__init__.py +93 -0
- QuantNodes/ai/llm/__init__.py +75 -0
- QuantNodes/ai/llm/base.py +233 -0
- QuantNodes/ai/llm/decorators.py +281 -0
- QuantNodes/ai/llm/gateway.py +571 -0
- QuantNodes/ai/llm/null.py +76 -0
- QuantNodes/ai/llm/openai.py +435 -0
- QuantNodes/ai/optimizer.py +405 -0
- QuantNodes/ai/prompts/__init__.py +229 -0
- QuantNodes/ai/sandbox.py +371 -0
- QuantNodes/ai/sandbox_pandas_bridge.py +150 -0
- QuantNodes/ai/strategy_gen.py +396 -0
- QuantNodes/backtest/__init__.py +64 -0
- QuantNodes/backtest/backtest_node.py +188 -0
- QuantNodes/backtest/broker_node.py +378 -0
- QuantNodes/backtest/config_runner.py +397 -0
- QuantNodes/backtest/config_strategy.py +64 -0
- QuantNodes/backtest/risk_node.py +360 -0
- QuantNodes/backtest/strategy_node.py +268 -0
- QuantNodes/cache_node/__init__.py +19 -0
- QuantNodes/cache_node/base.py +244 -0
- QuantNodes/cache_node/cache_store.py +99 -0
- QuantNodes/cache_node/metadata.py +100 -0
- QuantNodes/cli/__init__.py +109 -0
- QuantNodes/cli/_helpers.py +511 -0
- QuantNodes/cli/command.py +110 -0
- QuantNodes/cli/commands/__init__.py +69 -0
- QuantNodes/cli/commands/agent.py +158 -0
- QuantNodes/cli/commands/alpha.py +951 -0
- QuantNodes/cli/commands/chat.py +38 -0
- QuantNodes/cli/commands/evolve.py +120 -0
- QuantNodes/cli/commands/factor.py +569 -0
- QuantNodes/cli/commands/init.py +190 -0
- QuantNodes/cli/commands/run.py +259 -0
- QuantNodes/cli/commands/serve.py +398 -0
- QuantNodes/cli/commands/version.py +120 -0
- QuantNodes/cli/enhanced.py +146 -0
- QuantNodes/conf_node/__init__.py +37 -0
- QuantNodes/conf_node/base.py +120 -0
- QuantNodes/conf_node/env_config.py +132 -0
- QuantNodes/conf_node/ini_config.py +70 -0
- QuantNodes/conf_node/json_config.py +69 -0
- QuantNodes/conf_node/yaml_config.py +78 -0
- QuantNodes/constants.py +17 -0
- QuantNodes/core/__init__.py +196 -0
- QuantNodes/core/_lookback_helpers.py +49 -0
- QuantNodes/core/ast_parser.py +198 -0
- QuantNodes/core/base.py +61 -0
- QuantNodes/core/cache_manager.py +344 -0
- QuantNodes/core/cache_utils.py +150 -0
- QuantNodes/core/cond_builder.py +53 -0
- QuantNodes/core/config.py +170 -0
- QuantNodes/core/constants.py +48 -0
- QuantNodes/core/control.py +412 -0
- QuantNodes/core/data_preprocessing.py +453 -0
- QuantNodes/core/data_source.py +46 -0
- QuantNodes/core/events.py +178 -0
- QuantNodes/core/evolution/__init__.py +22 -0
- QuantNodes/core/evolution/loop.py +583 -0
- QuantNodes/core/evolution/operators.py +289 -0
- QuantNodes/core/evolution/settings.py +44 -0
- QuantNodes/core/expression.py +841 -0
- QuantNodes/core/feedback/__init__.py +38 -0
- QuantNodes/core/feedback/channels.py +182 -0
- QuantNodes/core/feedback/collector.py +91 -0
- QuantNodes/core/feedback/dataclass.py +239 -0
- QuantNodes/core/feedback/llm_judge.py +138 -0
- QuantNodes/core/knowledge/__init__.py +69 -0
- QuantNodes/core/knowledge/knowledge_base.py +217 -0
- QuantNodes/core/knowledge/lineage_compress.py +196 -0
- QuantNodes/core/knowledge/lineage_expand.py +123 -0
- QuantNodes/core/knowledge/metrics/__init__.py +43 -0
- QuantNodes/core/knowledge/metrics/evaluator.py +176 -0
- QuantNodes/core/knowledge/metrics/metrics.py +220 -0
- QuantNodes/core/knowledge/rag_prompt.py +196 -0
- QuantNodes/core/knowledge/retriever.py +209 -0
- QuantNodes/core/lambda_node.py +81 -0
- QuantNodes/core/monitoring/__init__.py +22 -0
- QuantNodes/core/monitoring/collector.py +292 -0
- QuantNodes/core/monitoring/dashboard.py +365 -0
- QuantNodes/core/node.py +375 -0
- QuantNodes/core/pandas_utils.py +504 -0
- QuantNodes/core/parallel/__init__.py +15 -0
- QuantNodes/core/parallel/worker.py +140 -0
- QuantNodes/core/parallel/worker_process.py +265 -0
- QuantNodes/core/path_utils.py +73 -0
- QuantNodes/core/pipeline.py +328 -0
- QuantNodes/core/plugin.py +135 -0
- QuantNodes/core/quality_gate/__init__.py +32 -0
- QuantNodes/core/quality_gate/complexity.py +94 -0
- QuantNodes/core/quality_gate/consistency.py +26 -0
- QuantNodes/core/quality_gate/node.py +97 -0
- QuantNodes/core/quality_gate/redundancy.py +51 -0
- QuantNodes/core/quality_gate/settings.py +43 -0
- QuantNodes/core/quality_gate/zoo.py +98 -0
- QuantNodes/core/serializable.py +116 -0
- QuantNodes/core/serialization.py +673 -0
- QuantNodes/core/tools.py +333 -0
- QuantNodes/core/trajectory/__init__.py +25 -0
- QuantNodes/core/trajectory/entry.py +116 -0
- QuantNodes/core/trajectory/lineage.py +67 -0
- QuantNodes/core/trajectory/pool.py +211 -0
- QuantNodes/core/trajectory/selector.py +140 -0
- QuantNodes/core/visualization/__init__.py +33 -0
- QuantNodes/core/visualization/builder.py +233 -0
- QuantNodes/core/visualization/gate_breakdown.py +140 -0
- QuantNodes/core/visualization/lineage_dag.py +203 -0
- QuantNodes/core/visualization/metric_distribution.py +125 -0
- QuantNodes/core/visualization/report.py +68 -0
- QuantNodes/database_node/__init__.py +69 -0
- QuantNodes/database_node/base.py +135 -0
- QuantNodes/database_node/clickhouse_node.py +272 -0
- QuantNodes/database_node/csv_node.py +83 -0
- QuantNodes/database_node/duckdb_node.py +86 -0
- QuantNodes/database_node/factory.py +83 -0
- QuantNodes/database_node/mysql_node.py +100 -0
- QuantNodes/database_node/parquet_node.py +75 -0
- QuantNodes/database_node/sqlite_node.py +67 -0
- QuantNodes/factor_node/__init__.py +50 -0
- QuantNodes/factor_node/factor.py +563 -0
- QuantNodes/factor_node/factor_db.py +421 -0
- QuantNodes/factor_node/factor_functions/__init__.py +252 -0
- QuantNodes/factor_node/factor_functions/_helpers.py +358 -0
- QuantNodes/factor_node/factor_functions/_helpers_debug.py +317 -0
- QuantNodes/factor_node/factor_functions/composite_ops.py +136 -0
- QuantNodes/factor_node/factor_functions/math_ops.py +433 -0
- QuantNodes/factor_node/factor_functions/section_ops.py +290 -0
- QuantNodes/factor_node/factor_functions/talib_ops.py +1293 -0
- QuantNodes/factor_node/factor_functions/time_ops.py +535 -0
- QuantNodes/factor_node/factor_operation.py +1115 -0
- QuantNodes/factor_node/factor_table.py +1073 -0
- QuantNodes/factor_node/quant_nodes_object.py +60 -0
- QuantNodes/mcp_server/__init__.py +27 -0
- QuantNodes/mcp_server/__main__.py +4 -0
- QuantNodes/mcp_server/server.py +272 -0
- QuantNodes/methods/__init__.py +28 -0
- QuantNodes/methods/pipeline.py +100 -0
- QuantNodes/methods/sandbox.py +102 -0
- QuantNodes/monitor/__init__.py +27 -0
- QuantNodes/monitor/agent_tools/__init__.py +5 -0
- QuantNodes/monitor/agent_tools/monitor_tool.py +98 -0
- QuantNodes/monitor/agent_tools/schedule_tool.py +98 -0
- QuantNodes/monitor/agent_tools/version_tool.py +133 -0
- QuantNodes/monitor/monitor/__init__.py +6 -0
- QuantNodes/monitor/monitor/alerter.py +60 -0
- QuantNodes/monitor/monitor/collector.py +164 -0
- QuantNodes/monitor/monitor/dashboard.py +115 -0
- QuantNodes/monitor/monitor/drift.py +190 -0
- QuantNodes/monitor/scheduler/__init__.py +4 -0
- QuantNodes/monitor/scheduler/runner.py +133 -0
- QuantNodes/monitor/scheduler/scheduler.py +184 -0
- QuantNodes/monitor/storage/__init__.py +16 -0
- QuantNodes/monitor/storage/models.py +70 -0
- QuantNodes/monitor/storage/repository.py +407 -0
- QuantNodes/monitor/version/__init__.py +4 -0
- QuantNodes/monitor/version/diff.py +81 -0
- QuantNodes/monitor/version/version_manager.py +182 -0
- QuantNodes/operator_node/__init__.py +28 -0
- QuantNodes/operator_node/base.py +97 -0
- QuantNodes/operator_node/query_node.py +129 -0
- QuantNodes/operator_node/sql_builder.py +125 -0
- QuantNodes/operator_node/sql_utils.py +172 -0
- QuantNodes/operator_node/transform.py +130 -0
- QuantNodes/operators/__init__.py +90 -0
- QuantNodes/operators/_engine.py +108 -0
- QuantNodes/operators/composite.py +161 -0
- QuantNodes/operators/composite_dag.py +667 -0
- QuantNodes/operators/composite_dag_ops.py +343 -0
- QuantNodes/operators/composite_dag_pandas_ops.py +382 -0
- QuantNodes/operators/custom.py +408 -0
- QuantNodes/operators/facade.py +164 -0
- QuantNodes/operators/math.py +163 -0
- QuantNodes/operators/proxy.py +29 -0
- QuantNodes/operators/registry.py +144 -0
- QuantNodes/operators/section.py +99 -0
- QuantNodes/operators/talib.py +757 -0
- QuantNodes/operators/templates.py +95 -0
- QuantNodes/operators/time_series.py +136 -0
- QuantNodes/prompts/__init__.py +20 -0
- QuantNodes/prompts/backtest/__init__.py +12 -0
- QuantNodes/prompts/backtest/factor_based.py +86 -0
- QuantNodes/prompts/backtest/standard.py +73 -0
- QuantNodes/prompts/factor/__init__.py +14 -0
- QuantNodes/prompts/factor/correlation.py +77 -0
- QuantNodes/prompts/factor/group_backtest.py +86 -0
- QuantNodes/prompts/factor/ic_analysis.py +91 -0
- QuantNodes/prompts/strategy/__init__.py +18 -0
- QuantNodes/prompts/strategy/market_neutral.py +96 -0
- QuantNodes/prompts/strategy/mean_reversion.py +107 -0
- QuantNodes/prompts/strategy/momentum.py +160 -0
- QuantNodes/prompts/strategy/pairs_trading.py +107 -0
- QuantNodes/prompts/strategy/trend_following.py +96 -0
- QuantNodes/research/README.md +106 -0
- QuantNodes/research/__init__.py +154 -0
- QuantNodes/research/_legacy_3c/__init__.py +61 -0
- QuantNodes/research/_legacy_3c/auto_researcher.py +289 -0
- QuantNodes/research/_legacy_3c/factor_evaluator.py +560 -0
- QuantNodes/research/_legacy_3c/factor_miner.py +318 -0
- QuantNodes/research/_legacy_3c/mcts_search.py +324 -0
- QuantNodes/research/factor_test/__init__.py +25 -0
- QuantNodes/research/factor_test/config.py +184 -0
- QuantNodes/research/factor_test/config_builder.py +276 -0
- QuantNodes/research/factor_test/e2e/data_prep.py +163 -0
- QuantNodes/research/factor_test/e2e/run_evolution_e2e.py +309 -0
- QuantNodes/research/factor_test/evolution_adapter.py +231 -0
- QuantNodes/research/factor_test/feedback_wrapper.py +102 -0
- QuantNodes/research/factor_test/ifind_db/__init__.py +7 -0
- QuantNodes/research/factor_test/ifind_db/fetcher.py +224 -0
- QuantNodes/research/factor_test/ifind_db/ifind_database.py +689 -0
- QuantNodes/research/factor_test/nodes/__init__.py +1 -0
- QuantNodes/research/factor_test/nodes/_base.py +91 -0
- QuantNodes/research/factor_test/nodes/adjust_date_node.py +48 -0
- QuantNodes/research/factor_test/nodes/configs.py +240 -0
- QuantNodes/research/factor_test/nodes/factor_neutralize_node.py +87 -0
- QuantNodes/research/factor_test/nodes/factor_preprocess_node.py +222 -0
- QuantNodes/research/factor_test/nodes/factor_score_node.py +141 -0
- QuantNodes/research/factor_test/nodes/factor_test_report_node.py +153 -0
- QuantNodes/research/factor_test/nodes/group_analyzer_node.py +317 -0
- QuantNodes/research/factor_test/nodes/ic_analyzer_node.py +112 -0
- QuantNodes/research/factor_test/nodes/load_data_node.py +100 -0
- QuantNodes/research/factor_test/nodes/long_short_node.py +93 -0
- QuantNodes/research/factor_test/nodes/neutralizers.py +222 -0
- QuantNodes/research/factor_test/nodes/preprocess_strategies.py +277 -0
- QuantNodes/research/factor_test/nodes/risk_correlation_node.py +112 -0
- QuantNodes/research/factor_test/nodes/sample_pool_filter_node.py +110 -0
- QuantNodes/research/factor_test/nodes/tradability_filter_node.py +92 -0
- QuantNodes/research/factor_test/pipeline_runner.py +305 -0
- QuantNodes/research/factor_test/pipeline_spec.py +216 -0
- QuantNodes/research/factor_test/utils/__init__.py +26 -0
- QuantNodes/research/factor_test/utils/constants.py +86 -0
- QuantNodes/research/factor_test/utils/data_loader.py +141 -0
- QuantNodes/research/factor_test/utils/date_utils.py +232 -0
- QuantNodes/research/factor_test/utils/file_loaders.py +150 -0
- QuantNodes/research/factor_test/utils/labels.py +37 -0
- QuantNodes/research/factor_test/utils/metrics_extractor.py +55 -0
- QuantNodes/research/factor_test/utils/performance_metrics.py +175 -0
- QuantNodes/research/factor_test/utils/safe_load.py +106 -0
- QuantNodes/research/quant_alpha/CHANGELOG.md +80 -0
- QuantNodes/research/quant_alpha/README.md +142 -0
- QuantNodes/research/quant_alpha/__init__.py +45 -0
- QuantNodes/research/quant_alpha/adapters/__init__.py +99 -0
- QuantNodes/research/quant_alpha/adapters/calculator.py +503 -0
- QuantNodes/research/quant_alpha/adapters/expression.py +387 -0
- QuantNodes/research/quant_alpha/alpha101_design/__init__.py +50 -0
- QuantNodes/research/quant_alpha/alpha101_design/few_shot_examples.py +243 -0
- QuantNodes/research/quant_alpha/alpha101_design/philosophy.py +474 -0
- QuantNodes/research/quant_alpha/alpha158_design/__init__.py +63 -0
- QuantNodes/research/quant_alpha/alpha158_design/few_shot_examples.py +219 -0
- QuantNodes/research/quant_alpha/alpha158_design/philosophy.py +240 -0
- QuantNodes/research/quant_alpha/evaluation/__init__.py +47 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/__init__.py +8 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g1_handcrafted.py +135 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g2_llm_only.py +269 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g3_alpha_gpt.py +152 -0
- QuantNodes/research/quant_alpha/evaluation/clickhouse_data_loader.py +227 -0
- QuantNodes/research/quant_alpha/evaluation/contracts.py +376 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/__init__.py +6 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/polars_evaluator.py +545 -0
- QuantNodes/research/quant_alpha/evaluation/mock_data_loader.py +226 -0
- QuantNodes/research/quant_alpha/evaluation/runner.py +243 -0
- QuantNodes/research/quant_alpha/llm/__init__.py +38 -0
- QuantNodes/research/quant_alpha/llm/parser.py +681 -0
- QuantNodes/research/quant_alpha/logic_driven_pipeline.py +411 -0
- QuantNodes/research/quant_alpha/logic_mining/__init__.py +74 -0
- QuantNodes/research/quant_alpha/logic_mining/compiler.py +457 -0
- QuantNodes/research/quant_alpha/logic_mining/generator.py +366 -0
- QuantNodes/research/quant_alpha/logic_mining/models.py +252 -0
- QuantNodes/research/quant_alpha/logic_mining/parser.py +287 -0
- QuantNodes/research/quant_alpha/logic_mining/pipelines.py +297 -0
- QuantNodes/research/quant_alpha/logic_mining/sources.py +149 -0
- QuantNodes/research/quant_alpha/mcts/__init__.py +66 -0
- QuantNodes/research/quant_alpha/mcts/cache.py +262 -0
- QuantNodes/research/quant_alpha/mcts/extension_ops.py +320 -0
- QuantNodes/research/quant_alpha/mcts/feedback.py +825 -0
- QuantNodes/research/quant_alpha/mcts/op_prior.py +180 -0
- QuantNodes/research/quant_alpha/mcts/search.py +540 -0
- QuantNodes/research/quant_alpha/mcts/tree.py +201 -0
- QuantNodes/research/quant_alpha/operator_vocab/__init__.py +50 -0
- QuantNodes/research/quant_alpha/operator_vocab/config.py +54 -0
- QuantNodes/research/quant_alpha/operator_vocab/metadata.py +263 -0
- QuantNodes/research/quant_alpha/operator_vocab/vocabulary.py +481 -0
- QuantNodes/research/quant_alpha/pipeline.py +1027 -0
- QuantNodes/research/quant_alpha/types/__init__.py +27 -0
- QuantNodes/research/quant_alpha/types/constants.py +28 -0
- QuantNodes/research/quant_alpha/types/state.py +205 -0
- QuantNodes/research/quant_alpha/workflow/__init__.py +32 -0
- QuantNodes/research/quant_alpha/workflow/alpha_gpt.py +911 -0
- QuantNodes/research/quant_alpha/workflow/alpha_logics.py +416 -0
- QuantNodes/research/quant_alpha/workflow/state.py +27 -0
- QuantNodes/research/report_reproducer.py +485 -0
- QuantNodes/research/wiki.py +1155 -0
- QuantNodes/symbolic/__init__.py +51 -0
- QuantNodes/symbolic/compiler.py +113 -0
- QuantNodes/symbolic/dialect.py +260 -0
- QuantNodes/symbolic/executor.py +147 -0
- QuantNodes/symbolic/expression.py +234 -0
- QuantNodes/symbolic/functions.py +433 -0
- QuantNodes/symbolic/optimizer.py +165 -0
- QuantNodes/ui_node/__init__.py +30 -0
- QuantNodes/ui_node/base.py +222 -0
- quantnodes-3.0.0.dist-info/METADATA +463 -0
- quantnodes-3.0.0.dist-info/RECORD +399 -0
- quantnodes-3.0.0.dist-info/WHEEL +5 -0
- quantnodes-3.0.0.dist-info/entry_points.txt +24 -0
- quantnodes-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
配置加载器
|
|
4
|
+
|
|
5
|
+
解析 YAML 配置文件为 StrategyConfig 对象。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
import importlib.util
|
|
12
|
+
import warnings
|
|
13
|
+
from typing import Optional
|
|
14
|
+
import yaml
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from .types import (
|
|
18
|
+
StrategyConfig,
|
|
19
|
+
FactorConfig,
|
|
20
|
+
OperationConfig,
|
|
21
|
+
CompositeConfig,
|
|
22
|
+
BacktestConfig,
|
|
23
|
+
ValidationConfig,
|
|
24
|
+
DataConfig,
|
|
25
|
+
OutputConfig,
|
|
26
|
+
CoverageReport,
|
|
27
|
+
)
|
|
28
|
+
from QuantNodes.operators.proxy import list_operators as _list_operators
|
|
29
|
+
|
|
30
|
+
# executor category → registry category 映射
|
|
31
|
+
_CATEGORY_MAP = {
|
|
32
|
+
"time_series": "time",
|
|
33
|
+
"section": "section",
|
|
34
|
+
"math": "point",
|
|
35
|
+
"composite": "point",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ConfigLoader:
|
|
40
|
+
"""YAML配置加载器"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, working_dir: str = "."):
|
|
43
|
+
self.working_dir = Path(working_dir)
|
|
44
|
+
self._config: Optional[StrategyConfig] = None
|
|
45
|
+
|
|
46
|
+
def load(self, path: str) -> StrategyConfig:
|
|
47
|
+
"""加载YAML配置文件
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
path: 配置文件路径
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
StrategyConfig 对象
|
|
54
|
+
"""
|
|
55
|
+
config_path = self.working_dir / path
|
|
56
|
+
if not config_path.exists():
|
|
57
|
+
raise FileNotFoundError(f"Config file not found: {config_path}")
|
|
58
|
+
|
|
59
|
+
with open(config_path, encoding="utf-8") as f:
|
|
60
|
+
data = yaml.safe_load(f)
|
|
61
|
+
|
|
62
|
+
if data is None:
|
|
63
|
+
data = {}
|
|
64
|
+
|
|
65
|
+
self._config = self._parse(data)
|
|
66
|
+
return self._config
|
|
67
|
+
|
|
68
|
+
def _parse(self, data: dict) -> StrategyConfig:
|
|
69
|
+
"""解析配置字典"""
|
|
70
|
+
config = StrategyConfig(
|
|
71
|
+
version=data.get("version", "1.0"),
|
|
72
|
+
name=data.get("name", ""),
|
|
73
|
+
description=data.get("description", ""),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# 数据源配置
|
|
77
|
+
if "data" in data:
|
|
78
|
+
d = data["data"]
|
|
79
|
+
config.data = DataConfig(
|
|
80
|
+
source=d.get("source", "csv"),
|
|
81
|
+
path=d.get("path", ""),
|
|
82
|
+
columns=d.get("columns", []),
|
|
83
|
+
date_column=d.get("date_column", "date"),
|
|
84
|
+
code_column=d.get("code_column", "code"),
|
|
85
|
+
db_date_column=d.get("db_date_column", ""),
|
|
86
|
+
db_code_column=d.get("db_code_column", ""),
|
|
87
|
+
table=d.get("table", ""),
|
|
88
|
+
conn_ini=d.get("conn_ini", "conn.ini"),
|
|
89
|
+
conn_section=d.get("conn_section", "ClickHouse"),
|
|
90
|
+
column_mapping=d.get("column_mapping", {}),
|
|
91
|
+
query_filter=d.get("query_filter", ""),
|
|
92
|
+
standard_columns=d.get("standard_columns", {
|
|
93
|
+
"open": "open",
|
|
94
|
+
"high": "high",
|
|
95
|
+
"low": "low",
|
|
96
|
+
"close": "close",
|
|
97
|
+
"volume": "volume",
|
|
98
|
+
}),
|
|
99
|
+
cache_enabled=d.get("cache_enabled", False),
|
|
100
|
+
cache_ttl_days=d.get("cache_ttl_days", 7),
|
|
101
|
+
cache_dir=d.get("cache_dir", "~/.quantnodes/cache"),
|
|
102
|
+
cache_force_refresh=d.get("cache_force_refresh", False),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# 因子定义
|
|
106
|
+
config.factors = [
|
|
107
|
+
FactorConfig(
|
|
108
|
+
name=f["name"],
|
|
109
|
+
expr=f.get("expr", ""),
|
|
110
|
+
description=f.get("description", "")
|
|
111
|
+
)
|
|
112
|
+
for f in data.get("factors", [])
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
# 运算配置
|
|
116
|
+
config.operations = [
|
|
117
|
+
OperationConfig(
|
|
118
|
+
type=op["type"],
|
|
119
|
+
name=op["name"],
|
|
120
|
+
category=op["category"],
|
|
121
|
+
inputs=op.get("inputs", []),
|
|
122
|
+
params=op.get("params", {})
|
|
123
|
+
)
|
|
124
|
+
for op in data.get("operations", [])
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
# 组合因子
|
|
128
|
+
config.composite = [
|
|
129
|
+
CompositeConfig(
|
|
130
|
+
name=c["name"],
|
|
131
|
+
formula=c.get("formula", ""),
|
|
132
|
+
weights=c.get("weights"),
|
|
133
|
+
normalize=c.get("normalize", False),
|
|
134
|
+
winsorize=c.get("winsorize")
|
|
135
|
+
)
|
|
136
|
+
for c in data.get("composite", [])
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
# 回测配置
|
|
140
|
+
if "backtest" in data:
|
|
141
|
+
bt = data["backtest"]
|
|
142
|
+
config.backtest = BacktestConfig(
|
|
143
|
+
start_date=bt.get("start_date", ""),
|
|
144
|
+
end_date=bt.get("end_date", ""),
|
|
145
|
+
initial_cash=bt.get("initial_cash", 1000000),
|
|
146
|
+
commission=bt.get("commission", 0.001),
|
|
147
|
+
slippage=bt.get("slippage", 0.001),
|
|
148
|
+
universe=bt.get("universe", "A_stock"),
|
|
149
|
+
signals=bt.get("signals", {}),
|
|
150
|
+
positions=bt.get("positions", {}),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# 验证配置
|
|
154
|
+
if "validation" in data:
|
|
155
|
+
v = data["validation"]
|
|
156
|
+
config.validation = ValidationConfig(
|
|
157
|
+
run_tests=v.get("run_tests", True),
|
|
158
|
+
test_files=v.get("test_files", []),
|
|
159
|
+
metrics=v.get("metrics", {}),
|
|
160
|
+
custom_operators=v.get("custom_operators", []),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# 输出配置
|
|
164
|
+
if "output" in data:
|
|
165
|
+
o = data["output"]
|
|
166
|
+
config.output = OutputConfig(
|
|
167
|
+
format=o.get("format", "parquet"),
|
|
168
|
+
path=o.get("path", "outputs/result.parquet"),
|
|
169
|
+
save_signals=o.get("save_signals", True),
|
|
170
|
+
save_positions=o.get("save_positions", True),
|
|
171
|
+
save_equity_curve=o.get("save_equity_curve", True),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return config
|
|
175
|
+
|
|
176
|
+
def _preload_custom_operators(self, custom_operators: list) -> None:
|
|
177
|
+
"""预加载自定义算子到 registry
|
|
178
|
+
|
|
179
|
+
在 check_coverage 之前调用,确保自定义算子被识别。
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
custom_operators: ValidationConfig.custom_operators 列表
|
|
183
|
+
"""
|
|
184
|
+
if not custom_operators:
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
from QuantNodes.operators.proxy import register_operator
|
|
188
|
+
|
|
189
|
+
for entry in custom_operators:
|
|
190
|
+
if isinstance(entry, str):
|
|
191
|
+
source_path = entry
|
|
192
|
+
category = "point"
|
|
193
|
+
functions = None
|
|
194
|
+
else:
|
|
195
|
+
source_path = entry.get("source", "")
|
|
196
|
+
category = entry.get("category", "point")
|
|
197
|
+
functions = entry.get("functions")
|
|
198
|
+
|
|
199
|
+
if not source_path:
|
|
200
|
+
continue
|
|
201
|
+
|
|
202
|
+
try:
|
|
203
|
+
spec = importlib.util.spec_from_file_location("custom_ops", source_path)
|
|
204
|
+
if spec is None or spec.loader is None:
|
|
205
|
+
warnings.warn(f"无法加载自定义算子文件: {source_path}")
|
|
206
|
+
continue
|
|
207
|
+
module = importlib.util.module_from_spec(spec)
|
|
208
|
+
spec.loader.exec_module(module)
|
|
209
|
+
except Exception as e:
|
|
210
|
+
warnings.warn(f"加载自定义算子文件失败 {source_path}: {e}")
|
|
211
|
+
continue
|
|
212
|
+
|
|
213
|
+
for name in dir(module):
|
|
214
|
+
if name.startswith("_"):
|
|
215
|
+
continue
|
|
216
|
+
if functions and name not in functions:
|
|
217
|
+
continue
|
|
218
|
+
if not functions and not name.startswith("custom_"):
|
|
219
|
+
continue
|
|
220
|
+
|
|
221
|
+
func = getattr(module, name)
|
|
222
|
+
if not callable(func):
|
|
223
|
+
continue
|
|
224
|
+
|
|
225
|
+
register_operator(_CATEGORY_MAP.get(category, "point"), name=name)(func)
|
|
226
|
+
|
|
227
|
+
def check_coverage(self, config: StrategyConfig) -> CoverageReport:
|
|
228
|
+
"""检查配置覆盖度
|
|
229
|
+
|
|
230
|
+
使用 factor_functions 的真实注册表检查算子是否存在。
|
|
231
|
+
会先加载 custom_operators 以确保自定义算子被识别。
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
config: 策略配置
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
CoverageReport 对象
|
|
238
|
+
"""
|
|
239
|
+
# 预加载自定义算子
|
|
240
|
+
self._preload_custom_operators(config.validation.custom_operators)
|
|
241
|
+
|
|
242
|
+
covered = []
|
|
243
|
+
unresolved = []
|
|
244
|
+
|
|
245
|
+
# 获取所有已注册的算子名称
|
|
246
|
+
all_operators = set(_list_operators())
|
|
247
|
+
|
|
248
|
+
# 已定义的列名(factors + operations 的输出)
|
|
249
|
+
defined_names = set()
|
|
250
|
+
for factor in config.factors:
|
|
251
|
+
defined_names.add(factor.name)
|
|
252
|
+
for op in config.operations:
|
|
253
|
+
defined_names.add(op.name)
|
|
254
|
+
|
|
255
|
+
# 检查因子定义
|
|
256
|
+
for factor in config.factors:
|
|
257
|
+
if factor.expr:
|
|
258
|
+
covered.append("factor:%s" % factor.name)
|
|
259
|
+
else:
|
|
260
|
+
unresolved.append("factor:%s" % factor.name)
|
|
261
|
+
|
|
262
|
+
# 检查算子 - 使用 factor_functions 真实注册表
|
|
263
|
+
for op in config.operations:
|
|
264
|
+
category = op.category
|
|
265
|
+
|
|
266
|
+
if category in all_operators:
|
|
267
|
+
covered.append("op:%s" % category)
|
|
268
|
+
else:
|
|
269
|
+
unresolved.append("op:%s" % category)
|
|
270
|
+
|
|
271
|
+
# 检查组合因子公式
|
|
272
|
+
for comp in config.composite:
|
|
273
|
+
if not comp.formula:
|
|
274
|
+
unresolved.append("composite:%s" % comp.name)
|
|
275
|
+
continue
|
|
276
|
+
|
|
277
|
+
covered.append("composite:%s" % comp.name)
|
|
278
|
+
|
|
279
|
+
# 提取公式中调用的函数名
|
|
280
|
+
func_names = re.findall(r'\b([a-zA-Z_]\w*)\s*\(', comp.formula)
|
|
281
|
+
for fn in func_names:
|
|
282
|
+
if fn not in all_operators and fn not in defined_names:
|
|
283
|
+
unresolved.append("composite:%s:unknown_func:%s" % (comp.name, fn))
|
|
284
|
+
|
|
285
|
+
# 提取公式中引用的标识符(非函数调用的)
|
|
286
|
+
# 移除函数调用部分后,提取剩余的标识符
|
|
287
|
+
formula_no_funcs = re.sub(r'\b\w+\s*\([^)]*\)', '', comp.formula)
|
|
288
|
+
ref_names = re.findall(r'\b([a-zA-Z_]\w*)\b', formula_no_funcs)
|
|
289
|
+
for rn in ref_names:
|
|
290
|
+
# 跳过 Python 关键字和数字
|
|
291
|
+
if rn in ('true', 'false', 'null', 'and', 'or', 'not', 'None'):
|
|
292
|
+
continue
|
|
293
|
+
if rn not in defined_names and rn not in all_operators:
|
|
294
|
+
unresolved.append("composite:%s:unknown_ref:%s" % (comp.name, rn))
|
|
295
|
+
|
|
296
|
+
return CoverageReport(covered=covered, unresolved=unresolved)
|
|
297
|
+
|
|
298
|
+
def get_config(self) -> Optional[StrategyConfig]:
|
|
299
|
+
"""获取当前配置"""
|
|
300
|
+
return self._config
|
|
301
|
+
|
|
302
|
+
def to_yaml(self, config: StrategyConfig, path: str) -> None:
|
|
303
|
+
"""导出配置为YAML
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
config: 策略配置
|
|
307
|
+
path: 输出路径
|
|
308
|
+
"""
|
|
309
|
+
data = {
|
|
310
|
+
"version": config.version,
|
|
311
|
+
"name": config.name,
|
|
312
|
+
"description": config.description,
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if config.data:
|
|
316
|
+
data["data"] = {
|
|
317
|
+
"source": config.data.source,
|
|
318
|
+
"path": config.data.path,
|
|
319
|
+
"columns": config.data.columns,
|
|
320
|
+
"date_column": config.data.date_column,
|
|
321
|
+
"code_column": config.data.code_column,
|
|
322
|
+
}
|
|
323
|
+
if config.data.db_date_column:
|
|
324
|
+
data["data"]["db_date_column"] = config.data.db_date_column
|
|
325
|
+
if config.data.db_code_column:
|
|
326
|
+
data["data"]["db_code_column"] = config.data.db_code_column
|
|
327
|
+
if config.data.table:
|
|
328
|
+
data["data"]["table"] = config.data.table
|
|
329
|
+
if config.data.conn_ini != "conn.ini":
|
|
330
|
+
data["data"]["conn_ini"] = config.data.conn_ini
|
|
331
|
+
if config.data.conn_section != "ClickHouse":
|
|
332
|
+
data["data"]["conn_section"] = config.data.conn_section
|
|
333
|
+
if config.data.column_mapping:
|
|
334
|
+
data["data"]["column_mapping"] = config.data.column_mapping
|
|
335
|
+
if config.data.query_filter:
|
|
336
|
+
data["data"]["query_filter"] = config.data.query_filter
|
|
337
|
+
if config.data.standard_columns:
|
|
338
|
+
data["data"]["standard_columns"] = config.data.standard_columns
|
|
339
|
+
if config.data.cache_enabled:
|
|
340
|
+
data["data"]["cache_enabled"] = True
|
|
341
|
+
data["data"]["cache_ttl_days"] = config.data.cache_ttl_days
|
|
342
|
+
if config.data.cache_dir != "~/.quantnodes/cache":
|
|
343
|
+
data["data"]["cache_dir"] = config.data.cache_dir
|
|
344
|
+
if config.data.cache_force_refresh:
|
|
345
|
+
data["data"]["cache_force_refresh"] = True
|
|
346
|
+
|
|
347
|
+
data["factors"] = [
|
|
348
|
+
{
|
|
349
|
+
"name": f.name,
|
|
350
|
+
"expr": f.expr,
|
|
351
|
+
"description": f.description,
|
|
352
|
+
}
|
|
353
|
+
for f in config.factors
|
|
354
|
+
]
|
|
355
|
+
|
|
356
|
+
data["operations"] = [
|
|
357
|
+
{
|
|
358
|
+
"type": op.type,
|
|
359
|
+
"name": op.name,
|
|
360
|
+
"category": op.category,
|
|
361
|
+
"inputs": op.inputs,
|
|
362
|
+
"params": op.params,
|
|
363
|
+
}
|
|
364
|
+
for op in config.operations
|
|
365
|
+
]
|
|
366
|
+
|
|
367
|
+
data["composite"] = [
|
|
368
|
+
{
|
|
369
|
+
"name": c.name,
|
|
370
|
+
"formula": c.formula,
|
|
371
|
+
"weights": c.weights,
|
|
372
|
+
"normalize": c.normalize,
|
|
373
|
+
"winsorize": c.winsorize,
|
|
374
|
+
}
|
|
375
|
+
for c in config.composite
|
|
376
|
+
]
|
|
377
|
+
|
|
378
|
+
if config.backtest:
|
|
379
|
+
data["backtest"] = {
|
|
380
|
+
"start_date": config.backtest.start_date,
|
|
381
|
+
"end_date": config.backtest.end_date,
|
|
382
|
+
"initial_cash": config.backtest.initial_cash,
|
|
383
|
+
"commission": config.backtest.commission,
|
|
384
|
+
"slippage": config.backtest.slippage,
|
|
385
|
+
}
|
|
386
|
+
if config.backtest.universe != "A_stock":
|
|
387
|
+
data["backtest"]["universe"] = config.backtest.universe
|
|
388
|
+
if config.backtest.signals:
|
|
389
|
+
data["backtest"]["signals"] = config.backtest.signals
|
|
390
|
+
if config.backtest.positions:
|
|
391
|
+
data["backtest"]["positions"] = config.backtest.positions
|
|
392
|
+
|
|
393
|
+
if config.validation:
|
|
394
|
+
v = config.validation
|
|
395
|
+
data["validation"] = {
|
|
396
|
+
"run_tests": v.run_tests,
|
|
397
|
+
}
|
|
398
|
+
if v.test_files:
|
|
399
|
+
data["validation"]["test_files"] = v.test_files
|
|
400
|
+
if v.metrics:
|
|
401
|
+
data["validation"]["metrics"] = v.metrics
|
|
402
|
+
if v.custom_operators:
|
|
403
|
+
data["validation"]["custom_operators"] = v.custom_operators
|
|
404
|
+
|
|
405
|
+
if config.output:
|
|
406
|
+
data["output"] = {
|
|
407
|
+
"format": config.output.format,
|
|
408
|
+
"path": config.output.path,
|
|
409
|
+
"save_signals": config.output.save_signals,
|
|
410
|
+
"save_positions": config.output.save_positions,
|
|
411
|
+
"save_equity_curve": config.output.save_equity_curve,
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
415
|
+
yaml.dump(data, f, allow_unicode=True, sort_keys=False)
|
|
416
|
+
|
|
417
|
+
def load_config(path: str) -> StrategyConfig:
|
|
418
|
+
"""便捷加载函数
|
|
419
|
+
|
|
420
|
+
Args:
|
|
421
|
+
path: 配置文件路径
|
|
422
|
+
|
|
423
|
+
Returns:
|
|
424
|
+
StrategyConfig 对象
|
|
425
|
+
"""
|
|
426
|
+
loader = ConfigLoader()
|
|
427
|
+
return loader.load(path)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# bollinger_bands.yaml
|
|
2
|
+
# 布林带突破策略
|
|
3
|
+
# 逻辑: 价格跌破下轨买入,突破上轨卖出
|
|
4
|
+
|
|
5
|
+
version: "1.0"
|
|
6
|
+
name: "bollinger_breakout"
|
|
7
|
+
description: "布林带突破策略 - 价格跌破下轨买入,突破上轨卖出"
|
|
8
|
+
|
|
9
|
+
data:
|
|
10
|
+
source: clickhouse
|
|
11
|
+
conn_ini: conn.ini
|
|
12
|
+
conn_section: ClickHouse
|
|
13
|
+
table: quote.cn_stock
|
|
14
|
+
columns: [ts_code, trade_date, open, high, low, close, vol]
|
|
15
|
+
|
|
16
|
+
db_date_column: trade_date
|
|
17
|
+
db_code_column: ts_code
|
|
18
|
+
date_column: date
|
|
19
|
+
code_column: code
|
|
20
|
+
|
|
21
|
+
column_mapping:
|
|
22
|
+
ts_code: code
|
|
23
|
+
trade_date: date
|
|
24
|
+
vol: volume
|
|
25
|
+
|
|
26
|
+
query_filter: "WHERE trade_date >= toDateTime('2023-07-01')"
|
|
27
|
+
|
|
28
|
+
factors:
|
|
29
|
+
- name: close_ma
|
|
30
|
+
expr: "ts_mean(close, 20)"
|
|
31
|
+
description: "20日均线(布林带中轨)"
|
|
32
|
+
|
|
33
|
+
- name: close_std
|
|
34
|
+
expr: "ts_std(close, 20)"
|
|
35
|
+
description: "20日标准差"
|
|
36
|
+
|
|
37
|
+
- name: upper_band
|
|
38
|
+
expr: "close_ma + 2 * close_std"
|
|
39
|
+
description: "布林带上轨"
|
|
40
|
+
|
|
41
|
+
- name: lower_band
|
|
42
|
+
expr: "close_ma - 2 * close_std"
|
|
43
|
+
description: "布林带下轨"
|
|
44
|
+
|
|
45
|
+
- name: band_width
|
|
46
|
+
expr: "(upper_band - lower_band) / close_ma"
|
|
47
|
+
description: "布林带宽度"
|
|
48
|
+
|
|
49
|
+
operations:
|
|
50
|
+
- type: section
|
|
51
|
+
name: band_width_rank
|
|
52
|
+
category: rank
|
|
53
|
+
inputs: [band_width]
|
|
54
|
+
description: "布林带宽度截面排名"
|
|
55
|
+
|
|
56
|
+
- type: section
|
|
57
|
+
name: close_position
|
|
58
|
+
category: rank
|
|
59
|
+
inputs: [close]
|
|
60
|
+
description: "价格截面排名"
|
|
61
|
+
|
|
62
|
+
composite:
|
|
63
|
+
- name: alpha
|
|
64
|
+
formula: "-1 * band_width_rank"
|
|
65
|
+
|
|
66
|
+
backtest:
|
|
67
|
+
start_date: "2023-07-01"
|
|
68
|
+
end_date: "2024-07-19"
|
|
69
|
+
initial_cash: 1000000
|
|
70
|
+
commission: 0.001
|
|
71
|
+
slippage: 0.001
|
|
72
|
+
|
|
73
|
+
signals:
|
|
74
|
+
buy_threshold: 0.6
|
|
75
|
+
sell_threshold: 0.4
|
|
76
|
+
|
|
77
|
+
positions:
|
|
78
|
+
max_positions: 10
|
|
79
|
+
rebalance_freq: "weekly"
|
|
80
|
+
|
|
81
|
+
output:
|
|
82
|
+
format: parquet
|
|
83
|
+
path: "outputs/bollinger_result.parquet"
|
|
84
|
+
save_signals: true
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# dual_ma.yaml
|
|
2
|
+
# 双均线金叉死叉策略
|
|
3
|
+
# 用户场景: "帮我写一个双均线策略,回测一下看看效果"
|
|
4
|
+
|
|
5
|
+
version: "1.0"
|
|
6
|
+
name: "dual_ma_crossover"
|
|
7
|
+
description: "双均线金叉死叉策略 - 短期均线上穿长期均线买入,下穿卖出"
|
|
8
|
+
|
|
9
|
+
data:
|
|
10
|
+
source: clickhouse
|
|
11
|
+
conn_ini: conn.ini
|
|
12
|
+
conn_section: ClickHouse
|
|
13
|
+
table: quote.cn_stock
|
|
14
|
+
columns: [ts_code, trade_date, open, high, low, close, vol]
|
|
15
|
+
|
|
16
|
+
db_date_column: trade_date
|
|
17
|
+
db_code_column: ts_code
|
|
18
|
+
date_column: date
|
|
19
|
+
code_column: code
|
|
20
|
+
|
|
21
|
+
column_mapping:
|
|
22
|
+
ts_code: code
|
|
23
|
+
trade_date: date
|
|
24
|
+
vol: volume
|
|
25
|
+
|
|
26
|
+
query_filter: "WHERE trade_date >= toDateTime('2023-07-01')"
|
|
27
|
+
|
|
28
|
+
factors:
|
|
29
|
+
- name: short_ma
|
|
30
|
+
expr: "ts_mean(close, 5)"
|
|
31
|
+
description: "5日均线(短期)"
|
|
32
|
+
|
|
33
|
+
- name: long_ma
|
|
34
|
+
expr: "ts_mean(close, 20)"
|
|
35
|
+
description: "20日均线(长期)"
|
|
36
|
+
|
|
37
|
+
- name: ma_diff
|
|
38
|
+
expr: "short_ma - long_ma"
|
|
39
|
+
description: "均线差值"
|
|
40
|
+
|
|
41
|
+
operations:
|
|
42
|
+
- type: section
|
|
43
|
+
name: ma_diff_rank
|
|
44
|
+
category: rank
|
|
45
|
+
inputs: [ma_diff]
|
|
46
|
+
description: "均线差值截面排名"
|
|
47
|
+
|
|
48
|
+
composite:
|
|
49
|
+
- name: alpha
|
|
50
|
+
formula: "ma_diff_rank"
|
|
51
|
+
|
|
52
|
+
backtest:
|
|
53
|
+
start_date: "2023-07-01"
|
|
54
|
+
end_date: "2024-07-19"
|
|
55
|
+
initial_cash: 1000000
|
|
56
|
+
commission: 0.001
|
|
57
|
+
slippage: 0.001
|
|
58
|
+
|
|
59
|
+
signals:
|
|
60
|
+
buy_threshold: 0.6
|
|
61
|
+
sell_threshold: 0.4
|
|
62
|
+
|
|
63
|
+
positions:
|
|
64
|
+
max_positions: 10
|
|
65
|
+
rebalance_freq: "weekly"
|
|
66
|
+
|
|
67
|
+
output:
|
|
68
|
+
format: parquet
|
|
69
|
+
path: "outputs/dual_ma_result.parquet"
|
|
70
|
+
save_signals: true
|
|
71
|
+
save_positions: true
|
|
72
|
+
save_equity_curve: true
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# strategy.yaml
|
|
2
|
+
# 策略配置文件模板
|
|
3
|
+
|
|
4
|
+
version: "1.0"
|
|
5
|
+
name: "my_strategy"
|
|
6
|
+
description: "策略描述"
|
|
7
|
+
|
|
8
|
+
# 数据源 (可选)
|
|
9
|
+
# data:
|
|
10
|
+
# source: "csv"
|
|
11
|
+
# path: "data/data.csv"
|
|
12
|
+
# columns: [date, code, open, high, low, close, volume]
|
|
13
|
+
# date_column: "date"
|
|
14
|
+
# code_column: "code"
|
|
15
|
+
|
|
16
|
+
# 因子定义 (可选)
|
|
17
|
+
# factors:
|
|
18
|
+
# - name: factor_name
|
|
19
|
+
# expr: "close / close.shift(20) - 1"
|
|
20
|
+
# description: "因子描述"
|
|
21
|
+
|
|
22
|
+
# 运算配置 (可选)
|
|
23
|
+
# operations:
|
|
24
|
+
# - type: time_series # time_series / section / math / composite
|
|
25
|
+
# name: op_name
|
|
26
|
+
# category: ts_mean # 具体算子
|
|
27
|
+
# inputs: [factor_name]
|
|
28
|
+
# params:
|
|
29
|
+
# window: 20
|
|
30
|
+
|
|
31
|
+
# 组合因子 (可选)
|
|
32
|
+
# composite:
|
|
33
|
+
# - name: alpha
|
|
34
|
+
# formula: "rank(factor_name)"
|
|
35
|
+
# normalize: true
|
|
36
|
+
|
|
37
|
+
# 回测配置 (可选)
|
|
38
|
+
# backtest:
|
|
39
|
+
# start_date: "2023-01-01"
|
|
40
|
+
# end_date: "2024-12-31"
|
|
41
|
+
# initial_cash: 1000000
|
|
42
|
+
# commission: 0.001
|
|
43
|
+
# slippage: 0.001
|
|
44
|
+
|
|
45
|
+
# 验证配置 (可选)
|
|
46
|
+
# validation:
|
|
47
|
+
# run_tests: true
|
|
48
|
+
# metrics:
|
|
49
|
+
# ic_threshold: 0.02
|
|
50
|
+
# max_correlation: 0.7
|
|
51
|
+
|
|
52
|
+
# 输出配置 (可选)
|
|
53
|
+
# output:
|
|
54
|
+
# format: "parquet"
|
|
55
|
+
# path: "outputs/result.parquet"
|
|
56
|
+
# save_signals: true
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# mean_reversion.yaml
|
|
2
|
+
# 均值回复策略配置
|
|
3
|
+
|
|
4
|
+
version: "1.0"
|
|
5
|
+
name: "mean_reversion"
|
|
6
|
+
description: "均值回复策略"
|
|
7
|
+
|
|
8
|
+
# 因子定义
|
|
9
|
+
factors:
|
|
10
|
+
- name: close_ma
|
|
11
|
+
expr: "ts_mean(close, 20)"
|
|
12
|
+
description: "20日均线"
|
|
13
|
+
|
|
14
|
+
- name: close_std
|
|
15
|
+
expr: "ts_std(close, 20)"
|
|
16
|
+
description: "20日标准差"
|
|
17
|
+
|
|
18
|
+
# 运算
|
|
19
|
+
operations:
|
|
20
|
+
- type: section
|
|
21
|
+
name: zscore_value
|
|
22
|
+
category: zscore
|
|
23
|
+
inputs: [close_ma]
|
|
24
|
+
|
|
25
|
+
- type: section
|
|
26
|
+
name: alpha_rank
|
|
27
|
+
category: rank
|
|
28
|
+
inputs: [zscore_value]
|
|
29
|
+
|
|
30
|
+
# 组合
|
|
31
|
+
composite:
|
|
32
|
+
- name: alpha
|
|
33
|
+
formula: "-1 * alpha_rank"
|
|
34
|
+
|
|
35
|
+
backtest:
|
|
36
|
+
start_date: "2023-01-01"
|
|
37
|
+
end_date: "2024-12-31"
|
|
38
|
+
initial_cash: 1000000
|
|
39
|
+
|
|
40
|
+
signals:
|
|
41
|
+
buy_threshold: 0.05
|
|
42
|
+
sell_threshold: -0.03
|
|
43
|
+
|
|
44
|
+
validation:
|
|
45
|
+
run_tests: true
|
|
46
|
+
metrics:
|
|
47
|
+
ic_threshold: 0.02
|