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,149 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
sources.py - Logic Mining 数据源适配
|
|
4
|
+
|
|
5
|
+
支持从 alpha101_design / alpha158_design / Alpha191 等数据源
|
|
6
|
+
提取公式用于逻辑抽取。
|
|
7
|
+
|
|
8
|
+
Usage::
|
|
9
|
+
|
|
10
|
+
from QuantNodes.research.quant_alpha.logic_mining.sources import (
|
|
11
|
+
get_formulas_from_source, SOURCES,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
formulas = get_formulas_from_source("alpha101", max_count=20)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
from typing import Any, Dict, List, Optional
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
__all__ = ["SOURCES", "get_formulas_from_source", "list_available_sources"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# 预定义的 Alpha101 代表性公式(量价类)
|
|
28
|
+
ALPHA101_FORMULAS: Dict[str, str] = {
|
|
29
|
+
"alpha001": "rank(ts_argmax(signedpower(where(close < delay(close, 1), 1, -1) * (close - ts_min(close, 5)), 2), 5)) - 0.5",
|
|
30
|
+
"alpha006": "-ts_corr(open, volume, 10)",
|
|
31
|
+
"alpha012": "sign(delta(volume, 1)) * (-1 * delta(close, 1))",
|
|
32
|
+
"alpha018": "-rank(rank(std(abs(close - open), 5) + (close - open) + rank(corr(close, ts_mean(volume, 20), 5))))",
|
|
33
|
+
"alpha033": "rank(-1 + open / close)",
|
|
34
|
+
"alpha038": "-rank(ts_mean(close, 10) / ts_mean(close, 20) * rank(volume))",
|
|
35
|
+
"alpha041": "power(high * low, 0.5) - ts_mean(power(high * low, 0.5), 3)",
|
|
36
|
+
"alpha054": "-1 * rank((low - close) * power(volume, 0.5) / power(ts_mean(volume, 20), 0.5))",
|
|
37
|
+
"alpha055": "-1 * corr(rank(sub((high + low) / 2, ts_mean(high, 20))), rank(volume), 10)",
|
|
38
|
+
"alpha066": "-1 * ts_corr(close, ts_mean(volume, 20), 5)",
|
|
39
|
+
"alpha078": "rank(ts_corr(ts_mean(ts_mean(volume, 30), 37), ts_mean(close, 20), 7))",
|
|
40
|
+
"alpha085": "rank(ts_corr(high, volume, 5))",
|
|
41
|
+
"alpha088": "rank(ts_argmax(close - delay(close, 1), 30))",
|
|
42
|
+
"alpha095": "std(volume, 20) / std(close, 20)",
|
|
43
|
+
"alpha101": "rank(ts_mean(delta(close, 1), 5) - delta(ts_mean(close, 20), 5) / ts_mean(close, 20))",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# 预定义的 Alpha158 模板类别(来自 alpha158_design)
|
|
47
|
+
ALPHA158_TEMPLATE_CATEGORIES: List[Dict[str, str]] = [
|
|
48
|
+
{"id": "KBAR", "name": "K线形态", "example": "rank(ts_mean(close - open, 20))"},
|
|
49
|
+
{"id": "PRICE", "name": "价格时序", "example": "ts_mean(close / delay(close, 5) - 1, 20)"},
|
|
50
|
+
{"id": "VOLUME", "name": "成交量时序", "example": "rank(volume / ts_mean(volume, 20))"},
|
|
51
|
+
{"id": "ROLLING", "name": "滚动统计", "example": "rank(ts_std(returns, 20))"},
|
|
52
|
+
{"id": "MOMENTUM", "name": "动量", "example": "rank(close / delay(close, 20) - 1)"},
|
|
53
|
+
{"id": "REVERSAL", "name": "反转", "example": "-rank(close / delay(close, 5) - 1)"},
|
|
54
|
+
{"id": "VOLATILITY", "name": "波动率", "example": "rank(ts_std(close, 20) / ts_mean(close, 20))"},
|
|
55
|
+
{"id": "LIQUIDITY", "name": "流动性", "example": "rank(volume / amount)"},
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
# 数据源注册表
|
|
59
|
+
SOURCES: Dict[str, Dict[str, Any]] = {
|
|
60
|
+
"alpha101": {
|
|
61
|
+
"name": "WorldQuant Alpha101",
|
|
62
|
+
"description": "WorldQuant 101 formulaic alphas",
|
|
63
|
+
"formulas": ALPHA101_FORMULAS,
|
|
64
|
+
"count": len(ALPHA101_FORMULAS),
|
|
65
|
+
},
|
|
66
|
+
"alpha158": {
|
|
67
|
+
"name": "Qlib Alpha158",
|
|
68
|
+
"description": "Qlib 158 standard features (templates)",
|
|
69
|
+
"templates": ALPHA158_TEMPLATE_CATEGORIES,
|
|
70
|
+
"count": len(ALPHA158_TEMPLATE_CATEGORIES),
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_formulas_from_source(
|
|
76
|
+
source_lib: str,
|
|
77
|
+
max_count: int = 20,
|
|
78
|
+
only_volume_price: bool = True,
|
|
79
|
+
) -> List[Dict[str, str]]:
|
|
80
|
+
"""从指定数据源获取公式
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
source_lib: 来源库名称 ("alpha101" / "alpha158" / "alpha191")
|
|
84
|
+
max_count: 最大数量
|
|
85
|
+
only_volume_price: 仅返回量价类公式(过滤掉含财务/基本面数据的)
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
List of {"id": ..., "formula": ...}
|
|
89
|
+
"""
|
|
90
|
+
if source_lib not in SOURCES:
|
|
91
|
+
logger.warning("Unknown source: %s, available: %s", source_lib, list(SOURCES.keys()))
|
|
92
|
+
return []
|
|
93
|
+
|
|
94
|
+
source = SOURCES[source_lib]
|
|
95
|
+
results = []
|
|
96
|
+
|
|
97
|
+
if source_lib == "alpha101":
|
|
98
|
+
for fid, formula in source["formulas"].items():
|
|
99
|
+
if only_volume_price and not _is_volume_price(formula):
|
|
100
|
+
continue
|
|
101
|
+
results.append({"id": fid, "formula": formula, "lib": source_lib})
|
|
102
|
+
if len(results) >= max_count:
|
|
103
|
+
break
|
|
104
|
+
|
|
105
|
+
elif source_lib == "alpha158":
|
|
106
|
+
for tmpl in source["templates"]:
|
|
107
|
+
if only_volume_price and not _is_volume_price(tmpl["example"]):
|
|
108
|
+
continue
|
|
109
|
+
results.append({
|
|
110
|
+
"id": tmpl["id"],
|
|
111
|
+
"formula": tmpl["example"],
|
|
112
|
+
"lib": source_lib,
|
|
113
|
+
"name": tmpl["name"],
|
|
114
|
+
})
|
|
115
|
+
if len(results) >= max_count:
|
|
116
|
+
break
|
|
117
|
+
|
|
118
|
+
elif source_lib == "alpha191":
|
|
119
|
+
# Alpha191 占位(PR-6 实现)
|
|
120
|
+
logger.info("alpha191 not yet implemented, returning empty list")
|
|
121
|
+
return []
|
|
122
|
+
|
|
123
|
+
logger.info("Loaded %d formulas from %s", len(results), source_lib)
|
|
124
|
+
return results
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _is_volume_price(formula: str) -> bool:
|
|
128
|
+
"""简单判断是否为量价类公式(排除财务/基本面类)"""
|
|
129
|
+
formula_lower = formula.lower()
|
|
130
|
+
# 排除包含财务指标的关键词
|
|
131
|
+
exclude_keywords = [
|
|
132
|
+
"earnings", "revenue", "profit", "bv", "market_cap",
|
|
133
|
+
"pb", "pe", "ps", "dividend", "roe", "roa",
|
|
134
|
+
"营业收入", "净利润", "市值", "市盈率",
|
|
135
|
+
]
|
|
136
|
+
for kw in exclude_keywords:
|
|
137
|
+
if kw in formula_lower:
|
|
138
|
+
return False
|
|
139
|
+
return True
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def list_available_sources() -> List[str]:
|
|
143
|
+
"""列出所有可用的数据源"""
|
|
144
|
+
return list(SOURCES.keys())
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def get_source_info(source_lib: str) -> Optional[Dict[str, Any]]:
|
|
148
|
+
"""获取数据源详细信息"""
|
|
149
|
+
return SOURCES.get(source_lib)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
mcts - QuantAlpha MCTS 因子搜索子包
|
|
4
|
+
|
|
5
|
+
参考 AlphaJungle 论文思路:
|
|
6
|
+
- 把候选因子组织成搜索树
|
|
7
|
+
- 每个节点有多维评价
|
|
8
|
+
- UCB1 选择策略
|
|
9
|
+
- 维度化反馈指导扩展方向
|
|
10
|
+
- 频繁子树规避
|
|
11
|
+
|
|
12
|
+
M2 改进(vs 旧 mcts_search.py):
|
|
13
|
+
- 7 硬编码 EXTENSION_OPS → 26 动态生成(从 OperatorVocab 162 算子)
|
|
14
|
+
- 无谱系 → 完整 entry_id + parent_id(可映射 TrajectoryEntry)
|
|
15
|
+
- 单一 dimension_scores → 5 通道 FactorFeedback 完整框架
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from QuantNodes.research.quant_alpha.mcts.extension_ops import (
|
|
21
|
+
ExtensionOp,
|
|
22
|
+
ExtensionOpPool,
|
|
23
|
+
DEFAULT_WINDOWS,
|
|
24
|
+
)
|
|
25
|
+
from QuantNodes.research.quant_alpha.mcts.feedback import (
|
|
26
|
+
MCTSFeedbackConfig,
|
|
27
|
+
collect_all_channels,
|
|
28
|
+
collect_code_channel,
|
|
29
|
+
collect_execution_channel,
|
|
30
|
+
collect_llm_channel,
|
|
31
|
+
collect_shape_channel,
|
|
32
|
+
collect_value_channel,
|
|
33
|
+
)
|
|
34
|
+
from QuantNodes.research.quant_alpha.mcts.search import (
|
|
35
|
+
MCTSSearch,
|
|
36
|
+
MCTSSearchConfig,
|
|
37
|
+
MCTSSearchResult,
|
|
38
|
+
)
|
|
39
|
+
from QuantNodes.research.quant_alpha.mcts.tree import (
|
|
40
|
+
MCTSTree,
|
|
41
|
+
MCTSNode,
|
|
42
|
+
NodeStatus,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
# 操作池
|
|
47
|
+
"ExtensionOp",
|
|
48
|
+
"ExtensionOpPool",
|
|
49
|
+
"DEFAULT_WINDOWS",
|
|
50
|
+
# 反馈
|
|
51
|
+
"MCTSFeedbackConfig",
|
|
52
|
+
"collect_all_channels",
|
|
53
|
+
"collect_code_channel",
|
|
54
|
+
"collect_execution_channel",
|
|
55
|
+
"collect_llm_channel",
|
|
56
|
+
"collect_shape_channel",
|
|
57
|
+
"collect_value_channel",
|
|
58
|
+
# 搜索
|
|
59
|
+
"MCTSSearch",
|
|
60
|
+
"MCTSSearchConfig",
|
|
61
|
+
"MCTSSearchResult",
|
|
62
|
+
# 树
|
|
63
|
+
"MCTSTree",
|
|
64
|
+
"MCTSNode",
|
|
65
|
+
"NodeStatus",
|
|
66
|
+
]
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""MCTSCache — 持久化共享缓存,跨运行复用公式评估结果。
|
|
3
|
+
|
|
4
|
+
缓存布局:
|
|
5
|
+
{cache_root}/{data_fingerprint}/
|
|
6
|
+
cache.json # 反馈条目(人类可读)
|
|
7
|
+
series_cache.pkl # {formula: pl.Series} 字典(二进制,快速)
|
|
8
|
+
|
|
9
|
+
Usage::
|
|
10
|
+
|
|
11
|
+
from QuantNodes.research.quant_alpha.mcts.cache import MCTSCache, MCTSCacheConfig
|
|
12
|
+
|
|
13
|
+
cache = MCTSCache(MCTSCacheConfig(enabled=True))
|
|
14
|
+
cache.load(data) # 加载缓存
|
|
15
|
+
|
|
16
|
+
# 使用缓存
|
|
17
|
+
if cache.has_series(formula):
|
|
18
|
+
result = cache.get_series(formula)
|
|
19
|
+
else:
|
|
20
|
+
result = evaluate(formula, data)
|
|
21
|
+
cache.put_series(formula, result)
|
|
22
|
+
|
|
23
|
+
cache.save() # 持久化
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import hashlib
|
|
29
|
+
import json
|
|
30
|
+
import logging
|
|
31
|
+
import pickle
|
|
32
|
+
import time
|
|
33
|
+
from dataclasses import dataclass, field
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
from typing import Any, Dict, Optional, Set
|
|
36
|
+
|
|
37
|
+
import polars as pl
|
|
38
|
+
|
|
39
|
+
from QuantNodes.core.feedback import FactorFeedback
|
|
40
|
+
|
|
41
|
+
logger = logging.getLogger(__name__)
|
|
42
|
+
|
|
43
|
+
DEFAULT_CACHE_ROOT = Path.home() / ".quantnodes" / "mcts_cache"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class MCTSCacheConfig:
|
|
48
|
+
"""缓存配置。"""
|
|
49
|
+
cache_root: Path = DEFAULT_CACHE_ROOT
|
|
50
|
+
enabled: bool = True
|
|
51
|
+
max_series_entries: int = 5000
|
|
52
|
+
max_series_bytes: int = 500_000_000 # 500MB
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class MCTSCache:
|
|
56
|
+
"""持久化共享缓存,用于 MCTS 公式评估。
|
|
57
|
+
|
|
58
|
+
特性:
|
|
59
|
+
- 数据指纹自动失效:不同数据 = 不同缓存目录
|
|
60
|
+
- 混合存储:JSON(反馈)+ pickle(Series)
|
|
61
|
+
- 增量更新:只保存新评估的公式
|
|
62
|
+
- 向后兼容:cache=None 保持当前行为
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def __init__(self, config: Optional[MCTSCacheConfig] = None):
|
|
66
|
+
self.config = config or MCTSCacheConfig()
|
|
67
|
+
self._formula_cache: Dict[str, pl.Series] = {}
|
|
68
|
+
self._feedback_cache: Dict[str, FactorFeedback] = {}
|
|
69
|
+
self._cache_dir: Optional[Path] = None
|
|
70
|
+
self._dirty = False
|
|
71
|
+
|
|
72
|
+
# ----------------------------------------------------------
|
|
73
|
+
# 数据指纹
|
|
74
|
+
# ----------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def compute_data_fingerprint(data: pl.DataFrame) -> str:
|
|
78
|
+
"""计算 DataFrame 的稳定哈希。
|
|
79
|
+
|
|
80
|
+
使用:shape、column names、dtypes、首尾行采样。
|
|
81
|
+
两个相同指纹的 DataFrame 对同一公式会产生相同的 pl.Series。
|
|
82
|
+
"""
|
|
83
|
+
parts = [
|
|
84
|
+
str(data.shape),
|
|
85
|
+
str(sorted(data.columns)),
|
|
86
|
+
str(sorted(str(d) for d in data.dtypes)),
|
|
87
|
+
]
|
|
88
|
+
sample_size = min(100, len(data))
|
|
89
|
+
if sample_size > 0:
|
|
90
|
+
# 转换为字符串以确保确定性
|
|
91
|
+
head_str = str(data.head(sample_size).rows())
|
|
92
|
+
tail_str = str(data.tail(sample_size).rows())
|
|
93
|
+
parts.append(hashlib.md5(head_str.encode()).hexdigest())
|
|
94
|
+
parts.append(hashlib.md5(tail_str.encode()).hexdigest())
|
|
95
|
+
return hashlib.md5("|".join(parts).encode()).hexdigest()[:16]
|
|
96
|
+
|
|
97
|
+
# ----------------------------------------------------------
|
|
98
|
+
# 加载 / 保存
|
|
99
|
+
# ----------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
def load(self, data: pl.DataFrame) -> None:
|
|
102
|
+
"""从磁盘加载缓存。
|
|
103
|
+
|
|
104
|
+
如果没有缓存或数据指纹不匹配,从空缓存开始。
|
|
105
|
+
"""
|
|
106
|
+
if not self.config.enabled:
|
|
107
|
+
return
|
|
108
|
+
|
|
109
|
+
fp = self.compute_data_fingerprint(data)
|
|
110
|
+
self._cache_dir = self.config.cache_root / fp
|
|
111
|
+
json_path = self._cache_dir / "cache.json"
|
|
112
|
+
pkl_path = self._cache_dir / "series_cache.pkl"
|
|
113
|
+
|
|
114
|
+
if not self._cache_dir.exists():
|
|
115
|
+
logger.info("No MCTS cache found at %s, starting fresh", self._cache_dir)
|
|
116
|
+
return
|
|
117
|
+
|
|
118
|
+
# 加载反馈
|
|
119
|
+
if json_path.exists():
|
|
120
|
+
try:
|
|
121
|
+
raw = json.loads(json_path.read_text(encoding="utf-8"))
|
|
122
|
+
self._feedback_cache = {
|
|
123
|
+
k: FactorFeedback.from_dict(v)
|
|
124
|
+
for k, v in raw.get("entries", {}).items()
|
|
125
|
+
}
|
|
126
|
+
logger.info(
|
|
127
|
+
"Loaded %d feedback entries from %s",
|
|
128
|
+
len(self._feedback_cache), json_path,
|
|
129
|
+
)
|
|
130
|
+
except Exception as e:
|
|
131
|
+
logger.warning("Failed to load feedback cache: %s", e)
|
|
132
|
+
|
|
133
|
+
# 加载 Series
|
|
134
|
+
if pkl_path.exists():
|
|
135
|
+
try:
|
|
136
|
+
with open(pkl_path, "rb") as f:
|
|
137
|
+
self._formula_cache = pickle.load(f)
|
|
138
|
+
logger.info(
|
|
139
|
+
"Loaded %d series entries from %s",
|
|
140
|
+
len(self._formula_cache), pkl_path,
|
|
141
|
+
)
|
|
142
|
+
except Exception as e:
|
|
143
|
+
logger.warning("Failed to load series cache: %s", e)
|
|
144
|
+
|
|
145
|
+
self._dirty = False
|
|
146
|
+
|
|
147
|
+
def save(self) -> None:
|
|
148
|
+
"""持久化当前缓存到磁盘。"""
|
|
149
|
+
if not self.config.enabled or self._cache_dir is None:
|
|
150
|
+
return
|
|
151
|
+
if not self._dirty:
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
self._cache_dir.mkdir(parents=True, exist_ok=True)
|
|
155
|
+
|
|
156
|
+
# 保存反馈为 JSON
|
|
157
|
+
json_path = self._cache_dir / "cache.json"
|
|
158
|
+
payload = {
|
|
159
|
+
"version": 1,
|
|
160
|
+
"created_at": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
161
|
+
"entry_count": len(self._feedback_cache),
|
|
162
|
+
"series_count": len(self._formula_cache),
|
|
163
|
+
"entries": {
|
|
164
|
+
k: v.to_dict() for k, v in self._feedback_cache.items()
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
json_path.write_text(
|
|
168
|
+
json.dumps(payload, ensure_ascii=False, indent=2),
|
|
169
|
+
encoding="utf-8",
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
# 保存 Series 为 pickle
|
|
173
|
+
pkl_path = self._cache_dir / "series_cache.pkl"
|
|
174
|
+
with open(pkl_path, "wb") as f:
|
|
175
|
+
pickle.dump(self._formula_cache, f, protocol=pickle.HIGHEST_PROTOCOL)
|
|
176
|
+
|
|
177
|
+
logger.info(
|
|
178
|
+
"Saved MCTS cache: %d formulas, %d feedback entries to %s",
|
|
179
|
+
len(self._formula_cache), len(self._feedback_cache), self._cache_dir,
|
|
180
|
+
)
|
|
181
|
+
self._dirty = False
|
|
182
|
+
|
|
183
|
+
# ----------------------------------------------------------
|
|
184
|
+
# 字典式 API(直接替换 _formula_cache / _feedback_cache)
|
|
185
|
+
# ----------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
def get_series(self, formula: str) -> Optional[pl.Series]:
|
|
188
|
+
"""获取公式的评估结果。"""
|
|
189
|
+
return self._formula_cache.get(formula)
|
|
190
|
+
|
|
191
|
+
def put_series(self, formula: str, series: pl.Series) -> None:
|
|
192
|
+
"""存储公式的评估结果。"""
|
|
193
|
+
self._formula_cache[formula] = series
|
|
194
|
+
self._dirty = True
|
|
195
|
+
|
|
196
|
+
def has_series(self, formula: str) -> bool:
|
|
197
|
+
"""检查公式是否已评估。"""
|
|
198
|
+
return formula in self._formula_cache
|
|
199
|
+
|
|
200
|
+
def get_feedback(self, formula: str) -> Optional[FactorFeedback]:
|
|
201
|
+
"""获取公式的 5 通道反馈。"""
|
|
202
|
+
return self._feedback_cache.get(formula)
|
|
203
|
+
|
|
204
|
+
def put_feedback(self, formula: str, fb: FactorFeedback) -> None:
|
|
205
|
+
"""存储公式的 5 通道反馈。"""
|
|
206
|
+
self._feedback_cache[formula] = fb
|
|
207
|
+
self._dirty = True
|
|
208
|
+
|
|
209
|
+
def has_feedback(self, formula: str) -> bool:
|
|
210
|
+
"""检查公式是否已有反馈。"""
|
|
211
|
+
return formula in self._feedback_cache
|
|
212
|
+
|
|
213
|
+
def clear(self) -> None:
|
|
214
|
+
"""清空内存缓存。"""
|
|
215
|
+
self._formula_cache.clear()
|
|
216
|
+
self._feedback_cache.clear()
|
|
217
|
+
self._dirty = False
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def formula_count(self) -> int:
|
|
221
|
+
"""缓存的公式数量。"""
|
|
222
|
+
return len(self._formula_cache)
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def feedback_count(self) -> int:
|
|
226
|
+
"""缓存的反馈数量。"""
|
|
227
|
+
return len(self._feedback_cache)
|
|
228
|
+
|
|
229
|
+
# ----------------------------------------------------------
|
|
230
|
+
# 失效 / 清理
|
|
231
|
+
# ----------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
def invalidate(self) -> None:
|
|
234
|
+
"""删除当前数据集的整个缓存目录。"""
|
|
235
|
+
if self._cache_dir and self._cache_dir.exists():
|
|
236
|
+
import shutil
|
|
237
|
+
shutil.rmtree(self._cache_dir)
|
|
238
|
+
logger.info("Invalidated MCTS cache at %s", self._cache_dir)
|
|
239
|
+
self.clear()
|
|
240
|
+
self._cache_dir = None
|
|
241
|
+
|
|
242
|
+
def prune(self, keep_formulas: Set[str]) -> int:
|
|
243
|
+
"""移除不在 keep_formulas 中的条目。返回移除数量。"""
|
|
244
|
+
removed = 0
|
|
245
|
+
for formula in list(self._formula_cache.keys()):
|
|
246
|
+
if formula not in keep_formulas:
|
|
247
|
+
del self._formula_cache[formula]
|
|
248
|
+
removed += 1
|
|
249
|
+
for formula in list(self._feedback_cache.keys()):
|
|
250
|
+
if formula not in keep_formulas:
|
|
251
|
+
del self._feedback_cache[formula]
|
|
252
|
+
removed += 1
|
|
253
|
+
if removed:
|
|
254
|
+
self._dirty = True
|
|
255
|
+
return removed
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
__all__ = [
|
|
259
|
+
"MCTSCache",
|
|
260
|
+
"MCTSCacheConfig",
|
|
261
|
+
"DEFAULT_CACHE_ROOT",
|
|
262
|
+
]
|