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,184 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
"""Pydantic 配置模型 / Configuration Models"""
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FactorSetting(BaseModel):
|
|
9
|
+
"""因子配置"""
|
|
10
|
+
name: str = Field(..., description="因子名称")
|
|
11
|
+
factor_dir: str = Field(..., description="因子文件路径")
|
|
12
|
+
factor_key: str = Field(default='', description="H5 key (如因子在 H5 中)")
|
|
13
|
+
format: str = Field(default='h5', description="数据格式: h5/csv/npy/parquet")
|
|
14
|
+
hypothesis: str = Field(default='', description="研究假设 (供 LLM 一致性检查)")
|
|
15
|
+
description: str = Field(default='', description="因子描述 (供 LLM 一致性检查)")
|
|
16
|
+
expression: str = Field(default='', description="代码表达式 (供 LLM 一致性检查)")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TradableSetting(BaseModel):
|
|
20
|
+
"""可交易性配置"""
|
|
21
|
+
no_st: bool = Field(default=True, description="剔除 ST")
|
|
22
|
+
no_suspended: bool = Field(default=True, description="剔除停牌")
|
|
23
|
+
no_up_down_limit: bool = Field(default=False, description="剔除涨跌停")
|
|
24
|
+
min_ipo_days: int = Field(default=360, description="剔除上市不足 N 日的新股")
|
|
25
|
+
trace: Optional[dict] = Field(default=None, description="追踪条件, e.g. {'suspend': (25, 1)}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class PreprocessSetting(BaseModel):
|
|
29
|
+
"""预处理配置
|
|
30
|
+
|
|
31
|
+
T0-2/T0-3 (Phase 3.1):
|
|
32
|
+
- adj_date_beg/end 改 Optional[int]=None (H10 兼容, 启动校验抛错)
|
|
33
|
+
- 新增 3 隐式默认 Pydantic 字段 (mad_n=5.0, pct_low=0.025, pct_high=0.975, M5)
|
|
34
|
+
M12: 新增 i18n_name_map 自定义行业名称映射 (覆盖全局默认 INDUSTRY_MAPPING)
|
|
35
|
+
"""
|
|
36
|
+
adj_date_beg: Optional[int] = Field(
|
|
37
|
+
default=None, description="起始日期 yyyymmdd (H10: None → 启动报错)"
|
|
38
|
+
)
|
|
39
|
+
adj_date_end: Optional[int] = Field(
|
|
40
|
+
default=None, description="截止日期 yyyymmdd (H10: None → 启动报错)"
|
|
41
|
+
)
|
|
42
|
+
adj_mode: list = Field(default=['M', 'end'], description="调仓模式: [mode, position]")
|
|
43
|
+
sample_index: str = Field(default='all', description="样本池: all/HS300/ZZ500/ZZ800/custom")
|
|
44
|
+
sample_index_customdir: Optional[tuple] = Field(
|
|
45
|
+
default=None, description="自定义样本池路径 (sample_index=custom 时必填)"
|
|
46
|
+
)
|
|
47
|
+
sample_industry: str = Field(default='all', description="行业筛选: all/中信行业名")
|
|
48
|
+
tradable: TradableSetting = Field(default_factory=TradableSetting)
|
|
49
|
+
missing: str = Field(default='', description="缺失值处理: ''/ind_avg")
|
|
50
|
+
extreme: str = Field(default='', description="去极值: ''/median/pct_shrink")
|
|
51
|
+
norm: str = Field(default='', description="标准化: ''/zscore/norm")
|
|
52
|
+
industry_neutral: bool = Field(default=False, description="行业中性化")
|
|
53
|
+
risk_neutral: bool = Field(default=False, description="风险因子中性化")
|
|
54
|
+
risk_factors: list = Field(default_factory=list, description="风险因子: [(file, key), ...]")
|
|
55
|
+
# T0-2: 隐式默认从节点 __init__ 提升到 Pydantic 字段
|
|
56
|
+
mad_n: float = Field(default=5.0, description="median winsorize 倍数 (M5)")
|
|
57
|
+
pct_low: float = Field(default=0.025, description="pct_shrink 下分位 (M5)")
|
|
58
|
+
pct_high: float = Field(default=0.975, description="pct_shrink 上分位 (M5)")
|
|
59
|
+
# M12: 自定义行业名称映射 (中文→英文, key=code 列名, value=行业名) → 覆盖全局 INDUSTRY_MAPPING
|
|
60
|
+
i18n_name_map: Optional[dict[str, str]] = Field(
|
|
61
|
+
default=None,
|
|
62
|
+
description="自定义行业名称映射 (key: 列名, value: 显示名) → 覆盖全局 INDUSTRY_MAPPING",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class ICSetting(BaseModel):
|
|
67
|
+
"""IC 分析配置"""
|
|
68
|
+
min_group_size: int = Field(default=5, description="计算 IC 最少需要的因子值数量")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class GroupSetting(BaseModel):
|
|
72
|
+
"""分组分析配置"""
|
|
73
|
+
groups: int = Field(default=5, description="分组数")
|
|
74
|
+
factor_direction: int = Field(default=1, description="因子方向: 1=越大越好, -1=越小越好")
|
|
75
|
+
floor_mode: str = Field(
|
|
76
|
+
default='group', description="数据不足时策略: group=跳过, last=沿用上期"
|
|
77
|
+
)
|
|
78
|
+
hedge: str = Field(default='equal', description="对冲基准: HS300/ZZ500/equal/custom")
|
|
79
|
+
hedge_path: Optional[str] = Field(default=None, description="自定义对冲基准路径")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class LongShortSetting(BaseModel):
|
|
83
|
+
"""多空组合配置"""
|
|
84
|
+
factor_direction: int = Field(default=1, description="因子方向: 1=越大越好, -1=越小越好")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ScoreSetting(BaseModel):
|
|
88
|
+
"""市值行业分层打分配置
|
|
89
|
+
|
|
90
|
+
T0-2 (Phase 3.1): 新增 3 隐式默认 Pydantic 字段
|
|
91
|
+
(n_industries=29, n_size_groups=3, n_quantile_groups=5, H15).
|
|
92
|
+
"""
|
|
93
|
+
enabled: bool = Field(default=True, description="是否运行")
|
|
94
|
+
n_industries: int = Field(default=29, description="行业数 (中信 29 / 申万 30, H15)")
|
|
95
|
+
n_size_groups: int = Field(default=3, description="市值分组数 (H15)")
|
|
96
|
+
n_quantile_groups: int = Field(default=5, description="因子分位数 (H15)")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class RiskCorrelationSetting(BaseModel):
|
|
100
|
+
"""风险因子相关性配置"""
|
|
101
|
+
factors: str = Field(default='all', description="风险因子: 'all' 或 [(file, key), ...]")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class AnalysisSetting(BaseModel):
|
|
105
|
+
"""分析配置"""
|
|
106
|
+
ic: ICSetting = Field(default_factory=ICSetting)
|
|
107
|
+
group: GroupSetting = Field(default_factory=GroupSetting)
|
|
108
|
+
longshort: LongShortSetting = Field(default_factory=LongShortSetting)
|
|
109
|
+
score: ScoreSetting = Field(default_factory=ScoreSetting)
|
|
110
|
+
risk_corr: RiskCorrelationSetting = Field(default_factory=RiskCorrelationSetting)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class OutputSetting(BaseModel):
|
|
114
|
+
"""输出配置"""
|
|
115
|
+
dir: str = Field(default='./output/', description="输出目录")
|
|
116
|
+
format: list = Field(default=['parquet', 'json'], description="输出格式")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class FeedbackSetting(BaseModel):
|
|
120
|
+
"""FactorFeedback 集成配置
|
|
121
|
+
|
|
122
|
+
enabled=False 时, 现有行为完全不变 (向后兼容)。
|
|
123
|
+
enabled=True 时, pipeline_runner 自动包装 5 个分析节点返回为 FactorFeedback,
|
|
124
|
+
聚合到 ctx['Feedback'], 并可选择持久化到 output_dir。
|
|
125
|
+
"""
|
|
126
|
+
enabled: bool = Field(default=False, description="是否启用 FactorFeedback 自动包装")
|
|
127
|
+
output_dir: Optional[str] = Field(
|
|
128
|
+
default=None,
|
|
129
|
+
description="Parquet/JSON 持久化目录 (None=不持久化, 仅返回 ctx)",
|
|
130
|
+
)
|
|
131
|
+
judge_enabled: bool = Field(
|
|
132
|
+
default=False, description="是否启用 LLMJudge (hypothesis↔expression 一致性)"
|
|
133
|
+
)
|
|
134
|
+
judge_model: str = Field(default="mock", description="LLMJudge 模型名 (mock/deepseek-v3/...)")
|
|
135
|
+
judge_max_attempts: int = Field(default=3, description="LLMJudge 解析失败最大重试次数")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class QualityGateConfig(BaseModel):
|
|
139
|
+
"""QualityGate 集成配置 (Week 3)。
|
|
140
|
+
|
|
141
|
+
enabled=False: 不构造 QualityGateNode, 行为不变
|
|
142
|
+
enabled=True: 构造 QualityGateNode, 可在 run_evolution() 中拦截低质量因子
|
|
143
|
+
"""
|
|
144
|
+
enabled: bool = Field(default=False, description="是否启用 QualityGateNode")
|
|
145
|
+
zoo_path: Optional[str] = Field(default=None, description="FactorZoo 路径 (None=内存)")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class EvolutionConfig(BaseModel):
|
|
149
|
+
"""演化主循环配置 (Week 4)。
|
|
150
|
+
|
|
151
|
+
enabled=False: 不演化, run_evolution() 抛错
|
|
152
|
+
enabled=True: 启用多轮演化循环
|
|
153
|
+
"""
|
|
154
|
+
enabled: bool = Field(default=False, description="是否启用演化模式")
|
|
155
|
+
max_rounds: int = Field(default=3, description="演化总轮数 (不含 round 0 原始)")
|
|
156
|
+
parents_per_round: int = Field(default=1, description="每轮选几个 parent (crossover 时强制 2)")
|
|
157
|
+
parent_selection_strategy: str = Field(
|
|
158
|
+
default="top_percent_plus_random",
|
|
159
|
+
description="选择策略: best/random/weighted/weighted_inverse/top_percent_plus_random",
|
|
160
|
+
)
|
|
161
|
+
top_percent_threshold: float = Field(default=0.3, description="top_percent_plus_random 阈值")
|
|
162
|
+
metric: str = Field(default="sharpe", description="用于排序/加权的指标")
|
|
163
|
+
pool_dir: Optional[str] = Field(
|
|
164
|
+
default=None, description="TrajectoryPool 路径 (None=output.dir/trajectory)"
|
|
165
|
+
)
|
|
166
|
+
early_stop_patience: int = Field(default=0, description="连续 N 轮无改善则停 (0=不启用)")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class SingleFactorTestConfig(BaseModel):
|
|
170
|
+
"""单因子回测完整配置"""
|
|
171
|
+
factor: FactorSetting
|
|
172
|
+
preprocess: PreprocessSetting
|
|
173
|
+
analysis: AnalysisSetting = Field(default_factory=AnalysisSetting)
|
|
174
|
+
output: OutputSetting = Field(default_factory=OutputSetting)
|
|
175
|
+
feedback: FeedbackSetting = Field(default_factory=FeedbackSetting)
|
|
176
|
+
quality_gate: QualityGateConfig = Field(default_factory=QualityGateConfig)
|
|
177
|
+
evolution: EvolutionConfig = Field(default_factory=EvolutionConfig)
|
|
178
|
+
data_path: str = Field(default='./testdata/test_h5_new/', description="数据根目录")
|
|
179
|
+
load_keys: list = Field(
|
|
180
|
+
# M7: 默认含 tradability filter 必需键 (st/suspend/ud_limit/ipo_days)
|
|
181
|
+
default=['stklist', 'trade_dt', 'cp', 'id_citic1', 'mv_float',
|
|
182
|
+
'st', 'suspend', 'ud_limit', 'ipo_days'],
|
|
183
|
+
description="需要加载的数据 key 列表"
|
|
184
|
+
)
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
"""SingleFactorTestConfig 流式构造器 / Config Builder (Phase 3.4)
|
|
3
|
+
|
|
4
|
+
``SingleFactorTestConfig`` 是深度嵌套的 pydantic 模型 (factor / preprocess /
|
|
5
|
+
analysis{ic,group,longshort,score,risk_corr} / output / feedback /
|
|
6
|
+
quality_gate / evolution)。手工构造冗长易错 (e.g.
|
|
7
|
+
``run_evolution_e2e._build_config`` 37 行嵌套)。
|
|
8
|
+
|
|
9
|
+
``SingleFactorTestConfigBuilder`` 提供流式 API 扁平化常用字段:
|
|
10
|
+
|
|
11
|
+
cfg = (
|
|
12
|
+
SingleFactorTestConfigBuilder()
|
|
13
|
+
.factor("mom20", "mom20.h5", hypothesis="momentum")
|
|
14
|
+
.dates(20240101, 20241231)
|
|
15
|
+
.preprocess(extreme="median", norm="zscore")
|
|
16
|
+
.groups(5, direction=1)
|
|
17
|
+
.output("./out/", fmt=["json"])
|
|
18
|
+
.data_path("./data/")
|
|
19
|
+
.build()
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
设计要点:
|
|
23
|
+
- 每个 setter 返回 ``self`` 支持链式
|
|
24
|
+
- 默认值全部委托各 ``*Setting`` 的 pydantic 默认 (单一真值源, 不重复)
|
|
25
|
+
- ``build()`` 时统一构造 pydantic 模型并触发校验 (缺必填如 factor 即报错)
|
|
26
|
+
- 不改 ``SingleFactorTestConfig`` / ``config.py``; 现有直接构造方式不变
|
|
27
|
+
"""
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
from typing import Any, Optional
|
|
31
|
+
|
|
32
|
+
from QuantNodes.research.factor_test.config import (
|
|
33
|
+
AnalysisSetting,
|
|
34
|
+
EvolutionConfig,
|
|
35
|
+
FactorSetting,
|
|
36
|
+
FeedbackSetting,
|
|
37
|
+
GroupSetting,
|
|
38
|
+
ICSetting,
|
|
39
|
+
LongShortSetting,
|
|
40
|
+
OutputSetting,
|
|
41
|
+
PreprocessSetting,
|
|
42
|
+
QualityGateConfig,
|
|
43
|
+
RiskCorrelationSetting,
|
|
44
|
+
ScoreSetting,
|
|
45
|
+
SingleFactorTestConfig,
|
|
46
|
+
TradableSetting,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _clean(kwargs: dict) -> dict:
|
|
51
|
+
"""剔除值为 None 的项, 让 pydantic 默认值生效 (单一真值源)。"""
|
|
52
|
+
return {k: v for k, v in kwargs.items() if v is not None}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class SingleFactorTestConfigBuilder:
|
|
56
|
+
"""流式构造 ``SingleFactorTestConfig``。
|
|
57
|
+
|
|
58
|
+
所有 setter 仅记录非 None 字段; ``build()`` 时聚合为 pydantic 模型,
|
|
59
|
+
缺省字段沿用各 ``*Setting`` 的默认值。
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __init__(self) -> None:
|
|
63
|
+
self._factor: Optional[dict] = None
|
|
64
|
+
self._preprocess: dict = {}
|
|
65
|
+
self._tradable: Optional[dict] = None
|
|
66
|
+
self._ic: dict = {}
|
|
67
|
+
self._group: dict = {}
|
|
68
|
+
self._longshort: dict = {}
|
|
69
|
+
self._score: dict = {}
|
|
70
|
+
self._risk_corr: dict = {}
|
|
71
|
+
self._output: dict = {}
|
|
72
|
+
self._feedback: dict = {}
|
|
73
|
+
self._quality_gate: dict = {}
|
|
74
|
+
self._evolution: dict = {}
|
|
75
|
+
self._top: dict = {}
|
|
76
|
+
|
|
77
|
+
# ── factor ────────────────────────────────────────────────
|
|
78
|
+
def factor(
|
|
79
|
+
self,
|
|
80
|
+
name: str,
|
|
81
|
+
factor_dir: str,
|
|
82
|
+
*,
|
|
83
|
+
factor_key: Optional[str] = None,
|
|
84
|
+
fmt: Optional[str] = None,
|
|
85
|
+
hypothesis: Optional[str] = None,
|
|
86
|
+
description: Optional[str] = None,
|
|
87
|
+
expression: Optional[str] = None,
|
|
88
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
89
|
+
self._factor = _clean({
|
|
90
|
+
"name": name,
|
|
91
|
+
"factor_dir": factor_dir,
|
|
92
|
+
"factor_key": factor_key,
|
|
93
|
+
"format": fmt,
|
|
94
|
+
"hypothesis": hypothesis,
|
|
95
|
+
"description": description,
|
|
96
|
+
"expression": expression,
|
|
97
|
+
})
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
# ── preprocess ────────────────────────────────────────────
|
|
101
|
+
def dates(self, beg: int, end: int) -> "SingleFactorTestConfigBuilder":
|
|
102
|
+
self._preprocess["adj_date_beg"] = beg
|
|
103
|
+
self._preprocess["adj_date_end"] = end
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
def adj_mode(self, mode: list) -> "SingleFactorTestConfigBuilder":
|
|
107
|
+
self._preprocess["adj_mode"] = mode
|
|
108
|
+
return self
|
|
109
|
+
|
|
110
|
+
def sample(
|
|
111
|
+
self,
|
|
112
|
+
index: Optional[str] = None,
|
|
113
|
+
industry: Optional[str] = None,
|
|
114
|
+
*,
|
|
115
|
+
index_customdir: Optional[tuple] = None,
|
|
116
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
117
|
+
self._preprocess.update(_clean({
|
|
118
|
+
"sample_index": index,
|
|
119
|
+
"sample_industry": industry,
|
|
120
|
+
"sample_index_customdir": index_customdir,
|
|
121
|
+
}))
|
|
122
|
+
return self
|
|
123
|
+
|
|
124
|
+
def preprocess(
|
|
125
|
+
self,
|
|
126
|
+
*,
|
|
127
|
+
missing: Optional[str] = None,
|
|
128
|
+
extreme: Optional[str] = None,
|
|
129
|
+
norm: Optional[str] = None,
|
|
130
|
+
mad_n: Optional[float] = None,
|
|
131
|
+
pct_low: Optional[float] = None,
|
|
132
|
+
pct_high: Optional[float] = None,
|
|
133
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
134
|
+
self._preprocess.update(_clean({
|
|
135
|
+
"missing": missing,
|
|
136
|
+
"extreme": extreme,
|
|
137
|
+
"norm": norm,
|
|
138
|
+
"mad_n": mad_n,
|
|
139
|
+
"pct_low": pct_low,
|
|
140
|
+
"pct_high": pct_high,
|
|
141
|
+
}))
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
def neutralize(
|
|
145
|
+
self,
|
|
146
|
+
*,
|
|
147
|
+
industry: Optional[bool] = None,
|
|
148
|
+
risk: Optional[bool] = None,
|
|
149
|
+
risk_factors: Optional[list] = None,
|
|
150
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
151
|
+
self._preprocess.update(_clean({
|
|
152
|
+
"industry_neutral": industry,
|
|
153
|
+
"risk_neutral": risk,
|
|
154
|
+
"risk_factors": risk_factors,
|
|
155
|
+
}))
|
|
156
|
+
return self
|
|
157
|
+
|
|
158
|
+
def tradable(self, **kwargs: Any) -> "SingleFactorTestConfigBuilder":
|
|
159
|
+
self._tradable = dict(kwargs)
|
|
160
|
+
return self
|
|
161
|
+
|
|
162
|
+
# ── analysis ──────────────────────────────────────────────
|
|
163
|
+
def ic(self, *, min_group_size: Optional[int] = None) -> "SingleFactorTestConfigBuilder":
|
|
164
|
+
self._ic.update(_clean({"min_group_size": min_group_size}))
|
|
165
|
+
return self
|
|
166
|
+
|
|
167
|
+
def groups(
|
|
168
|
+
self,
|
|
169
|
+
n: Optional[int] = None,
|
|
170
|
+
*,
|
|
171
|
+
direction: Optional[int] = None,
|
|
172
|
+
floor_mode: Optional[str] = None,
|
|
173
|
+
hedge: Optional[str] = None,
|
|
174
|
+
hedge_path: Optional[str] = None,
|
|
175
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
176
|
+
self._group.update(_clean({
|
|
177
|
+
"groups": n,
|
|
178
|
+
"factor_direction": direction,
|
|
179
|
+
"floor_mode": floor_mode,
|
|
180
|
+
"hedge": hedge,
|
|
181
|
+
"hedge_path": hedge_path,
|
|
182
|
+
}))
|
|
183
|
+
return self
|
|
184
|
+
|
|
185
|
+
def longshort(self, *, direction: Optional[int] = None) -> "SingleFactorTestConfigBuilder":
|
|
186
|
+
self._longshort.update(_clean({"factor_direction": direction}))
|
|
187
|
+
return self
|
|
188
|
+
|
|
189
|
+
def score(
|
|
190
|
+
self,
|
|
191
|
+
*,
|
|
192
|
+
enabled: Optional[bool] = None,
|
|
193
|
+
n_industries: Optional[int] = None,
|
|
194
|
+
n_size_groups: Optional[int] = None,
|
|
195
|
+
n_quantile_groups: Optional[int] = None,
|
|
196
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
197
|
+
self._score.update(_clean({
|
|
198
|
+
"enabled": enabled,
|
|
199
|
+
"n_industries": n_industries,
|
|
200
|
+
"n_size_groups": n_size_groups,
|
|
201
|
+
"n_quantile_groups": n_quantile_groups,
|
|
202
|
+
}))
|
|
203
|
+
return self
|
|
204
|
+
|
|
205
|
+
def risk_corr(self, factors: Any = None) -> "SingleFactorTestConfigBuilder":
|
|
206
|
+
if factors is not None:
|
|
207
|
+
self._risk_corr["factors"] = factors
|
|
208
|
+
return self
|
|
209
|
+
|
|
210
|
+
# ── output / feedback / quality_gate / evolution ─────────
|
|
211
|
+
def output(
|
|
212
|
+
self,
|
|
213
|
+
dir: Optional[str] = None,
|
|
214
|
+
*,
|
|
215
|
+
fmt: Optional[list] = None,
|
|
216
|
+
) -> "SingleFactorTestConfigBuilder":
|
|
217
|
+
self._output.update(_clean({"dir": dir, "format": fmt}))
|
|
218
|
+
return self
|
|
219
|
+
|
|
220
|
+
def feedback(self, **kwargs: Any) -> "SingleFactorTestConfigBuilder":
|
|
221
|
+
self._feedback.update(kwargs)
|
|
222
|
+
return self
|
|
223
|
+
|
|
224
|
+
def quality_gate(self, **kwargs: Any) -> "SingleFactorTestConfigBuilder":
|
|
225
|
+
self._quality_gate.update(kwargs)
|
|
226
|
+
return self
|
|
227
|
+
|
|
228
|
+
def evolution(self, **kwargs: Any) -> "SingleFactorTestConfigBuilder":
|
|
229
|
+
self._evolution.update(kwargs)
|
|
230
|
+
return self
|
|
231
|
+
|
|
232
|
+
# ── top-level ─────────────────────────────────────────────
|
|
233
|
+
def data_path(self, path: str) -> "SingleFactorTestConfigBuilder":
|
|
234
|
+
self._top["data_path"] = path
|
|
235
|
+
return self
|
|
236
|
+
|
|
237
|
+
def load_keys(self, keys: list) -> "SingleFactorTestConfigBuilder":
|
|
238
|
+
self._top["load_keys"] = keys
|
|
239
|
+
return self
|
|
240
|
+
|
|
241
|
+
# ── build ─────────────────────────────────────────────────
|
|
242
|
+
def build(self) -> SingleFactorTestConfig:
|
|
243
|
+
"""聚合并构造 SingleFactorTestConfig (触发 pydantic 校验)。
|
|
244
|
+
|
|
245
|
+
Raises:
|
|
246
|
+
ValueError: 未设置 factor (name/factor_dir 必填)。
|
|
247
|
+
pydantic.ValidationError: 字段校验失败。
|
|
248
|
+
"""
|
|
249
|
+
if self._factor is None:
|
|
250
|
+
raise ValueError(
|
|
251
|
+
"factor is required: call .factor(name, factor_dir) before build()"
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
preprocess = dict(self._preprocess)
|
|
255
|
+
if self._tradable is not None:
|
|
256
|
+
preprocess["tradable"] = TradableSetting(**self._tradable)
|
|
257
|
+
|
|
258
|
+
analysis = AnalysisSetting(
|
|
259
|
+
ic=ICSetting(**self._ic),
|
|
260
|
+
group=GroupSetting(**self._group),
|
|
261
|
+
longshort=LongShortSetting(**self._longshort),
|
|
262
|
+
score=ScoreSetting(**self._score),
|
|
263
|
+
risk_corr=RiskCorrelationSetting(**self._risk_corr),
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
kwargs: dict = {
|
|
267
|
+
"factor": FactorSetting(**self._factor),
|
|
268
|
+
"preprocess": PreprocessSetting(**preprocess),
|
|
269
|
+
"analysis": analysis,
|
|
270
|
+
"output": OutputSetting(**self._output),
|
|
271
|
+
"feedback": FeedbackSetting(**self._feedback),
|
|
272
|
+
"quality_gate": QualityGateConfig(**self._quality_gate),
|
|
273
|
+
"evolution": EvolutionConfig(**self._evolution),
|
|
274
|
+
}
|
|
275
|
+
kwargs.update(self._top)
|
|
276
|
+
return SingleFactorTestConfig(**kwargs)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
"""E2E 数据准备 — 生成 H5 格式合成数据, 模拟 iFinD 真实数据结构。
|
|
3
|
+
|
|
4
|
+
输出目录结构 (符合 LoadDataNode 期望):
|
|
5
|
+
{output_dir}/
|
|
6
|
+
├── stk_daily.h5 # 股票日数据
|
|
7
|
+
│ ├── cp # 收盘价
|
|
8
|
+
│ ├── st # ST 标记
|
|
9
|
+
│ ├── suspend # 停牌
|
|
10
|
+
│ ├── ud_limit # 涨跌停
|
|
11
|
+
│ ├── ipo_days # 上市天数
|
|
12
|
+
│ ├── id_citic1 # 行业
|
|
13
|
+
│ └── mv_float # 自由流通市值
|
|
14
|
+
├── index_daily.h5 # 指数日数据
|
|
15
|
+
│ ├── index_cp # 指数收盘价
|
|
16
|
+
│ └── ...
|
|
17
|
+
├── stklist.h5
|
|
18
|
+
├── trade_dt.h5
|
|
19
|
+
└── {factor_name}.h5 # 因子数据 (如 momentum_20d)
|
|
20
|
+
|
|
21
|
+
用法:
|
|
22
|
+
python -m QuantNodes.research.factor_test.e2e.data_prep \\
|
|
23
|
+
--output-dir /tmp/e2e_data/ \\
|
|
24
|
+
--n-days 120 --n-stocks 30 \\
|
|
25
|
+
--factors momentum_20d,reversal_5d,volatility_60d
|
|
26
|
+
"""
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import argparse
|
|
30
|
+
from datetime import datetime, timedelta
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
import numpy as np
|
|
34
|
+
import pandas as pd
|
|
35
|
+
from QuantNodes.core.path_utils import ensure_dir
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _gen_factor_data(rng: np.random.RandomState, n_days: int, n_stocks: int,
|
|
39
|
+
name: str) -> pd.DataFrame:
|
|
40
|
+
"""生成特定形态的因子值 (与名称挂钩, 让不同因子有不同 IC)。"""
|
|
41
|
+
dates = _gen_dates(n_days)
|
|
42
|
+
stocks = _gen_stocks(n_stocks)
|
|
43
|
+
if "momentum" in name.lower():
|
|
44
|
+
# 因子值与未来收益正相关 (正 IC)
|
|
45
|
+
trend = np.linspace(0, 0.5, n_days).reshape(-1, 1)
|
|
46
|
+
base = rng.randn(n_days, n_stocks) + trend
|
|
47
|
+
elif "reversal" in name.lower():
|
|
48
|
+
# 因子值与未来收益负相关 (负 IC)
|
|
49
|
+
trend = -np.linspace(0, 0.5, n_days).reshape(-1, 1)
|
|
50
|
+
base = rng.randn(n_days, n_stocks) + trend
|
|
51
|
+
elif "volatility" in name.lower():
|
|
52
|
+
# 因子值与波动率相关 (弱 IC)
|
|
53
|
+
base = rng.randn(n_days, n_stocks) * 0.5
|
|
54
|
+
else:
|
|
55
|
+
# 默认: 随机因子 (无 IC)
|
|
56
|
+
base = rng.randn(n_days, n_stocks)
|
|
57
|
+
return pd.DataFrame(base, index=dates, columns=stocks)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _gen_dates(n_days: int) -> list[int]:
|
|
61
|
+
# H11: 不再硬编码 '2026-01-04', 默认从 1 年前开始 (滚动)
|
|
62
|
+
start_date = (datetime.now() - timedelta(days=365)).strftime('%Y-%m-%d')
|
|
63
|
+
return [int(d.strftime('%Y%m%d'))
|
|
64
|
+
for d in pd.bdate_range(start_date, periods=n_days)]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _gen_stocks(n_stocks: int) -> list[int]:
|
|
68
|
+
return list(range(100001, 100001 + n_stocks))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _gen_index_cp(rng: np.random.RandomState, n_days: int) -> pd.DataFrame:
|
|
72
|
+
"""沪深 300 + 中证 500 指数收盘价。"""
|
|
73
|
+
dates = _gen_dates(n_days)
|
|
74
|
+
return pd.DataFrame({
|
|
75
|
+
'000300.SH': 3500 + np.cumsum(rng.randn(n_days) * 10),
|
|
76
|
+
'000905.SH': 6000 + np.cumsum(rng.randn(n_days) * 15),
|
|
77
|
+
}, index=dates)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _gen_stk_daily(rng: np.random.RandomState, n_days: int, n_stocks: int) -> dict:
|
|
81
|
+
"""生成 stk_daily.h5 的所有 key。"""
|
|
82
|
+
dates = _gen_dates(n_days)
|
|
83
|
+
stocks = _gen_stocks(n_stocks)
|
|
84
|
+
# 收盘价: 几何布朗运动
|
|
85
|
+
price = 100 * np.exp(np.cumsum(rng.randn(n_days, n_stocks) * 0.02, axis=0))
|
|
86
|
+
# 行业 (申万一级 1-30)
|
|
87
|
+
industry = rng.randint(1, 31, (n_days, n_stocks))
|
|
88
|
+
# 自由流通市值
|
|
89
|
+
mv = rng.lognormal(10, 1, (n_days, n_stocks))
|
|
90
|
+
# ST / 停牌 / 涨跌停 — 稀疏
|
|
91
|
+
st = np.zeros((n_days, n_stocks), dtype=int)
|
|
92
|
+
st[:, :min(2, n_stocks)] = 1
|
|
93
|
+
suspend = np.zeros((n_days, n_stocks), dtype=int)
|
|
94
|
+
if n_stocks > 3:
|
|
95
|
+
suspend[5:8, 3] = 1
|
|
96
|
+
ud_limit = np.zeros((n_days, n_stocks), dtype=int)
|
|
97
|
+
if n_stocks > 5:
|
|
98
|
+
ud_limit[10:12, 5] = 1
|
|
99
|
+
# 上市天数 (>360 不剔除)
|
|
100
|
+
ipo_days = np.ones((n_days, n_stocks), dtype=int) * 500
|
|
101
|
+
ipo_days[0, 0] = 100 # 第一只新股, 会被 IPO < 360 剔除
|
|
102
|
+
return {
|
|
103
|
+
"cp": pd.DataFrame(price, index=dates, columns=stocks),
|
|
104
|
+
"st": pd.DataFrame(st, index=dates, columns=stocks),
|
|
105
|
+
"suspend": pd.DataFrame(suspend, index=dates, columns=stocks),
|
|
106
|
+
"ud_limit": pd.DataFrame(ud_limit, index=dates, columns=stocks),
|
|
107
|
+
"ipo_days": pd.DataFrame(ipo_days, index=dates, columns=stocks),
|
|
108
|
+
"id_citic1": pd.DataFrame(industry, index=dates, columns=stocks),
|
|
109
|
+
"mv_float": pd.DataFrame(mv, index=dates, columns=stocks),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def main():
|
|
114
|
+
parser = argparse.ArgumentParser(description="E2E 数据准备")
|
|
115
|
+
parser.add_argument("--output-dir", required=True, help="输出目录")
|
|
116
|
+
parser.add_argument("--n-days", type=int, default=120, help="天数 (默认 120)")
|
|
117
|
+
parser.add_argument("--n-stocks", type=int, default=30, help="股票数 (默认 30)")
|
|
118
|
+
parser.add_argument("--factors", default="momentum_20d,reversal_5d,volatility_60d",
|
|
119
|
+
help="逗号分隔的因子列表")
|
|
120
|
+
parser.add_argument("--seed", type=int, default=42, help="随机种子")
|
|
121
|
+
args = parser.parse_args()
|
|
122
|
+
|
|
123
|
+
out = Path(args.output_dir)
|
|
124
|
+
ensure_dir(out)
|
|
125
|
+
rng = np.random.RandomState(args.seed)
|
|
126
|
+
n_days, n_stocks = args.n_days, args.n_stocks
|
|
127
|
+
factors = [f.strip() for f in args.factors.split(",") if f.strip()]
|
|
128
|
+
|
|
129
|
+
print(f"生成数据: {n_days} 天 × {n_stocks} 股票, 因子={factors}")
|
|
130
|
+
print(f"输出目录: {out}")
|
|
131
|
+
|
|
132
|
+
# 1. stklist / trade_dt
|
|
133
|
+
dates = _gen_dates(n_days)
|
|
134
|
+
stocks = _gen_stocks(n_stocks)
|
|
135
|
+
pd.DataFrame(stocks, columns=[0]).to_hdf(out / "stklist.h5", key="data", mode="w")
|
|
136
|
+
pd.DataFrame(dates, columns=[0]).to_hdf(out / "trade_dt.h5", key="data", mode="w")
|
|
137
|
+
print(f" ✓ stklist.h5, trade_dt.h5 ({len(stocks)} stocks × {len(dates)} dates)")
|
|
138
|
+
|
|
139
|
+
# 2. stk_daily.h5
|
|
140
|
+
stk_daily = _gen_stk_daily(rng, n_days, n_stocks)
|
|
141
|
+
with pd.HDFStore(out / "stk_daily.h5", mode="w") as store:
|
|
142
|
+
for key, df in stk_daily.items():
|
|
143
|
+
store.put(key, df, format="table")
|
|
144
|
+
print(f" ✓ stk_daily.h5 ({len(stk_daily)} keys)")
|
|
145
|
+
|
|
146
|
+
# 3. index_daily.h5
|
|
147
|
+
index_cp = _gen_index_cp(rng, n_days)
|
|
148
|
+
with pd.HDFStore(out / "index_daily.h5", mode="w") as store:
|
|
149
|
+
store.put("index_cp", index_cp, format="table")
|
|
150
|
+
print(f" ✓ index_daily.h5 (index_cp: {index_cp.shape})")
|
|
151
|
+
|
|
152
|
+
# 4. 因子 H5 (LoadDataNode 用 factor_dir 加载)
|
|
153
|
+
for fname in factors:
|
|
154
|
+
factor = _gen_factor_data(rng, n_days, n_stocks, fname)
|
|
155
|
+
factor.to_hdf(out / f"{fname}.h5", key="data", mode="w")
|
|
156
|
+
print(f" ✓ {fname}.h5 (shape: {factor.shape})")
|
|
157
|
+
|
|
158
|
+
print("\n✓ 数据准备完成")
|
|
159
|
+
print(f" data_path: {out}")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
if __name__ == "__main__":
|
|
163
|
+
main()
|