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,289 @@
|
|
|
1
|
+
"""Evolution Operators — LLM-based + mock implementation.
|
|
2
|
+
|
|
3
|
+
3 operators:
|
|
4
|
+
- Hypothesizer: 从 research direction 生成新因子候选 (round 0)
|
|
5
|
+
- Mutator: 从 parent 因子派生 mutation 子代
|
|
6
|
+
- Crosser: 从两个 parent 因子组合 crossover 子代
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import re
|
|
12
|
+
import uuid
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from typing import Callable, Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class FactorCandidate:
|
|
19
|
+
"""因子候选 — EvolutionLoop 与 PipelineRunner 之间传递的最小单位。"""
|
|
20
|
+
factor_id: str
|
|
21
|
+
name: str
|
|
22
|
+
expression: str
|
|
23
|
+
hypothesis: str = ""
|
|
24
|
+
description: str = ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_HYPOTHESIZE_PROMPT = (
|
|
28
|
+
"你是一个量化研究员, 负责基于研究假设生成 alpha 因子。\n"
|
|
29
|
+
"研究假设: {hypothesis}\n"
|
|
30
|
+
"现有描述: {description}\n\n"
|
|
31
|
+
"请生成一个可执行的因子表达式 "
|
|
32
|
+
"(Python 语法, 引用基础特征: "
|
|
33
|
+
"open/high/low/close/volume/amount/vwap/turnover/mv_float)。\n"
|
|
34
|
+
"返回 JSON: {{\"name\": \"因子名\", \"expression\": \"代码表达式\", "
|
|
35
|
+
"\"description\": \"因子描述\"}}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_MUTATE_PROMPT = """你是一个量化研究员, 负责对父因子做变异, 探索新变体。
|
|
40
|
+
父因子: {parent_expression}
|
|
41
|
+
父假设: {parent_hypothesis}
|
|
42
|
+
父描述: {parent_description}
|
|
43
|
+
|
|
44
|
+
请生成一个变异版本 (在保持核心逻辑前提下, 调整参数 / 调换算子 / 增加过滤)。
|
|
45
|
+
返回 JSON: {{"name": "新因子名", "expression": "新表达式", "description": "新描述"}}"""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
_CROSSOVER_PROMPT = """你是一个量化研究员, 负责组合两个父因子产生新组合。
|
|
49
|
+
父因子 1: {p1_expression} ({p1_description})
|
|
50
|
+
父因子 2: {p2_expression} ({p2_description})
|
|
51
|
+
|
|
52
|
+
请生成一个组合 (可加可减可相乘可平均), 保持经济意义。
|
|
53
|
+
返回 JSON: {{"name": "组合因子名", "expression": "组合表达式", "description": "组合描述"}}"""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BaseOperator:
|
|
57
|
+
"""Operator 基类, 统一 LLM 调用协议。"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
model: str = "mock",
|
|
62
|
+
max_correction_attempts: int = 3,
|
|
63
|
+
seed: int = 42,
|
|
64
|
+
llm_callable: Optional[Callable] = None,
|
|
65
|
+
):
|
|
66
|
+
self.model = model
|
|
67
|
+
self.max_correction_attempts = max_correction_attempts
|
|
68
|
+
self.seed = seed
|
|
69
|
+
if llm_callable is None and model != "mock":
|
|
70
|
+
raise ValueError(
|
|
71
|
+
f"model={model!r} requires an explicit llm_callable. "
|
|
72
|
+
"Inject via get_llm_gateway() at the call site."
|
|
73
|
+
)
|
|
74
|
+
self._llm_callable = llm_callable
|
|
75
|
+
|
|
76
|
+
def _call(self, prompt: str) -> str:
|
|
77
|
+
if self._llm_callable is not None:
|
|
78
|
+
return self._llm_callable(prompt)
|
|
79
|
+
if self.model == "mock":
|
|
80
|
+
return json.dumps(_mock_variant(prompt))
|
|
81
|
+
raise NotImplementedError(
|
|
82
|
+
"真实 LLM 未实现, 请提供 llm_callable 或使用 model='mock'"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Hypothesizer(BaseOperator):
|
|
87
|
+
"""从研究假设生成初始因子 (round 0)。"""
|
|
88
|
+
|
|
89
|
+
def __init__(
|
|
90
|
+
self, *args, knowledge_base=None, rag_top_k: int = 3,
|
|
91
|
+
max_ancestor_depth: int = 2, max_descendant_depth: int = 2,
|
|
92
|
+
use_compress: bool = False, compressor=None,
|
|
93
|
+
**kwargs,
|
|
94
|
+
):
|
|
95
|
+
super().__init__(*args, **kwargs)
|
|
96
|
+
from ..knowledge import Compressor, KnowledgeBase
|
|
97
|
+
self.knowledge_base: KnowledgeBase | None = knowledge_base
|
|
98
|
+
self.rag_top_k = rag_top_k
|
|
99
|
+
self.max_ancestor_depth = max_ancestor_depth
|
|
100
|
+
self.max_descendant_depth = max_descendant_depth
|
|
101
|
+
self.use_compress = use_compress
|
|
102
|
+
self.compressor = compressor if compressor is not None else (
|
|
103
|
+
Compressor(model="mock") if use_compress else None
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def hypothesize(
|
|
107
|
+
self,
|
|
108
|
+
direction: str,
|
|
109
|
+
description: str = "",
|
|
110
|
+
) -> FactorCandidate:
|
|
111
|
+
# RAG: 若有 KB, 构造带历史示例的 prompt
|
|
112
|
+
if self.knowledge_base is not None and len(self.knowledge_base) > 0:
|
|
113
|
+
from ..knowledge import build_rag_prompt
|
|
114
|
+
prompt = build_rag_prompt(
|
|
115
|
+
direction=direction,
|
|
116
|
+
description=description,
|
|
117
|
+
kb=self.knowledge_base,
|
|
118
|
+
top_k=self.rag_top_k,
|
|
119
|
+
max_ancestor_depth=self.max_ancestor_depth,
|
|
120
|
+
max_descendant_depth=self.max_descendant_depth,
|
|
121
|
+
use_compress=self.use_compress,
|
|
122
|
+
compressor=self.compressor,
|
|
123
|
+
)
|
|
124
|
+
else:
|
|
125
|
+
prompt = _HYPOTHESIZE_PROMPT.format(
|
|
126
|
+
hypothesis=direction,
|
|
127
|
+
description=description,
|
|
128
|
+
)
|
|
129
|
+
for attempt in range(self.max_correction_attempts + 1):
|
|
130
|
+
try:
|
|
131
|
+
raw = self._call(prompt)
|
|
132
|
+
data = json.loads(raw)
|
|
133
|
+
return FactorCandidate(
|
|
134
|
+
factor_id=str(uuid.uuid4()),
|
|
135
|
+
name=str(data.get("name", f"h_{direction[:8]}")),
|
|
136
|
+
expression=str(data["expression"]),
|
|
137
|
+
hypothesis=direction,
|
|
138
|
+
description=str(data.get("description", description)),
|
|
139
|
+
)
|
|
140
|
+
except (json.JSONDecodeError, KeyError, TypeError):
|
|
141
|
+
if attempt == self.max_correction_attempts:
|
|
142
|
+
# 兜底: 用 mock 直接生成
|
|
143
|
+
data = _mock_variant(prompt)
|
|
144
|
+
return FactorCandidate(
|
|
145
|
+
factor_id=str(uuid.uuid4()),
|
|
146
|
+
name=str(data.get("name", f"h_{direction[:8]}")),
|
|
147
|
+
expression=str(data["expression"]),
|
|
148
|
+
hypothesis=direction,
|
|
149
|
+
description=str(data.get("description", description)),
|
|
150
|
+
)
|
|
151
|
+
continue
|
|
152
|
+
raise RuntimeError("unreachable") # for type checker
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class Mutator(BaseOperator):
|
|
156
|
+
"""从单个 parent 生成 mutation 子代。"""
|
|
157
|
+
|
|
158
|
+
def mutate(self, parent: FactorCandidate) -> FactorCandidate:
|
|
159
|
+
prompt = _MUTATE_PROMPT.format(
|
|
160
|
+
parent_expression=parent.expression,
|
|
161
|
+
parent_hypothesis=parent.hypothesis,
|
|
162
|
+
parent_description=parent.description,
|
|
163
|
+
)
|
|
164
|
+
for attempt in range(self.max_correction_attempts + 1):
|
|
165
|
+
try:
|
|
166
|
+
raw = self._call(prompt)
|
|
167
|
+
data = json.loads(raw)
|
|
168
|
+
return FactorCandidate(
|
|
169
|
+
factor_id=str(uuid.uuid4()),
|
|
170
|
+
name=str(data.get("name", f"m_{parent.name}")),
|
|
171
|
+
expression=str(data["expression"]),
|
|
172
|
+
hypothesis=parent.hypothesis,
|
|
173
|
+
description=str(data.get("description", parent.description)),
|
|
174
|
+
)
|
|
175
|
+
except (json.JSONDecodeError, KeyError, TypeError):
|
|
176
|
+
if attempt == self.max_correction_attempts:
|
|
177
|
+
data = _mock_variant(prompt)
|
|
178
|
+
return FactorCandidate(
|
|
179
|
+
factor_id=str(uuid.uuid4()),
|
|
180
|
+
name=str(data.get("name", f"m_{parent.name}")),
|
|
181
|
+
expression=str(data["expression"]),
|
|
182
|
+
hypothesis=parent.hypothesis,
|
|
183
|
+
description=str(data.get("description", parent.description)),
|
|
184
|
+
)
|
|
185
|
+
continue
|
|
186
|
+
raise RuntimeError("unreachable")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class Crosser(BaseOperator):
|
|
190
|
+
"""从两个 parent 生成 crossover 子代。"""
|
|
191
|
+
|
|
192
|
+
def crossover(
|
|
193
|
+
self,
|
|
194
|
+
parent1: FactorCandidate,
|
|
195
|
+
parent2: FactorCandidate,
|
|
196
|
+
) -> FactorCandidate:
|
|
197
|
+
prompt = _CROSSOVER_PROMPT.format(
|
|
198
|
+
p1_expression=parent1.expression,
|
|
199
|
+
p1_description=parent1.description,
|
|
200
|
+
p2_expression=parent2.expression,
|
|
201
|
+
p2_description=parent2.description,
|
|
202
|
+
)
|
|
203
|
+
for attempt in range(self.max_correction_attempts + 1):
|
|
204
|
+
try:
|
|
205
|
+
raw = self._call(prompt)
|
|
206
|
+
data = json.loads(raw)
|
|
207
|
+
return FactorCandidate(
|
|
208
|
+
factor_id=str(uuid.uuid4()),
|
|
209
|
+
name=str(data.get("name", f"x_{parent1.name}_{parent2.name}")),
|
|
210
|
+
expression=str(data["expression"]),
|
|
211
|
+
hypothesis=f"combo({parent1.hypothesis}, {parent2.hypothesis})",
|
|
212
|
+
description=str(data.get(
|
|
213
|
+
"description",
|
|
214
|
+
f"combo of {parent1.name} + {parent2.name}",
|
|
215
|
+
)),
|
|
216
|
+
)
|
|
217
|
+
except (json.JSONDecodeError, KeyError, TypeError):
|
|
218
|
+
if attempt == self.max_correction_attempts:
|
|
219
|
+
data = _mock_variant(prompt)
|
|
220
|
+
return FactorCandidate(
|
|
221
|
+
factor_id=str(uuid.uuid4()),
|
|
222
|
+
name=str(data.get("name", f"x_{parent1.name}_{parent2.name}")),
|
|
223
|
+
expression=str(data["expression"]),
|
|
224
|
+
hypothesis=f"combo({parent1.hypothesis}, {parent2.hypothesis})",
|
|
225
|
+
description=str(data.get(
|
|
226
|
+
"description",
|
|
227
|
+
f"combo of {parent1.name} + {parent2.name}",
|
|
228
|
+
)),
|
|
229
|
+
)
|
|
230
|
+
continue
|
|
231
|
+
raise RuntimeError("unreachable")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# ============================================================================
|
|
235
|
+
# Mock variant generator (heuristic-based fallback)
|
|
236
|
+
# ============================================================================
|
|
237
|
+
|
|
238
|
+
_MUTATION_TEMPLATES = [
|
|
239
|
+
lambda e: f"({e}).rolling(5).mean()",
|
|
240
|
+
lambda e: f"({e}).diff()",
|
|
241
|
+
lambda e: f"({e}).rank(pct=True)",
|
|
242
|
+
lambda e: f"({e}) - ({e}).shift(5)",
|
|
243
|
+
lambda e: f"({e}) * 2",
|
|
244
|
+
lambda e: f"({e}).abs()",
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
_CROSSOVER_TEMPLATES = [
|
|
248
|
+
lambda a, b: f"({a}) + ({b})",
|
|
249
|
+
lambda a, b: f"({a}) - ({b})",
|
|
250
|
+
lambda a, b: f"({a}) * ({b})",
|
|
251
|
+
lambda a, b: f"(({a}) + ({b})) / 2",
|
|
252
|
+
lambda a, b: f"({a}).rank(pct=True) - ({b}).rank(pct=True)",
|
|
253
|
+
]
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _mock_variant(prompt: str) -> dict:
|
|
257
|
+
"""基于 prompt 内容启发式生成变体。"""
|
|
258
|
+
# 提取父表达式 (按 "父因子: <expr>" 模式)
|
|
259
|
+
parent_match = re.search(r"父因子[:\s]+([^\n]+)", prompt)
|
|
260
|
+
parents_match = re.findall(r"父因子\s*\d*[:\s]+([^\n(]+)", prompt)
|
|
261
|
+
hyp_match = re.search(r"研究假设[:\s]+([^\n]+)", prompt)
|
|
262
|
+
|
|
263
|
+
hyp = hyp_match.group(1).strip() if hyp_match else "alpha"
|
|
264
|
+
|
|
265
|
+
if len(parents_match) >= 2:
|
|
266
|
+
# crossover
|
|
267
|
+
idx = sum(ord(c) for c in prompt) % len(_CROSSOVER_TEMPLATES)
|
|
268
|
+
tpl = _CROSSOVER_TEMPLATES[idx]
|
|
269
|
+
expr = tpl(parents_match[0].strip(), parents_match[1].strip())
|
|
270
|
+
return {
|
|
271
|
+
"name": f"x_mock_{idx}",
|
|
272
|
+
"expression": expr,
|
|
273
|
+
"description": f"combo of {parents_match[0][:20]} + {parents_match[1][:20]}",
|
|
274
|
+
}
|
|
275
|
+
if parent_match:
|
|
276
|
+
parent_expr = parent_match.group(1).strip()
|
|
277
|
+
idx = sum(ord(c) for c in prompt) % len(_MUTATION_TEMPLATES)
|
|
278
|
+
tpl = _MUTATION_TEMPLATES[idx]
|
|
279
|
+
return {
|
|
280
|
+
"name": f"m_mock_{idx}",
|
|
281
|
+
"expression": tpl(parent_expr),
|
|
282
|
+
"description": f"mutation of {parent_expr[:30]}",
|
|
283
|
+
}
|
|
284
|
+
# hypothesize fallback
|
|
285
|
+
return {
|
|
286
|
+
"name": f"h_mock_{hyp[:8]}",
|
|
287
|
+
"expression": "(close - close.shift(20)) / close.shift(20)",
|
|
288
|
+
"description": f"default expression for {hyp}",
|
|
289
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Evolution 配置 — 演化主循环相关设置。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OperatorSetting(BaseModel):
|
|
10
|
+
"""LLM Operator 配置 (hypothesize / mutate / crossover)。"""
|
|
11
|
+
enabled: bool = Field(default=True, description="启用该 operator")
|
|
12
|
+
model: str = Field(default="mock", description="LLM 模型 (mock/deepseek-v3/...)")
|
|
13
|
+
max_correction_attempts: int = Field(default=3, description="LLM 解析失败最大重试")
|
|
14
|
+
seed: int = Field(default=42, description="mock 模式随机种子")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class EvolutionSetting(BaseModel):
|
|
18
|
+
"""演化主循环配置 (集成到 SingleFactorTestConfig)。"""
|
|
19
|
+
enabled: bool = Field(default=False, description="是否启用演化模式")
|
|
20
|
+
max_rounds: int = Field(default=3, description="演化总轮数 (不含 round 0 原始)")
|
|
21
|
+
parents_per_round: int = Field(default=1, description="每轮选几个 parent (crossover=2)")
|
|
22
|
+
parent_selection_strategy: str = Field(
|
|
23
|
+
default="top_percent_plus_random",
|
|
24
|
+
description="选择策略 (best/random/weighted/weighted_inverse/top_percent_plus_random)",
|
|
25
|
+
)
|
|
26
|
+
top_percent_threshold: float = Field(
|
|
27
|
+
default=0.3, description="top_percent_plus_random 的 top 比例"
|
|
28
|
+
)
|
|
29
|
+
metric: str = Field(default="sharpe", description="用于排序/加权的指标")
|
|
30
|
+
pool_dir: Optional[str] = Field(
|
|
31
|
+
default=None, description="TrajectoryPool 目录 (None=output.dir/trajectory)"
|
|
32
|
+
)
|
|
33
|
+
early_stop_patience: int = Field(default=0, description="连续 N 轮无改善则停 (0=不启用)")
|
|
34
|
+
top_n: int = Field(default=10, description="最终 best_entries 返回 Top-N (EvolutionResult)")
|
|
35
|
+
hypothesizer: OperatorSetting = Field(default_factory=OperatorSetting)
|
|
36
|
+
mutator: OperatorSetting = Field(default_factory=OperatorSetting)
|
|
37
|
+
crosser: OperatorSetting = Field(default_factory=OperatorSetting)
|
|
38
|
+
|
|
39
|
+
def any_operator_enabled(self) -> bool:
|
|
40
|
+
return (
|
|
41
|
+
self.hypothesizer.enabled
|
|
42
|
+
or self.mutator.enabled
|
|
43
|
+
or self.crosser.enabled
|
|
44
|
+
)
|