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,95 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
operators.templates - 算子模板工厂
|
|
4
|
+
|
|
5
|
+
基于现有算子创建固定参数变体。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Dict, Optional, Union
|
|
11
|
+
|
|
12
|
+
from polars import Expr
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OperatorTemplate:
|
|
16
|
+
"""基于现有算子创建变体的模板"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
name: str,
|
|
21
|
+
category: str,
|
|
22
|
+
template: str,
|
|
23
|
+
defaults: Optional[Dict[str, Any]] = None,
|
|
24
|
+
):
|
|
25
|
+
"""初始化模板
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
name: 新算子名称
|
|
29
|
+
category: 算子分类 (point, time, section, multi_section, talib)
|
|
30
|
+
template: 模板算子名称
|
|
31
|
+
defaults: 默认参数字典
|
|
32
|
+
"""
|
|
33
|
+
self._name = name
|
|
34
|
+
self._category = category
|
|
35
|
+
self._template = template
|
|
36
|
+
self._defaults = defaults or {}
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def name(self) -> str:
|
|
40
|
+
return self._name
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def category(self) -> str:
|
|
44
|
+
return self._category
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def template(self) -> str:
|
|
48
|
+
return self._template
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def defaults(self) -> Dict[str, Any]:
|
|
52
|
+
return self._defaults.copy()
|
|
53
|
+
|
|
54
|
+
def __call__(self, f: Union[Expr, str], **kwargs) -> Expr:
|
|
55
|
+
"""调用时执行模板算子,自动注入默认值"""
|
|
56
|
+
from QuantNodes.factor_node.factor_functions import get_operator
|
|
57
|
+
|
|
58
|
+
template_func = get_operator(self._template, self._category)
|
|
59
|
+
if template_func is None:
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"Template operator '{self._template}' not found in category '{self._category}'"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
merged_kwargs = {**self._defaults, **kwargs}
|
|
65
|
+
return template_func(f, **merged_kwargs)
|
|
66
|
+
|
|
67
|
+
def register(self) -> "OperatorTemplate":
|
|
68
|
+
"""将模板注册为新的命名算子"""
|
|
69
|
+
from QuantNodes.operators.registry import _CustomOperatorRegistry
|
|
70
|
+
|
|
71
|
+
def _template_wrapper(f: Union[Expr, str], **kwargs) -> Expr:
|
|
72
|
+
return self(f, **kwargs)
|
|
73
|
+
|
|
74
|
+
_template_wrapper.__name__ = self._name
|
|
75
|
+
_template_wrapper.__qualname__ = f"OperatorTemplate.{self._name}"
|
|
76
|
+
_template_wrapper.__doc__ = (
|
|
77
|
+
f"基于 {self._template} 的模板算子,默认参数: {self._defaults}"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
_CustomOperatorRegistry.register(
|
|
81
|
+
self._category,
|
|
82
|
+
self._name,
|
|
83
|
+
_template_wrapper,
|
|
84
|
+
doc=_template_wrapper.__doc__,
|
|
85
|
+
params={"template": self._template, "defaults": self._defaults},
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return self
|
|
89
|
+
|
|
90
|
+
def __repr__(self) -> str:
|
|
91
|
+
return (
|
|
92
|
+
f"OperatorTemplate(name={self._name!r}, "
|
|
93
|
+
f"template={self._template!r}, "
|
|
94
|
+
f"defaults={self._defaults})"
|
|
95
|
+
)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
时间序列算子(代理层)
|
|
4
|
+
|
|
5
|
+
基于 factor_functions/time_ops.py 的实现,提供统一的类接口。
|
|
6
|
+
|
|
7
|
+
Available Operators:
|
|
8
|
+
- ts_mean: 滚动均值
|
|
9
|
+
- ts_std: 滚动标准差
|
|
10
|
+
- ts_max: 滚动最大值
|
|
11
|
+
- ts_min: 滚动最小值
|
|
12
|
+
- ts_sum: 滚动求和
|
|
13
|
+
- ts_median: 滚动中位数
|
|
14
|
+
- ts_corr: 滚动相关系数
|
|
15
|
+
- ts_cov: 滚动协方差
|
|
16
|
+
- ts_rank: 滚动排名
|
|
17
|
+
- ts_delta: 差分
|
|
18
|
+
- ts_pct_change: 百分比变化
|
|
19
|
+
- ts_lag: 滞后
|
|
20
|
+
- ts_shift: 前向移动
|
|
21
|
+
- ts_lead: 后向移动
|
|
22
|
+
- ts_prod: 滚动求积
|
|
23
|
+
- ewm_mean: 指数加权移动平均
|
|
24
|
+
- ewm_std: 指数加权移动标准差
|
|
25
|
+
- ewm_corr: 指数加权相关系数
|
|
26
|
+
|
|
27
|
+
Usage:
|
|
28
|
+
>>> ts.ts_mean(pl.col("close"), 20)
|
|
29
|
+
>>> ts.ts_std(pl.col("close"), 20)
|
|
30
|
+
>>> ts.ts_corr(pl.col("close"), pl.col("volume"), 20)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
from typing import TYPE_CHECKING, Union, Optional
|
|
36
|
+
|
|
37
|
+
from polars import Expr
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
from QuantNodes.factor_node.factor_functions.time_ops import (
|
|
43
|
+
ts_mean as _ts_mean,
|
|
44
|
+
ts_std as _ts_std,
|
|
45
|
+
ts_max as _ts_max,
|
|
46
|
+
ts_min as _ts_min,
|
|
47
|
+
ts_sum as _ts_sum,
|
|
48
|
+
rolling_prod as _ts_prod,
|
|
49
|
+
ts_median as _ts_median,
|
|
50
|
+
ts_corr as _ts_corr,
|
|
51
|
+
ts_cov as _ts_cov,
|
|
52
|
+
ts_rank as _ts_rank,
|
|
53
|
+
ts_delta as _ts_delta,
|
|
54
|
+
ts_pct_change as _ts_pct_change,
|
|
55
|
+
ts_lag as _ts_lag,
|
|
56
|
+
ts_lead as _ts_lead,
|
|
57
|
+
ewm_mean as _ewm_mean,
|
|
58
|
+
ewm_std as _ewm_std,
|
|
59
|
+
ewm_corr as _ewm_corr,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TimeSeriesOperators:
|
|
64
|
+
"""时间序列算子(代理层)"""
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def ts_mean(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
68
|
+
return _ts_mean(expr, window=window, min_periods=min_periods)
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def ts_std(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None, ddof: int = 1) -> Expr:
|
|
72
|
+
return _ts_std(expr, window=window, min_periods=min_periods, ddof=ddof)
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def ts_max(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
76
|
+
return _ts_max(expr, window=window, min_periods=min_periods)
|
|
77
|
+
|
|
78
|
+
@staticmethod
|
|
79
|
+
def ts_min(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
80
|
+
return _ts_min(expr, window=window, min_periods=min_periods)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def ts_sum(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
84
|
+
return _ts_sum(expr, window=window, min_periods=min_periods)
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def ts_prod(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
88
|
+
return _ts_prod(expr, window=window, min_periods=min_periods)
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def ts_median(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
92
|
+
return _ts_median(expr, window=window, min_periods=min_periods)
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def ts_corr(expr_a: Union[Expr, str], expr_b: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
96
|
+
return _ts_corr(expr_a, expr_b, window=window, min_periods=min_periods)
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def ts_cov(expr_a: Union[Expr, str], expr_b: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
100
|
+
return _ts_cov(expr_a, expr_b, window=window, min_periods=min_periods)
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def ts_rank(expr: Union[Expr, str], window: int = 20, min_periods: Optional[int] = None) -> Expr:
|
|
104
|
+
return _ts_rank(expr, window=window, min_periods=min_periods)
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def ts_delta(expr: Union[Expr, str], periods: int = 1) -> Expr:
|
|
108
|
+
return _ts_delta(expr, periods=periods)
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def ts_pct_change(expr: Union[Expr, str], periods: int = 1) -> Expr:
|
|
112
|
+
return _ts_pct_change(expr, periods=periods)
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def ts_lag(expr: Union[Expr, str], periods: int = 1) -> Expr:
|
|
116
|
+
return _ts_lag(expr, periods=periods)
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def ts_shift(expr: Union[Expr, str], periods: int = 1) -> Expr:
|
|
120
|
+
return _ts_lag(expr, periods=periods)
|
|
121
|
+
|
|
122
|
+
@staticmethod
|
|
123
|
+
def ts_lead(expr: Union[Expr, str], periods: int = 1) -> Expr:
|
|
124
|
+
return _ts_lead(expr, periods=periods)
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def ewm_mean(expr: Union[Expr, str], alpha: float = 0.5, adjust: bool = True) -> Expr:
|
|
128
|
+
return _ewm_mean(expr, alpha=alpha, adjust=adjust)
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def ewm_std(expr: Union[Expr, str], alpha: float = 0.5, adjust: bool = True) -> Expr:
|
|
132
|
+
return _ewm_std(expr, alpha=alpha, adjust=adjust)
|
|
133
|
+
|
|
134
|
+
@staticmethod
|
|
135
|
+
def ewm_corr(expr_a: Union[Expr, str], expr_b: Union[Expr, str], alpha: float = 0.5) -> Expr:
|
|
136
|
+
return _ewm_corr(expr_a, expr_b, alpha=alpha)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
QuantNodes Prompts Package
|
|
4
|
+
|
|
5
|
+
Complete prompts for external agents with reference code.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .strategy.momentum import MOMENTUM_PROMPT
|
|
9
|
+
from .strategy.mean_reversion import MEAN_REVERSION_PROMPT
|
|
10
|
+
from .strategy.trend_following import TREND_FOLLOWING_PROMPT
|
|
11
|
+
from .strategy.pairs_trading import PAIRS_TRADING_PROMPT
|
|
12
|
+
from .strategy.market_neutral import MARKET_NEUTRAL_PROMPT
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"MOMENTUM_PROMPT",
|
|
16
|
+
"MEAN_REVERSION_PROMPT",
|
|
17
|
+
"TREND_FOLLOWING_PROMPT",
|
|
18
|
+
"PAIRS_TRADING_PROMPT",
|
|
19
|
+
"MARKET_NEUTRAL_PROMPT",
|
|
20
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Factor-Based Backtest Prompt
|
|
4
|
+
|
|
5
|
+
Complete prompt for running factor-based backtests.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class BacktestPrompt:
|
|
14
|
+
version: str = "1.0.0"
|
|
15
|
+
name: str = "factor_based"
|
|
16
|
+
description: str = "因子回测"
|
|
17
|
+
created_at: str = "2025-05-14"
|
|
18
|
+
updated_at: str = "2025-05-14"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """你是一个量化回测专家,擅长运行因子回测。
|
|
23
|
+
|
|
24
|
+
## 因子回测流程
|
|
25
|
+
1. 计算因子值
|
|
26
|
+
2. 根据因子值排序分组
|
|
27
|
+
3. 计算各组收益率
|
|
28
|
+
4. 分析因子有效性
|
|
29
|
+
|
|
30
|
+
## 参数说明
|
|
31
|
+
- `factor_code`: 计算因子的代码,必须将结果赋给 result 变量
|
|
32
|
+
- `start_date`: 回测开始日期
|
|
33
|
+
- `end_date`: 回测结束日期
|
|
34
|
+
- `num_groups`: 分组数量 (默认5组)
|
|
35
|
+
|
|
36
|
+
## result 数据格式
|
|
37
|
+
result 必须是 DataFrame (Polars 或 Pandas 均可),包含:
|
|
38
|
+
- date: 日期
|
|
39
|
+
- code: 标的代码
|
|
40
|
+
- factor_value: 因子值
|
|
41
|
+
- forward_return: 未来收益
|
|
42
|
+
|
|
43
|
+
## 参考代码 (Polars)
|
|
44
|
+
```python
|
|
45
|
+
import polars as pl
|
|
46
|
+
|
|
47
|
+
result = pl.DataFrame({
|
|
48
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
49
|
+
"code": ["A", "B", "A", "B"],
|
|
50
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
51
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 参考代码 (Pandas)
|
|
56
|
+
```python
|
|
57
|
+
import pandas as pd
|
|
58
|
+
|
|
59
|
+
result = pd.DataFrame({
|
|
60
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
61
|
+
"code": ["A", "B", "A", "B"],
|
|
62
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
63
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def required_params(self) -> List[str]:
|
|
70
|
+
return ["factor_code", "start_date", "end_date", "num_groups"]
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def output_format(self) -> str:
|
|
74
|
+
return "factor_backtest_result"
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def validation_rules(self) -> Dict[str, Any]:
|
|
78
|
+
return {
|
|
79
|
+
"max_lines": 300,
|
|
80
|
+
"allowed_imports": ["polars", "numpy", "pandas"],
|
|
81
|
+
"forbidden_patterns": ["os.", "subprocess", "eval", "exec"],
|
|
82
|
+
"required_variables": ["result"]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
FACTOR_BACKTEST_PROMPT = BacktestPrompt()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Standard Backtest Prompt
|
|
4
|
+
|
|
5
|
+
Complete prompt for running standard backtests.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class BacktestPrompt:
|
|
14
|
+
version: str = "1.0.0"
|
|
15
|
+
name: str = "standard"
|
|
16
|
+
description: str = "标准回测"
|
|
17
|
+
created_at: str = "2025-05-14"
|
|
18
|
+
updated_at: str = "2025-05-14"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """你是一个量化回测专家,擅长运行标准回测。
|
|
23
|
+
|
|
24
|
+
## 回测流程
|
|
25
|
+
1. 准备历史价格数据
|
|
26
|
+
2. 创建策略实例
|
|
27
|
+
3. 创建经纪商实例
|
|
28
|
+
4. 运行回测获取结果
|
|
29
|
+
|
|
30
|
+
## 参数说明
|
|
31
|
+
- `start_date`: 回测开始日期 (YYYY-MM-DD)
|
|
32
|
+
- `end_date`: 回测结束日期 (YYYY-MM-DD)
|
|
33
|
+
- `initial_cash`: 初始资金 (默认 100000)
|
|
34
|
+
- `commission`: 手续费率 (默认 0.001)
|
|
35
|
+
|
|
36
|
+
## 约束
|
|
37
|
+
- 策略代码必须安全,使用 CodeSandbox 验证
|
|
38
|
+
- 必须创建 strategy, broker, quote_data 变量
|
|
39
|
+
- quote_data 必须包含 date, close 列
|
|
40
|
+
|
|
41
|
+
## 参考代码框架
|
|
42
|
+
```python
|
|
43
|
+
import pandas as pd
|
|
44
|
+
import numpy as np
|
|
45
|
+
from QuantNodes.backtest.strategy_node import MAStrategyNode
|
|
46
|
+
from QuantNodes.backtest.broker_node import SimulatedBrokerNode
|
|
47
|
+
|
|
48
|
+
strategy = MAStrategyNode(config={'short_window': 5, 'long_window': 20})
|
|
49
|
+
broker = SimulatedBrokerNode(config={'cash': 1000000, 'commission': 0.001})
|
|
50
|
+
|
|
51
|
+
quote_data = pd.read_csv('data.csv')
|
|
52
|
+
```
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def required_params(self) -> List[str]:
|
|
57
|
+
return ["pipeline_code", "start_date", "end_date"]
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def output_format(self) -> str:
|
|
61
|
+
return "backtest_result"
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def validation_rules(self) -> Dict[str, Any]:
|
|
65
|
+
return {
|
|
66
|
+
"max_lines": 300,
|
|
67
|
+
"allowed_imports": ["numpy", "pandas"],
|
|
68
|
+
"forbidden_patterns": ["os.", "subprocess", "eval", "exec"],
|
|
69
|
+
"required_variables": ["strategy", "broker", "quote_data"]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
STANDARD_BACKTEST_PROMPT = BacktestPrompt()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Factor Prompts
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .ic_analysis import IC_ANALYSIS_PROMPT
|
|
7
|
+
from .group_backtest import GROUP_BACKTEST_PROMPT
|
|
8
|
+
from .correlation import CORRELATION_PROMPT
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"IC_ANALYSIS_PROMPT",
|
|
12
|
+
"GROUP_BACKTEST_PROMPT",
|
|
13
|
+
"CORRELATION_PROMPT",
|
|
14
|
+
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Correlation Analysis Prompt
|
|
4
|
+
|
|
5
|
+
Complete prompt for factor correlation analysis.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class FactorPrompt:
|
|
14
|
+
version: str = "1.0.0"
|
|
15
|
+
name: str = "correlation"
|
|
16
|
+
description: str = "相关性分析"
|
|
17
|
+
created_at: str = "2025-05-14"
|
|
18
|
+
updated_at: str = "2025-05-14"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """你是一个因子分析专家,擅长相关性分析。
|
|
23
|
+
|
|
24
|
+
## 相关性分析说明
|
|
25
|
+
分析因子之间的相关性,避免高度相关的因子同时使用。
|
|
26
|
+
- 因子相关性高:冗余,增加风险
|
|
27
|
+
- 因子相关性低:互补,分散风险
|
|
28
|
+
|
|
29
|
+
## 参数说明
|
|
30
|
+
- `factor_code`: 计算因子的代码
|
|
31
|
+
- `correlation_threshold`: 相关性阈值 (默认0.8)
|
|
32
|
+
|
|
33
|
+
## result 数据格式
|
|
34
|
+
result 必须是 DataFrame (Polars 或 Pandas 均可),包含多列因子值
|
|
35
|
+
|
|
36
|
+
## 参考代码 (Polars)
|
|
37
|
+
```python
|
|
38
|
+
import polars as pl
|
|
39
|
+
|
|
40
|
+
result = pl.DataFrame({
|
|
41
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02"],
|
|
42
|
+
"factor_a": [0.1, 0.2, 0.3],
|
|
43
|
+
"factor_b": [0.15, 0.25, 0.35],
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 参考代码 (Pandas)
|
|
48
|
+
```python
|
|
49
|
+
import pandas as pd
|
|
50
|
+
|
|
51
|
+
result = pd.DataFrame({
|
|
52
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02"],
|
|
53
|
+
"factor_a": [0.1, 0.2, 0.3],
|
|
54
|
+
"factor_b": [0.15, 0.25, 0.35],
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def required_params(self) -> List[str]:
|
|
61
|
+
return ["factor_code", "correlation_threshold"]
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def output_format(self) -> str:
|
|
65
|
+
return "correlation_result"
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def validation_rules(self) -> Dict[str, Any]:
|
|
69
|
+
return {
|
|
70
|
+
"max_lines": 200,
|
|
71
|
+
"allowed_imports": ["polars", "numpy", "pandas"],
|
|
72
|
+
"forbidden_patterns": ["os.", "subprocess", "eval", "exec"],
|
|
73
|
+
"required_variables": ["result"]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
CORRELATION_PROMPT = FactorPrompt()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Group Backtest Prompt
|
|
4
|
+
|
|
5
|
+
Complete prompt for group-based backtest analysis.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class FactorPrompt:
|
|
14
|
+
version: str = "1.0.0"
|
|
15
|
+
name: str = "group_backtest"
|
|
16
|
+
description: str = "分组回测"
|
|
17
|
+
created_at: str = "2025-05-14"
|
|
18
|
+
updated_at: str = "2025-05-14"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """你是一个因子分析专家,擅长分组回测。
|
|
23
|
+
|
|
24
|
+
## 分组回测说明
|
|
25
|
+
分组回测是检验因子有效性的经典方法:
|
|
26
|
+
1. 按因子值将股票分成N组
|
|
27
|
+
2. 持有各组一定时间
|
|
28
|
+
3. 计算各组收益率差异
|
|
29
|
+
|
|
30
|
+
## 参数说明
|
|
31
|
+
- `factor_code`: 计算因子的代码
|
|
32
|
+
- `num_groups`: 分组数量 (通常5组)
|
|
33
|
+
- `start_date`: 回测开始日期
|
|
34
|
+
- `end_date`: 回测结束日期
|
|
35
|
+
|
|
36
|
+
## result 数据格式
|
|
37
|
+
result 必须是 DataFrame (Polars 或 Pandas 均可),包含:
|
|
38
|
+
- date: 日期
|
|
39
|
+
- code: 标的代码
|
|
40
|
+
- factor_value: 因子值
|
|
41
|
+
- forward_return: 未来收益
|
|
42
|
+
|
|
43
|
+
## 参考代码 (Polars)
|
|
44
|
+
```python
|
|
45
|
+
import polars as pl
|
|
46
|
+
|
|
47
|
+
result = pl.DataFrame({
|
|
48
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
49
|
+
"code": ["A", "B", "A", "B"],
|
|
50
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
51
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 参考代码 (Pandas)
|
|
56
|
+
```python
|
|
57
|
+
import pandas as pd
|
|
58
|
+
|
|
59
|
+
result = pd.DataFrame({
|
|
60
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
61
|
+
"code": ["A", "B", "A", "B"],
|
|
62
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
63
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def required_params(self) -> List[str]:
|
|
70
|
+
return ["factor_code", "num_groups", "start_date", "end_date"]
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def output_format(self) -> str:
|
|
74
|
+
return "group_backtest_result"
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def validation_rules(self) -> Dict[str, Any]:
|
|
78
|
+
return {
|
|
79
|
+
"max_lines": 200,
|
|
80
|
+
"allowed_imports": ["polars", "numpy", "pandas"],
|
|
81
|
+
"forbidden_patterns": ["os.", "subprocess", "eval", "exec"],
|
|
82
|
+
"required_variables": ["result"]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
GROUP_BACKTEST_PROMPT = FactorPrompt()
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
IC Analysis Prompt
|
|
4
|
+
|
|
5
|
+
Complete prompt for IC (Information Coefficient) analysis.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class FactorPrompt:
|
|
14
|
+
version: str = "1.0.0"
|
|
15
|
+
name: str = "ic_analysis"
|
|
16
|
+
description: str = "IC分析"
|
|
17
|
+
created_at: str = "2025-05-14"
|
|
18
|
+
updated_at: str = "2025-05-14"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """你是一个因子分析专家,擅长IC分析。
|
|
23
|
+
|
|
24
|
+
## IC分析说明
|
|
25
|
+
IC (Information Coefficient) 衡量因子预测能力。
|
|
26
|
+
- IC > 0 表示因子与收益正相关
|
|
27
|
+
- IC < 0 表示因子与收益负相关
|
|
28
|
+
- |IC| 越大表示预测能力越强
|
|
29
|
+
|
|
30
|
+
## IC指标
|
|
31
|
+
- IC Mean: IC时间序列均值
|
|
32
|
+
- IC Std: IC时间序列标准差
|
|
33
|
+
- ICIR: IC Mean / IC Std (信息比)
|
|
34
|
+
- Rank IC Mean: 秩相关系数均值
|
|
35
|
+
|
|
36
|
+
## 参数说明
|
|
37
|
+
- `factor_code`: 计算因子的代码,必须将结果赋给 result 变量
|
|
38
|
+
- `start_date`: 分析开始日期
|
|
39
|
+
- `end_date`: 分析结束日期
|
|
40
|
+
|
|
41
|
+
## result 数据格式
|
|
42
|
+
result 必须是 DataFrame (Polars 或 Pandas 均可),包含:
|
|
43
|
+
- date: 日期
|
|
44
|
+
- code: 标的代码
|
|
45
|
+
- factor_value: 因子值
|
|
46
|
+
- forward_return: 未来收益
|
|
47
|
+
|
|
48
|
+
## 参考代码 (Polars)
|
|
49
|
+
```python
|
|
50
|
+
import polars as pl
|
|
51
|
+
|
|
52
|
+
result = pl.DataFrame({
|
|
53
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
54
|
+
"code": ["A", "B", "A", "B"],
|
|
55
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
56
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 参考代码 (Pandas)
|
|
61
|
+
```python
|
|
62
|
+
import pandas as pd
|
|
63
|
+
|
|
64
|
+
result = pd.DataFrame({
|
|
65
|
+
"date": ["2024-01-01", "2024-01-01", "2024-01-02", "2024-01-02"],
|
|
66
|
+
"code": ["A", "B", "A", "B"],
|
|
67
|
+
"factor_value": [0.1, 0.2, 0.3, 0.4],
|
|
68
|
+
"forward_return": [0.05, 0.03, 0.02, 0.01],
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def required_params(self) -> List[str]:
|
|
75
|
+
return ["factor_code", "start_date", "end_date"]
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def output_format(self) -> str:
|
|
79
|
+
return "ic_analysis_result"
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def validation_rules(self) -> Dict[str, Any]:
|
|
83
|
+
return {
|
|
84
|
+
"max_lines": 200,
|
|
85
|
+
"allowed_imports": ["polars", "numpy", "pandas"],
|
|
86
|
+
"forbidden_patterns": ["os.", "subprocess", "eval", "exec"],
|
|
87
|
+
"required_variables": ["result"]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
IC_ANALYSIS_PROMPT = FactorPrompt()
|