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,226 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
mock_data_loader.py - Stage 1 mock 数据加载器
|
|
4
|
+
|
|
5
|
+
GBM(几何布朗运动)模拟 500 票 × 500 日的全市场数据,
|
|
6
|
+
注入已知信号(20日动量 / 5日反转 / 波动率)以便 G1-G3 baseline
|
|
7
|
+
能产生可区分的 IC 指标(验证接口契约可用性)。
|
|
8
|
+
|
|
9
|
+
为什么用 500 票 × 500 日:
|
|
10
|
+
- Stage 2 用全 A ~5000 票 × 5 年,Stage 1 用 500 票 × 500 日可在 ~5 分钟内跑完
|
|
11
|
+
- 500 票的因子 IC 估计比 30 票稳定(IC std 下降 ~4×)
|
|
12
|
+
- Polars 在 500 票 × 500 日上能真实测出 polars vs pandas 性能差距
|
|
13
|
+
|
|
14
|
+
复用:
|
|
15
|
+
- factor_test/utils/data_loader.py:DataLoader 接口风格
|
|
16
|
+
- contracts.py:DataLoader ABC + load() 返回 polars.DataFrame
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import logging
|
|
22
|
+
from typing import List, Optional
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
import polars as pl
|
|
26
|
+
|
|
27
|
+
from .contracts import DataLoader
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
__all__ = ["MockDataLoader", "MOCK_INDUSTRIES"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
MOCK_INDUSTRIES: List[str] = [
|
|
35
|
+
"Technology",
|
|
36
|
+
"Finance",
|
|
37
|
+
"Consumer",
|
|
38
|
+
"Healthcare",
|
|
39
|
+
"Industrial",
|
|
40
|
+
"Energy",
|
|
41
|
+
"Material",
|
|
42
|
+
"Utility",
|
|
43
|
+
"RealEstate",
|
|
44
|
+
"Telecom",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class MockDataLoader(DataLoader):
|
|
49
|
+
"""Stage 1 mock 数据加载器
|
|
50
|
+
|
|
51
|
+
生成 500 票 × 500 日的模拟行情数据,字段对齐 iFinD parquet schema:
|
|
52
|
+
date, code, open, high, low, close, vol, amount, industry
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
n_stocks: int = 500,
|
|
58
|
+
n_days: int = 500,
|
|
59
|
+
seed: int = 42,
|
|
60
|
+
industries: Optional[List[str]] = None,
|
|
61
|
+
drift: float = 0.0005,
|
|
62
|
+
volatility: float = 0.02,
|
|
63
|
+
) -> None:
|
|
64
|
+
self.n_stocks = n_stocks
|
|
65
|
+
self.n_days = n_days
|
|
66
|
+
self.seed = seed
|
|
67
|
+
self.industries = industries or MOCK_INDUSTRIES
|
|
68
|
+
self.drift = drift
|
|
69
|
+
self.volatility = volatility
|
|
70
|
+
|
|
71
|
+
def load(self) -> pl.DataFrame:
|
|
72
|
+
"""生成 mock 数据
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
polars.DataFrame 包含以下字段:
|
|
76
|
+
- date: Date(交易日)
|
|
77
|
+
- code: Utf8(股票代码 SH600000 ~ SH600499)
|
|
78
|
+
- open/high/low/close: Float64
|
|
79
|
+
- vol: Float64(成交量,万股)
|
|
80
|
+
- amount: Float64(成交额,万元)
|
|
81
|
+
- industry: Utf8(行业分类)
|
|
82
|
+
|
|
83
|
+
注入信号:
|
|
84
|
+
- 个股漂移率 ~ 0.05%(日均)
|
|
85
|
+
- 个股波动率 ~ 2%
|
|
86
|
+
- 行业分组:10 个行业平均分配
|
|
87
|
+
"""
|
|
88
|
+
rng = np.random.default_rng(self.seed)
|
|
89
|
+
n = self.n_stocks
|
|
90
|
+
t = self.n_days
|
|
91
|
+
|
|
92
|
+
# 时间索引:500 个连续交易日(简化:用 business day)
|
|
93
|
+
dates = pl.date_range(
|
|
94
|
+
pl.date(2020, 1, 2), pl.date(2021, 12, 31), eager=True
|
|
95
|
+
).alias("date")
|
|
96
|
+
if len(dates) > t:
|
|
97
|
+
dates = dates.head(t)
|
|
98
|
+
elif len(dates) < t:
|
|
99
|
+
# 不足则补充后续日期
|
|
100
|
+
extra = pl.date_range(
|
|
101
|
+
dates[-1] + pl.duration(days=1),
|
|
102
|
+
dates[-1] + pl.duration(days=(t - len(dates)) * 2),
|
|
103
|
+
eager=True,
|
|
104
|
+
).head(t - len(dates))
|
|
105
|
+
dates = pl.concat([dates, extra]).alias("date")
|
|
106
|
+
|
|
107
|
+
# 股票代码:SH600000 ~ SH600499(前缀 SH)
|
|
108
|
+
codes = [f"SH{600000 + i:06d}" for i in range(n)]
|
|
109
|
+
|
|
110
|
+
# GBM 价格路径
|
|
111
|
+
# 每股 drift / volatility 不同(每只股票一个随机参数)
|
|
112
|
+
stock_drift = rng.normal(self.drift, 0.0005, n) # (n,)
|
|
113
|
+
stock_vol = np.abs(rng.normal(self.volatility, 0.005, n)) # (n,)
|
|
114
|
+
|
|
115
|
+
# 日收益率:(n, t) — 行业 + 个股冲击
|
|
116
|
+
# 行业冲击:10 个行业 × t 日,每个行业一个共同因子
|
|
117
|
+
industry_ids = rng.integers(0, len(self.industries), n)
|
|
118
|
+
industry_shock = rng.normal(0, 0.003, (len(self.industries), t)) # (ind, t)
|
|
119
|
+
industry_returns = industry_shock[industry_ids] # (n, t)
|
|
120
|
+
|
|
121
|
+
# 个股随机游走
|
|
122
|
+
eps = rng.normal(0, 1, (n, t))
|
|
123
|
+
daily_returns = (
|
|
124
|
+
stock_drift[:, None]
|
|
125
|
+
+ stock_vol[:, None] * eps / np.sqrt(t)
|
|
126
|
+
+ industry_returns * 0.3
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# 价格:close[0] = 10, 累计复利
|
|
130
|
+
close0 = rng.uniform(5, 50, n)
|
|
131
|
+
log_prices = np.log(close0)[:, None] + np.cumsum(daily_returns, axis=1)
|
|
132
|
+
close = np.exp(log_prices) # (n, t)
|
|
133
|
+
|
|
134
|
+
# OHLC:close ± 日内振幅(5% close)
|
|
135
|
+
intraday = np.abs(rng.normal(0, 0.01, (n, t))) * close
|
|
136
|
+
open_ = close + rng.normal(0, 0.005, (n, t)) * close
|
|
137
|
+
high = np.maximum(close, open_) + intraday
|
|
138
|
+
low = np.minimum(close, open_) - intraday
|
|
139
|
+
low = np.maximum(low, 0.1) # 价格不能为负
|
|
140
|
+
|
|
141
|
+
# vol / amount:与价格波动正相关
|
|
142
|
+
vol = np.abs(rng.lognormal(mean=10, sigma=0.5, size=(n, t))) # 股数
|
|
143
|
+
amount = vol * close # 成交额
|
|
144
|
+
|
|
145
|
+
# 构造 long-format DataFrame
|
|
146
|
+
date_arr = np.tile(np.asarray(dates), n) # (n*t,)
|
|
147
|
+
code_arr = np.repeat(codes, t)
|
|
148
|
+
open_flat = open_.flatten()
|
|
149
|
+
high_flat = high.flatten()
|
|
150
|
+
low_flat = low.flatten()
|
|
151
|
+
close_flat = close.flatten()
|
|
152
|
+
vol_flat = vol.flatten()
|
|
153
|
+
amount_flat = amount.flatten()
|
|
154
|
+
industry_arr = np.array([self.industries[i] for i in industry_ids])
|
|
155
|
+
industry_flat = np.repeat(industry_arr, t)
|
|
156
|
+
|
|
157
|
+
df = pl.DataFrame(
|
|
158
|
+
{
|
|
159
|
+
"date": date_arr,
|
|
160
|
+
"code": code_arr,
|
|
161
|
+
"open": open_flat.astype(np.float64),
|
|
162
|
+
"high": high_flat.astype(np.float64),
|
|
163
|
+
"low": low_flat.astype(np.float64),
|
|
164
|
+
"close": close_flat.astype(np.float64),
|
|
165
|
+
"vol": vol_flat.astype(np.float64),
|
|
166
|
+
"amount": amount_flat.astype(np.float64),
|
|
167
|
+
"industry": industry_flat,
|
|
168
|
+
},
|
|
169
|
+
schema={
|
|
170
|
+
"date": pl.Date,
|
|
171
|
+
"code": pl.Utf8,
|
|
172
|
+
"open": pl.Float64,
|
|
173
|
+
"high": pl.Float64,
|
|
174
|
+
"low": pl.Float64,
|
|
175
|
+
"close": pl.Float64,
|
|
176
|
+
"vol": pl.Float64,
|
|
177
|
+
"amount": pl.Float64,
|
|
178
|
+
"industry": pl.Utf8,
|
|
179
|
+
},
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
# 计算前向收益(用于因子 IC 计算)
|
|
183
|
+
df = df.sort(["code", "date"])
|
|
184
|
+
df = df.with_columns(
|
|
185
|
+
(pl.col("close").shift(-1).over("code") / pl.col("close") - 1).alias(
|
|
186
|
+
"forward_return_1d"
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
logger.info(
|
|
191
|
+
"MockDataLoader: generated %s rows (%d stocks × %d days), %d industries",
|
|
192
|
+
f"{df.height:,}",
|
|
193
|
+
n,
|
|
194
|
+
t,
|
|
195
|
+
len(self.industries),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
return df
|
|
199
|
+
|
|
200
|
+
def load_summary(self) -> dict:
|
|
201
|
+
"""加载并返回数据摘要(用于测试与展示)"""
|
|
202
|
+
df = self.load()
|
|
203
|
+
close_mean = df["close"].mean()
|
|
204
|
+
close_std = df["close"].std()
|
|
205
|
+
return {
|
|
206
|
+
"n_rows": df.height,
|
|
207
|
+
"n_stocks": df["code"].n_unique(),
|
|
208
|
+
"n_days": df["date"].n_unique(),
|
|
209
|
+
"industries": sorted(df["industry"].unique().to_list()),
|
|
210
|
+
"date_range": [
|
|
211
|
+
str(df["date"].min()),
|
|
212
|
+
str(df["date"].max()),
|
|
213
|
+
],
|
|
214
|
+
"close_mean": float(close_mean) if close_mean is not None else 0.0,
|
|
215
|
+
"close_std": float(close_std) if close_std is not None else 0.0,
|
|
216
|
+
"amount_total": float(df["amount"].sum()),
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
if __name__ == "__main__":
|
|
221
|
+
loader = MockDataLoader()
|
|
222
|
+
df = loader.load()
|
|
223
|
+
print(df.head())
|
|
224
|
+
print(df.schema)
|
|
225
|
+
print("Rows:", df.height)
|
|
226
|
+
print("Summary:", loader.load_summary())
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
runner.py - Table 4 复现主入口
|
|
4
|
+
|
|
5
|
+
串联 DataLoader + Baseline × 3 + Evaluator,输出 Table4Report。
|
|
6
|
+
支持 Stage 1(mock)与 Stage 2(real,仅替换 loader / llm_client)。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import logging
|
|
13
|
+
import time
|
|
14
|
+
from datetime import datetime, timezone
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
17
|
+
|
|
18
|
+
from .contracts import (
|
|
19
|
+
Baseline,
|
|
20
|
+
DataLoader,
|
|
21
|
+
Evaluator,
|
|
22
|
+
Table4GroupResult,
|
|
23
|
+
Table4Report,
|
|
24
|
+
Table4Runner,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
__all__ = ["MockTable4Runner", "RealTable4Runner"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class MockTable4Runner(Table4Runner):
|
|
33
|
+
"""Stage 1 mock 主入口
|
|
34
|
+
|
|
35
|
+
用法::
|
|
36
|
+
|
|
37
|
+
from QuantNodes.research.quant_alpha.evaluation import (
|
|
38
|
+
MockDataLoader, PolarsAlphaCalculatorEvaluator,
|
|
39
|
+
G1Handcrafted, G2LlmOnly, G3AlphaGpt,
|
|
40
|
+
)
|
|
41
|
+
from QuantNodes.research.quant_alpha.evaluation.runner import MockTable4Runner
|
|
42
|
+
|
|
43
|
+
runner = MockTable4Runner(
|
|
44
|
+
loader=MockDataLoader(n_stocks=500, n_days=500),
|
|
45
|
+
evaluator=PolarsAlphaCalculatorEvaluator(),
|
|
46
|
+
baselines=[G1Handcrafted(n=100), G2LlmOnly(n=50), G3AlphaGpt(n=30)],
|
|
47
|
+
output_dir=Path("data/output/table4_mock"),
|
|
48
|
+
)
|
|
49
|
+
report = runner.run()
|
|
50
|
+
|
|
51
|
+
Stage 2 替换 loader/baselines 即可,runner 无需修改。
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
loader: DataLoader,
|
|
57
|
+
evaluator: Evaluator,
|
|
58
|
+
baselines: Sequence[Baseline],
|
|
59
|
+
output_dir: Optional[Path] = None,
|
|
60
|
+
forward_returns: Optional[List[int]] = None,
|
|
61
|
+
stage: str = "mock",
|
|
62
|
+
notes: Optional[List[str]] = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
self.loader = loader
|
|
65
|
+
self.evaluator = evaluator
|
|
66
|
+
self.baselines = list(baselines)
|
|
67
|
+
self.output_dir = Path(output_dir) if output_dir else None
|
|
68
|
+
self.forward_returns = forward_returns or [1]
|
|
69
|
+
self.stage = stage
|
|
70
|
+
self.notes = list(notes or [])
|
|
71
|
+
|
|
72
|
+
def run(self) -> Table4Report:
|
|
73
|
+
"""执行完整 pipeline"""
|
|
74
|
+
logger.info("[Table4Runner:%s] 开始执行", self.stage)
|
|
75
|
+
started_at = time.time()
|
|
76
|
+
|
|
77
|
+
# 1. 加载数据
|
|
78
|
+
t0 = time.time()
|
|
79
|
+
data = self.loader.load()
|
|
80
|
+
load_elapsed = time.time() - t0
|
|
81
|
+
logger.info(
|
|
82
|
+
"[Table4Runner] 数据加载完成: %s rows, %.2fs",
|
|
83
|
+
f"{data.height:,}" if hasattr(data, "height") else len(data),
|
|
84
|
+
load_elapsed,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# 2. 构造 report
|
|
88
|
+
report = Table4Report(
|
|
89
|
+
timestamp=datetime.now(tz=timezone.utc).isoformat(),
|
|
90
|
+
stage=self.stage,
|
|
91
|
+
notes=self.notes,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# 3. 遍历 baselines
|
|
95
|
+
for baseline in self.baselines:
|
|
96
|
+
group_name = baseline.group_name
|
|
97
|
+
logger.info("[Table4Runner] === %s 开始 ===", group_name)
|
|
98
|
+
|
|
99
|
+
t0 = time.time()
|
|
100
|
+
factors = baseline.generate_factors()
|
|
101
|
+
gen_elapsed = time.time() - t0
|
|
102
|
+
logger.info(
|
|
103
|
+
"[Table4Runner] %s 生成 %d 个因子 (%.2fs)",
|
|
104
|
+
group_name,
|
|
105
|
+
len(factors),
|
|
106
|
+
gen_elapsed,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
t0 = time.time()
|
|
110
|
+
metrics = self.evaluator.evaluate(
|
|
111
|
+
factors, data, forward_returns=self.forward_returns
|
|
112
|
+
)
|
|
113
|
+
eval_elapsed = time.time() - t0
|
|
114
|
+
logger.info(
|
|
115
|
+
"[Table4Runner] %s 评估完成: %d success / %d failed (%.2fs)",
|
|
116
|
+
group_name,
|
|
117
|
+
sum(1 for m in metrics if m.status == "success"),
|
|
118
|
+
sum(1 for m in metrics if m.status == "failed"),
|
|
119
|
+
eval_elapsed,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
group = Table4GroupResult(
|
|
123
|
+
group_name=group_name,
|
|
124
|
+
factors=factors,
|
|
125
|
+
metrics=metrics,
|
|
126
|
+
elapsed_sec=gen_elapsed + eval_elapsed,
|
|
127
|
+
)
|
|
128
|
+
report.add_group(group)
|
|
129
|
+
|
|
130
|
+
total_elapsed = time.time() - started_at
|
|
131
|
+
logger.info("[Table4Runner] 全部完成: %.2fs", total_elapsed)
|
|
132
|
+
|
|
133
|
+
# 4. 输出
|
|
134
|
+
if self.output_dir is not None:
|
|
135
|
+
self.output_dir.mkdir(parents=True, exist_ok=True)
|
|
136
|
+
self.save_json(report, self.output_dir / "table4_report.json")
|
|
137
|
+
self.save_markdown(report, self.output_dir / "table4_report.md")
|
|
138
|
+
|
|
139
|
+
return report
|
|
140
|
+
|
|
141
|
+
def save_json(self, report: Table4Report, path: Path) -> None:
|
|
142
|
+
"""保存为 JSON"""
|
|
143
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
144
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
145
|
+
json.dump(report.to_dict(), f, ensure_ascii=False, indent=2)
|
|
146
|
+
logger.info("[Table4Runner] JSON saved to %s", path)
|
|
147
|
+
|
|
148
|
+
def save_markdown(self, report: Table4Report, path: Path) -> None:
|
|
149
|
+
"""保存为 Markdown 报告"""
|
|
150
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
151
|
+
lines: List[str] = []
|
|
152
|
+
lines.append(f"# Table 4 复现报告({report.stage})\n")
|
|
153
|
+
lines.append(f"**生成时间**: {report.timestamp}\n")
|
|
154
|
+
lines.append("\n## 汇总\n")
|
|
155
|
+
lines.append("| Group | N | Success | Failed | avg IC | avg IR | best IR | elapsed(s) |\n")
|
|
156
|
+
lines.append("|------|--:|--------:|-------:|-------:|-------:|--------:|-----------:|\n")
|
|
157
|
+
for g in report.groups:
|
|
158
|
+
lines.append(
|
|
159
|
+
f"| {g.group_name} | {len(g.factors)} | {g.success_count} | "
|
|
160
|
+
f"{g.failed_count} | {g.avg_ic:.4f} | {g.avg_ir:.4f} | "
|
|
161
|
+
f"{g.best_ir:.4f} | {g.elapsed_sec:.2f} |\n"
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
# 排名
|
|
165
|
+
ranked = report.rank_groups_by_ir()
|
|
166
|
+
lines.append("\n## 按 avg_IR 排名\n")
|
|
167
|
+
for i, g in enumerate(ranked, 1):
|
|
168
|
+
lines.append(f"{i}. **{g.group_name}** — avg_IR = {g.avg_ir:.4f}\n")
|
|
169
|
+
|
|
170
|
+
# 论文对比(Stage 2 填)
|
|
171
|
+
if report.paper_comparison:
|
|
172
|
+
lines.append("\n## 论文 Table 4 对比\n")
|
|
173
|
+
lines.append("| Group | Ours avg_IR | Paper avg_IR | Diff |\n")
|
|
174
|
+
lines.append("|------|------------:|-------------:|-----:|\n")
|
|
175
|
+
for row in report.paper_comparison.get("rows", []):
|
|
176
|
+
lines.append(
|
|
177
|
+
f"| {row['group']} | {row['ours']:.4f} | {row['paper']:.4f} | "
|
|
178
|
+
f"{row['diff']:.4f} |\n"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
if report.notes:
|
|
182
|
+
lines.append("\n## 备注\n")
|
|
183
|
+
for n in report.notes:
|
|
184
|
+
lines.append(f"- {n}\n")
|
|
185
|
+
|
|
186
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
187
|
+
f.writelines(lines)
|
|
188
|
+
logger.info("[Table4Runner] Markdown saved to %s", path)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
if __name__ == "__main__":
|
|
192
|
+
logging.basicConfig(level=logging.INFO)
|
|
193
|
+
from .mock_data_loader import MockDataLoader
|
|
194
|
+
|
|
195
|
+
loader = MockDataLoader(n_stocks=100, n_days=200)
|
|
196
|
+
print("Mock loader summary:", loader.load_summary())
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class RealTable4Runner(MockTable4Runner):
|
|
200
|
+
"""Stage 2 real 主入口
|
|
201
|
+
|
|
202
|
+
与 MockTable4Runner 完全相同的流程,
|
|
203
|
+
仅 stage="real" 和默认输出目录不同。
|
|
204
|
+
|
|
205
|
+
用法::
|
|
206
|
+
|
|
207
|
+
from QuantNodes.research.quant_alpha.evaluation import (
|
|
208
|
+
ClickHouseDataLoader, PolarsAlphaCalculatorEvaluator,
|
|
209
|
+
G1Handcrafted, G2LlmOnly, G3AlphaGpt,
|
|
210
|
+
)
|
|
211
|
+
from QuantNodes.research.quant_alpha.evaluation.runner import RealTable4Runner
|
|
212
|
+
|
|
213
|
+
runner = RealTable4Runner(
|
|
214
|
+
loader=ClickHouseDataLoader(table="quote.stock_quote"),
|
|
215
|
+
evaluator=PolarsAlphaCalculatorEvaluator(),
|
|
216
|
+
baselines=[
|
|
217
|
+
G1Handcrafted(n=100),
|
|
218
|
+
G2LlmOnly(n=50), # 默认使用 LLMGateway → MiniMax
|
|
219
|
+
G3AlphaGpt(n=30), # 默认使用 LLMGateway → MiniMax
|
|
220
|
+
],
|
|
221
|
+
output_dir=Path("data/output/table4_real"),
|
|
222
|
+
)
|
|
223
|
+
report = runner.run()
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
def __init__(
|
|
227
|
+
self,
|
|
228
|
+
loader: DataLoader,
|
|
229
|
+
evaluator: Evaluator,
|
|
230
|
+
baselines: Sequence[Baseline],
|
|
231
|
+
output_dir: Optional[Path] = None,
|
|
232
|
+
forward_returns: Optional[List[int]] = None,
|
|
233
|
+
notes: Optional[List[str]] = None,
|
|
234
|
+
) -> None:
|
|
235
|
+
super().__init__(
|
|
236
|
+
loader=loader,
|
|
237
|
+
evaluator=evaluator,
|
|
238
|
+
baselines=baselines,
|
|
239
|
+
output_dir=output_dir or Path("data/output/table4_real"),
|
|
240
|
+
forward_returns=forward_returns,
|
|
241
|
+
stage="real",
|
|
242
|
+
notes=notes,
|
|
243
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
llm - Alpha-GPT M5 子包(仅 JSON 解析,不含 LLM 调度)
|
|
4
|
+
|
|
5
|
+
LLM 调度复用 nanobot upstream(见 .agent/agents/alpha-gpt-*.md),
|
|
6
|
+
本子包仅提供:
|
|
7
|
+
|
|
8
|
+
- parser.py: 5 阶段 LLM 输出 JSON 三层降级解析器
|
|
9
|
+
- utils: 公式算子白名单校验
|
|
10
|
+
|
|
11
|
+
M5 doc-first 详见:docs/quant_alpha/alpha_gpt_architecture.md
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .parser import (
|
|
15
|
+
ParseResult,
|
|
16
|
+
parse_json_3layer,
|
|
17
|
+
parse_idea_generator_output,
|
|
18
|
+
parse_formula_translator_output,
|
|
19
|
+
parse_evaluator_output,
|
|
20
|
+
parse_reflector_output,
|
|
21
|
+
parse_critic_output,
|
|
22
|
+
validate_formula_operators,
|
|
23
|
+
extract_operators,
|
|
24
|
+
ALLOWED_OPERATORS,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"ParseResult",
|
|
29
|
+
"parse_json_3layer",
|
|
30
|
+
"parse_idea_generator_output",
|
|
31
|
+
"parse_formula_translator_output",
|
|
32
|
+
"parse_evaluator_output",
|
|
33
|
+
"parse_reflector_output",
|
|
34
|
+
"parse_critic_output",
|
|
35
|
+
"validate_formula_operators",
|
|
36
|
+
"extract_operators",
|
|
37
|
+
"ALLOWED_OPERATORS",
|
|
38
|
+
]
|