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,485 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
研报复现 - ResearchReportReproducer
|
|
4
|
+
|
|
5
|
+
从研报PDF中提取因子公式、交易规则等量化逻辑,
|
|
6
|
+
验证其有效性,存入Wiki因子库。
|
|
7
|
+
|
|
8
|
+
流程: PDF解析 → LLM逻辑提取 → 因子验证 → Wiki存储 → 报告生成
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
import time
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
19
|
+
|
|
20
|
+
import polars as pl
|
|
21
|
+
|
|
22
|
+
from QuantNodes.research.quant_alpha.evaluation.contracts import (
|
|
23
|
+
FactorSpec,
|
|
24
|
+
FactorMetrics,
|
|
25
|
+
VerifyConfig,
|
|
26
|
+
)
|
|
27
|
+
from QuantNodes.research.quant_alpha.evaluation.evaluators.polars_evaluator import (
|
|
28
|
+
PolarsAlphaCalculatorEvaluator,
|
|
29
|
+
)
|
|
30
|
+
from QuantNodes.research.wiki import (
|
|
31
|
+
FactorCategory,
|
|
32
|
+
FactorSource,
|
|
33
|
+
LogicSource,
|
|
34
|
+
WikiFactor,
|
|
35
|
+
WikiFactorProxy,
|
|
36
|
+
WikiLogic,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ==================== 数据模型 ====================
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class ExtractedLogic:
|
|
44
|
+
"""从研报提取的逻辑"""
|
|
45
|
+
logic_type: str # factor | rule | condition | combination
|
|
46
|
+
title: str # 逻辑标题
|
|
47
|
+
description: str # 原文描述
|
|
48
|
+
formula: Optional[str] # 因子公式 (factor 类型必填)
|
|
49
|
+
evidence: str # 原文依据
|
|
50
|
+
confidence: float # LLM 提取置信度 (0-1)
|
|
51
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class ReproductionResult:
|
|
56
|
+
"""单条逻辑的复现结果"""
|
|
57
|
+
logic: ExtractedLogic
|
|
58
|
+
verification_status: str = "pending" # verified | failed | pending | unverifiable
|
|
59
|
+
factor_result: Optional[FactorMetrics] = None
|
|
60
|
+
deviation: str = ""
|
|
61
|
+
wiki_page_name: Optional[str] = None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass
|
|
65
|
+
class ReproductionReport:
|
|
66
|
+
"""研报复现报告"""
|
|
67
|
+
pdf_path: str
|
|
68
|
+
title: str
|
|
69
|
+
total_logics: int = 0
|
|
70
|
+
verified: int = 0
|
|
71
|
+
failed: int = 0
|
|
72
|
+
pending: int = 0
|
|
73
|
+
unverifiable: int = 0
|
|
74
|
+
results: List[ReproductionResult] = field(default_factory=list)
|
|
75
|
+
report_markdown: str = ""
|
|
76
|
+
elapsed_seconds: float = 0.0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ==================== Prompt 模板 ====================
|
|
80
|
+
|
|
81
|
+
EXTRACTION_PROMPT = """你是一个量化研究分析助手。从以下研报文本中提取所有量化逻辑。
|
|
82
|
+
|
|
83
|
+
研报标题: {title}
|
|
84
|
+
|
|
85
|
+
研报文本:
|
|
86
|
+
{text}
|
|
87
|
+
|
|
88
|
+
请提取以下类型的逻辑:
|
|
89
|
+
1. factor: 因子公式 (如 "close / delay(close, 20) - 1")
|
|
90
|
+
2. rule: 交易规则 (如 "金叉买入,死叉卖出")
|
|
91
|
+
3. condition: 筛选条件 (如 "市值 > 100亿")
|
|
92
|
+
4. combination: 组合规则 (如 "等权配置前20只")
|
|
93
|
+
|
|
94
|
+
对每个逻辑,返回 JSON:
|
|
95
|
+
{{
|
|
96
|
+
"logic_type": "factor|rule|condition|combination",
|
|
97
|
+
"title": "逻辑标题",
|
|
98
|
+
"description": "原文描述",
|
|
99
|
+
"formula": "因子公式 (factor类型必填, 其他类型为null)",
|
|
100
|
+
"evidence": "原文依据 (引用原文段落)",
|
|
101
|
+
"confidence": 0.0-1.0
|
|
102
|
+
}}
|
|
103
|
+
|
|
104
|
+
返回 JSON 数组,不要其他内容。"""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ==================== 编排器 ====================
|
|
108
|
+
|
|
109
|
+
class ResearchReportReproducer:
|
|
110
|
+
"""研报复现系统"""
|
|
111
|
+
|
|
112
|
+
def __init__(
|
|
113
|
+
self,
|
|
114
|
+
wiki_path: str,
|
|
115
|
+
llm_client=None,
|
|
116
|
+
verify_config: VerifyConfig = None,
|
|
117
|
+
):
|
|
118
|
+
"""
|
|
119
|
+
Args:
|
|
120
|
+
wiki_path: Wiki 因子库路径
|
|
121
|
+
llm_client: LLM 客户端 (可选, 默认使用 LLMGateway)
|
|
122
|
+
verify_config: 因子验证配置
|
|
123
|
+
"""
|
|
124
|
+
self.wiki_path = wiki_path
|
|
125
|
+
if llm_client is None:
|
|
126
|
+
from QuantNodes.ai.llm.gateway import get_llm_gateway
|
|
127
|
+
llm_client = get_llm_gateway()
|
|
128
|
+
self.llm_client = llm_client
|
|
129
|
+
self.proxy = WikiFactorProxy(wiki_path)
|
|
130
|
+
self.evaluator = PolarsAlphaCalculatorEvaluator()
|
|
131
|
+
self.verify_config = verify_config or VerifyConfig()
|
|
132
|
+
|
|
133
|
+
def process(
|
|
134
|
+
self,
|
|
135
|
+
pdf_path: str,
|
|
136
|
+
data: pl.DataFrame = None,
|
|
137
|
+
store_to_wiki: bool = True,
|
|
138
|
+
) -> ReproductionReport:
|
|
139
|
+
"""处理单个研报 PDF
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
pdf_path: PDF 文件路径
|
|
143
|
+
data: 行情数据 (用于因子验证, 可选)
|
|
144
|
+
store_to_wiki: 是否存入 Wiki
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
ReproductionReport
|
|
148
|
+
"""
|
|
149
|
+
start = time.time()
|
|
150
|
+
|
|
151
|
+
# 1. PDF 解析
|
|
152
|
+
title, text = self.parse_pdf(pdf_path)
|
|
153
|
+
|
|
154
|
+
# 2. 逻辑提取
|
|
155
|
+
logics = self.extract_logic_from_text(text, title)
|
|
156
|
+
|
|
157
|
+
# 3. 逐条验证
|
|
158
|
+
results: List[ReproductionResult] = []
|
|
159
|
+
for logic in logics:
|
|
160
|
+
if data is not None and logic.logic_type == "factor" and logic.formula:
|
|
161
|
+
result = self.verify_factor(logic, data)
|
|
162
|
+
else:
|
|
163
|
+
result = ReproductionResult(
|
|
164
|
+
logic=logic,
|
|
165
|
+
verification_status=(
|
|
166
|
+
"pending" if logic.logic_type != "factor" else "unverifiable"
|
|
167
|
+
),
|
|
168
|
+
deviation=(
|
|
169
|
+
"非因子类型, 待人工验证"
|
|
170
|
+
if logic.logic_type != "factor"
|
|
171
|
+
else "缺少数据, 无法验证"
|
|
172
|
+
),
|
|
173
|
+
)
|
|
174
|
+
results.append(result)
|
|
175
|
+
|
|
176
|
+
# 4. 存入 Wiki
|
|
177
|
+
if store_to_wiki:
|
|
178
|
+
for result in results:
|
|
179
|
+
self._store_to_wiki(result)
|
|
180
|
+
|
|
181
|
+
# 5. 生成报告
|
|
182
|
+
elapsed = time.time() - start
|
|
183
|
+
report_md = self.generate_report(results, title)
|
|
184
|
+
|
|
185
|
+
verified = sum(1 for r in results if r.verification_status == "verified")
|
|
186
|
+
failed = sum(1 for r in results if r.verification_status == "failed")
|
|
187
|
+
pending = sum(1 for r in results if r.verification_status == "pending")
|
|
188
|
+
unverifiable = sum(1 for r in results if r.verification_status == "unverifiable")
|
|
189
|
+
|
|
190
|
+
return ReproductionReport(
|
|
191
|
+
pdf_path=pdf_path,
|
|
192
|
+
title=title,
|
|
193
|
+
total_logics=len(results),
|
|
194
|
+
verified=verified,
|
|
195
|
+
failed=failed,
|
|
196
|
+
pending=pending,
|
|
197
|
+
unverifiable=unverifiable,
|
|
198
|
+
results=results,
|
|
199
|
+
report_markdown=report_md,
|
|
200
|
+
elapsed_seconds=elapsed,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
# ==================== PDF 解析 ====================
|
|
204
|
+
|
|
205
|
+
def parse_pdf(self, pdf_path: str) -> Tuple[str, str]:
|
|
206
|
+
"""解析 PDF, 返回 (title, text)"""
|
|
207
|
+
try:
|
|
208
|
+
from llmwikify.extractors import extract
|
|
209
|
+
result = extract(pdf_path)
|
|
210
|
+
return result.title or Path(pdf_path).stem, result.text
|
|
211
|
+
except ImportError:
|
|
212
|
+
return self._parse_pdf_fallback(pdf_path)
|
|
213
|
+
except Exception:
|
|
214
|
+
return self._parse_pdf_fallback(pdf_path)
|
|
215
|
+
|
|
216
|
+
def _parse_pdf_fallback(self, pdf_path: str) -> Tuple[str, str]:
|
|
217
|
+
"""PDF 解析回退方案 (尝试 pymupdf)"""
|
|
218
|
+
try:
|
|
219
|
+
import pymupdf
|
|
220
|
+
doc = pymupdf.open(pdf_path)
|
|
221
|
+
title = doc.metadata.get("title", "") or Path(pdf_path).stem
|
|
222
|
+
text_parts = []
|
|
223
|
+
for page in doc:
|
|
224
|
+
text_parts.append(page.get_text())
|
|
225
|
+
doc.close()
|
|
226
|
+
return title, "\n---\n".join(text_parts)
|
|
227
|
+
except ImportError:
|
|
228
|
+
return Path(pdf_path).stem, "[PDF 解析不可用: 请安装 llmwikify 或 pymupdf]"
|
|
229
|
+
except Exception as e:
|
|
230
|
+
return Path(pdf_path).stem, f"[PDF 解析失败: {e}]"
|
|
231
|
+
|
|
232
|
+
# ==================== 逻辑提取 ====================
|
|
233
|
+
|
|
234
|
+
def extract_logic_from_text(
|
|
235
|
+
self,
|
|
236
|
+
text: str,
|
|
237
|
+
title: str = "",
|
|
238
|
+
) -> List[ExtractedLogic]:
|
|
239
|
+
"""从文本提取逻辑"""
|
|
240
|
+
if self.llm_client is not None:
|
|
241
|
+
return self._llm_extract(text, title)
|
|
242
|
+
return self._rule_based_extract(text)
|
|
243
|
+
|
|
244
|
+
def _llm_extract(self, text: str, title: str) -> List[ExtractedLogic]:
|
|
245
|
+
"""LLM 逻辑提取"""
|
|
246
|
+
try:
|
|
247
|
+
from QuantNodes.ai.llm.base import Message
|
|
248
|
+
|
|
249
|
+
# 截断防溢出
|
|
250
|
+
max_chars = 8000
|
|
251
|
+
truncated = text[:max_chars] if len(text) > max_chars else text
|
|
252
|
+
|
|
253
|
+
prompt = EXTRACTION_PROMPT.format(title=title, text=truncated)
|
|
254
|
+
response = self.llm_client.chat([
|
|
255
|
+
Message(role="user", content=prompt)
|
|
256
|
+
])
|
|
257
|
+
|
|
258
|
+
content = response.choices[0].message.content
|
|
259
|
+
|
|
260
|
+
# 提取 JSON (处理可能的 markdown 代码块)
|
|
261
|
+
json_match = re.search(r'```(?:json)?\s*([\s\S]*?)```', content)
|
|
262
|
+
if json_match:
|
|
263
|
+
content = json_match.group(1)
|
|
264
|
+
content = content.strip()
|
|
265
|
+
|
|
266
|
+
logics_data = json.loads(content)
|
|
267
|
+
return [ExtractedLogic(**item) for item in logics_data]
|
|
268
|
+
|
|
269
|
+
except Exception:
|
|
270
|
+
return self._rule_based_extract(text)
|
|
271
|
+
|
|
272
|
+
def _rule_based_extract(self, text: str) -> List[ExtractedLogic]:
|
|
273
|
+
"""基于规则的逻辑提取 (不需要 LLM)"""
|
|
274
|
+
logics = []
|
|
275
|
+
|
|
276
|
+
# 匹配因子公式模式
|
|
277
|
+
formula_patterns = [
|
|
278
|
+
(r'(?:公式|factor|因子)[::]\s*(.+)', "factor"),
|
|
279
|
+
(r'(\w+\s*/\s*\w+[\w\s/*+-]*?-\s*1)', "factor"),
|
|
280
|
+
(r'(ts_\w+\([^)]+\))', "factor"),
|
|
281
|
+
(r'(rank\([^)]+\))', "factor"),
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
seen_formulas = set()
|
|
285
|
+
for pattern, logic_type in formula_patterns:
|
|
286
|
+
matches = re.findall(pattern, text, re.IGNORECASE)
|
|
287
|
+
for match in matches:
|
|
288
|
+
formula = match.strip()
|
|
289
|
+
if formula in seen_formulas or len(formula) < 5:
|
|
290
|
+
continue
|
|
291
|
+
seen_formulas.add(formula)
|
|
292
|
+
logics.append(ExtractedLogic(
|
|
293
|
+
logic_type=logic_type,
|
|
294
|
+
title=f"提取因子: {formula[:50]}",
|
|
295
|
+
description=formula,
|
|
296
|
+
formula=formula,
|
|
297
|
+
evidence=match,
|
|
298
|
+
confidence=0.5,
|
|
299
|
+
))
|
|
300
|
+
|
|
301
|
+
# 匹配交易规则模式
|
|
302
|
+
rule_patterns = [
|
|
303
|
+
r'(?:当|如果|若)(.+?)(?:时|买入|卖出|做多|做空)',
|
|
304
|
+
r'(金叉|死叉|上穿|下穿)(.+?)(?:买入|卖出)',
|
|
305
|
+
]
|
|
306
|
+
for pattern in rule_patterns:
|
|
307
|
+
matches = re.findall(pattern, text)
|
|
308
|
+
for match in matches:
|
|
309
|
+
desc = match.strip() if isinstance(match, str) else " ".join(match)
|
|
310
|
+
if len(desc) < 5:
|
|
311
|
+
continue
|
|
312
|
+
logics.append(ExtractedLogic(
|
|
313
|
+
logic_type="rule",
|
|
314
|
+
title=f"交易规则: {desc[:50]}",
|
|
315
|
+
description=desc,
|
|
316
|
+
formula=None,
|
|
317
|
+
evidence=desc,
|
|
318
|
+
confidence=0.4,
|
|
319
|
+
))
|
|
320
|
+
|
|
321
|
+
return logics
|
|
322
|
+
|
|
323
|
+
# ==================== 因子验证 ====================
|
|
324
|
+
|
|
325
|
+
def verify_factor(
|
|
326
|
+
self,
|
|
327
|
+
logic: ExtractedLogic,
|
|
328
|
+
data: pl.DataFrame,
|
|
329
|
+
) -> ReproductionResult:
|
|
330
|
+
"""验证单条因子逻辑"""
|
|
331
|
+
result = ReproductionResult(logic=logic)
|
|
332
|
+
|
|
333
|
+
if not logic.formula:
|
|
334
|
+
result.verification_status = "unverifiable"
|
|
335
|
+
result.deviation = "缺少公式"
|
|
336
|
+
return result
|
|
337
|
+
|
|
338
|
+
# 构造 FactorSpec
|
|
339
|
+
spec = FactorSpec(
|
|
340
|
+
formula_id=f"report_{logic.title}",
|
|
341
|
+
formula=logic.formula,
|
|
342
|
+
source="research_report",
|
|
343
|
+
category="other",
|
|
344
|
+
meta={
|
|
345
|
+
"description": logic.description,
|
|
346
|
+
"template_name": "research_report",
|
|
347
|
+
},
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
# 评估因子
|
|
351
|
+
metrics_list = self.evaluator.evaluate([spec], data)
|
|
352
|
+
if not metrics_list:
|
|
353
|
+
result.verification_status = "failed"
|
|
354
|
+
result.deviation = "评估失败"
|
|
355
|
+
return result
|
|
356
|
+
|
|
357
|
+
eval_result = metrics_list[0]
|
|
358
|
+
|
|
359
|
+
# 6 维验证
|
|
360
|
+
eval_result = self.evaluator.verify(
|
|
361
|
+
eval_result,
|
|
362
|
+
data,
|
|
363
|
+
config=self.verify_config,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
if eval_result.is_valid:
|
|
367
|
+
result.verification_status = "verified"
|
|
368
|
+
result.factor_result = eval_result
|
|
369
|
+
result.deviation = f"IC={eval_result.ic_mean:.4f}, IR={eval_result.ir:.4f}"
|
|
370
|
+
else:
|
|
371
|
+
result.verification_status = "failed"
|
|
372
|
+
result.factor_result = eval_result
|
|
373
|
+
if eval_result.fail_reasons:
|
|
374
|
+
result.deviation = "; ".join(eval_result.fail_reasons)
|
|
375
|
+
else:
|
|
376
|
+
result.deviation = "未通过验证"
|
|
377
|
+
|
|
378
|
+
return result
|
|
379
|
+
|
|
380
|
+
# ==================== Wiki 存储 ====================
|
|
381
|
+
|
|
382
|
+
def _store_to_wiki(self, result: ReproductionResult):
|
|
383
|
+
"""存储到 Wiki"""
|
|
384
|
+
if result.verification_status == "verified" and result.factor_result:
|
|
385
|
+
self._store_verified_factor(result)
|
|
386
|
+
else:
|
|
387
|
+
self._store_pending_logic(result)
|
|
388
|
+
|
|
389
|
+
def _store_verified_factor(self, result: ReproductionResult):
|
|
390
|
+
"""存储验证通过的因子"""
|
|
391
|
+
factor = WikiFactor(
|
|
392
|
+
name=result.logic.title,
|
|
393
|
+
formula=result.logic.formula,
|
|
394
|
+
source=FactorSource.RESEARCH_REPORT,
|
|
395
|
+
category=FactorCategory.OTHER,
|
|
396
|
+
tags=["research_report"],
|
|
397
|
+
ic_mean=result.factor_result.ic_mean,
|
|
398
|
+
ic_std=result.factor_result.ic_std,
|
|
399
|
+
icir=result.factor_result.ir,
|
|
400
|
+
rank_ic_mean=result.factor_result.rank_ic_mean,
|
|
401
|
+
turnover=result.factor_result.turnover,
|
|
402
|
+
metadata={
|
|
403
|
+
"source_evidence": result.logic.evidence,
|
|
404
|
+
"confidence": result.logic.confidence,
|
|
405
|
+
"logic_type": result.logic.logic_type,
|
|
406
|
+
"stability_score": result.factor_result.stability_score,
|
|
407
|
+
"diversification_score": result.factor_result.diversification_score,
|
|
408
|
+
"monotonicity_score": result.factor_result.monotonicity_score,
|
|
409
|
+
"coverage": result.factor_result.coverage,
|
|
410
|
+
"overall_score": result.factor_result.overall_score,
|
|
411
|
+
},
|
|
412
|
+
)
|
|
413
|
+
page_name = self.proxy.store_factor(factor)
|
|
414
|
+
result.wiki_page_name = page_name
|
|
415
|
+
|
|
416
|
+
def _store_pending_logic(self, result: ReproductionResult):
|
|
417
|
+
"""存储待验证的逻辑"""
|
|
418
|
+
logic = WikiLogic(
|
|
419
|
+
name=result.logic.title,
|
|
420
|
+
content=result.logic.description,
|
|
421
|
+
source=LogicSource.RESEARCH_REPORT,
|
|
422
|
+
extracted_formula=result.logic.formula,
|
|
423
|
+
validation_status="pending" if result.verification_status == "pending" else "rejected",
|
|
424
|
+
metadata={
|
|
425
|
+
"logic_type": result.logic.logic_type,
|
|
426
|
+
"evidence": result.logic.evidence,
|
|
427
|
+
"confidence": result.logic.confidence,
|
|
428
|
+
"deviation": result.deviation,
|
|
429
|
+
},
|
|
430
|
+
)
|
|
431
|
+
page_name = self.proxy.store_logic(logic)
|
|
432
|
+
result.wiki_page_name = page_name
|
|
433
|
+
|
|
434
|
+
# ==================== 报告生成 ====================
|
|
435
|
+
|
|
436
|
+
def generate_report(
|
|
437
|
+
self,
|
|
438
|
+
results: List[ReproductionResult],
|
|
439
|
+
title: str = "",
|
|
440
|
+
) -> str:
|
|
441
|
+
"""生成 Markdown 复现报告"""
|
|
442
|
+
verified = sum(1 for r in results if r.verification_status == "verified")
|
|
443
|
+
failed = sum(1 for r in results if r.verification_status == "failed")
|
|
444
|
+
pending = sum(1 for r in results if r.verification_status == "pending")
|
|
445
|
+
unverifiable = sum(1 for r in results if r.verification_status == "unverifiable")
|
|
446
|
+
|
|
447
|
+
lines = [
|
|
448
|
+
f"# 研报复现报告: {title}",
|
|
449
|
+
"",
|
|
450
|
+
f"**提取逻辑数**: {len(results)}",
|
|
451
|
+
f"**验证通过**: {verified}",
|
|
452
|
+
f"**验证失败**: {failed}",
|
|
453
|
+
f"**待验证**: {pending}",
|
|
454
|
+
f"**无法验证**: {unverifiable}",
|
|
455
|
+
"",
|
|
456
|
+
]
|
|
457
|
+
|
|
458
|
+
# 按状态分组展示
|
|
459
|
+
status_icons = {
|
|
460
|
+
"verified": "✅",
|
|
461
|
+
"failed": "❌",
|
|
462
|
+
"pending": "⏳",
|
|
463
|
+
"unverifiable": "⚠️",
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
for i, r in enumerate(results, 1):
|
|
467
|
+
icon = status_icons.get(r.verification_status, "?")
|
|
468
|
+
lines.append(f"### {i}. {r.logic.title} {icon}")
|
|
469
|
+
lines.append(f"- **类型**: {r.logic.logic_type}")
|
|
470
|
+
if r.logic.formula:
|
|
471
|
+
lines.append(f"- **公式**: `{r.logic.formula}`")
|
|
472
|
+
lines.append(f"- **描述**: {r.logic.description}")
|
|
473
|
+
lines.append(f"- **原文依据**: {r.logic.evidence}")
|
|
474
|
+
lines.append(f"- **置信度**: {r.logic.confidence:.2f}")
|
|
475
|
+
lines.append(f"- **验证状态**: {r.verification_status}")
|
|
476
|
+
if r.deviation:
|
|
477
|
+
lines.append(f"- **详情**: {r.deviation}")
|
|
478
|
+
if r.factor_result:
|
|
479
|
+
lines.append(f"- **IC Mean**: {r.factor_result.ic_mean:.4f}")
|
|
480
|
+
lines.append(f"- **IR**: {r.factor_result.ir:.4f}")
|
|
481
|
+
lines.append(f"- **稳定性**: {r.factor_result.stability_score:.4f}")
|
|
482
|
+
lines.append(f"- **综合分数**: {r.factor_result.overall_score:.4f}")
|
|
483
|
+
lines.append("")
|
|
484
|
+
|
|
485
|
+
return "\n".join(lines)
|