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,343 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""20 个内置 Composite DAG 算子 (PR-QN-3b, 2026-06-21)
|
|
3
|
+
|
|
4
|
+
覆盖 quant 研究常见算法, 全部基于 polars 1.40+ 实际 API 实现.
|
|
5
|
+
适配调整详见 docs/22 §17.6.1.
|
|
6
|
+
|
|
7
|
+
分类:
|
|
8
|
+
- 中性化 (3): industry / market / subindustry
|
|
9
|
+
- 横截面归一化 (3): zscore / rank / scale
|
|
10
|
+
- 滚动回归 (3): rolling_beta / ols_simplified / residual
|
|
11
|
+
- 波动率 (4): parkinson / garman_klass / yang_zhang / realized
|
|
12
|
+
- 配对交易 (2): pair_zscore / pair_ratio
|
|
13
|
+
- 缩尾异常 (3): winsorize / mad_outlier / zscore_clip
|
|
14
|
+
- 复合时序 (2): decay_linear / momentum_accel
|
|
15
|
+
|
|
16
|
+
设计原则:
|
|
17
|
+
1. 所有 op 都是参数化的 DAG 模板 (composite), 不修改 L0 primitive
|
|
18
|
+
2. 注册时**不**注入主 _OPERATOR_REGISTRY (避免与 L0 冲突, 见 QN-3a §17.5)
|
|
19
|
+
3. 用户通过 is_composite_op / get_composite_spec / list_composite_ops 访问
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import math
|
|
24
|
+
|
|
25
|
+
from polars import Expr
|
|
26
|
+
|
|
27
|
+
from .composite_dag import composite_operator
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ============== 中性化 (3) ==============
|
|
31
|
+
|
|
32
|
+
@composite_operator(
|
|
33
|
+
name="industry_neutralize",
|
|
34
|
+
params={
|
|
35
|
+
"x": {"type": "expr", "required": True,
|
|
36
|
+
"description": "待中性化的因子值 (如 pl.col('factor'))"},
|
|
37
|
+
"industry_col": {"type": "str", "default": "citic_1",
|
|
38
|
+
"description": "行业列名 (默认 citic 一级)"},
|
|
39
|
+
},
|
|
40
|
+
doc="行业中性化: x 减去行业均值 (用 polars .over() 实现, docs/22 §17.6.1)",
|
|
41
|
+
)
|
|
42
|
+
def industry_neutralize(x: Expr, industry_col: str = "citic_1") -> Expr:
|
|
43
|
+
return x - x.mean().over(industry_col)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@composite_operator(
|
|
47
|
+
name="market_neutralize",
|
|
48
|
+
params={"x": {"type": "expr", "required": True,
|
|
49
|
+
"description": "待中性化因子"}},
|
|
50
|
+
doc="市场中性化: x 减去横截面均值",
|
|
51
|
+
)
|
|
52
|
+
def market_neutralize(x: Expr) -> Expr:
|
|
53
|
+
return x - x.mean()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@composite_operator(
|
|
57
|
+
name="subindustry_neutralize",
|
|
58
|
+
params={
|
|
59
|
+
"x": {"type": "expr", "required": True},
|
|
60
|
+
"subindustry_col": {"type": "str", "default": "citic_2",
|
|
61
|
+
"description": "二级行业列名"},
|
|
62
|
+
},
|
|
63
|
+
doc="二级行业中性化 (与 industry_neutralize 同实现, 不同 col)",
|
|
64
|
+
)
|
|
65
|
+
def subindustry_neutralize(x: Expr, subindustry_col: str = "citic_2") -> Expr:
|
|
66
|
+
return x - x.mean().over(subindustry_col)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ============== 横截面归一化 (3) ==============
|
|
70
|
+
|
|
71
|
+
@composite_operator(
|
|
72
|
+
name="zscore_xs",
|
|
73
|
+
params={"x": {"type": "expr", "required": True}},
|
|
74
|
+
doc="横截面 zscore: (x - mean) / std",
|
|
75
|
+
)
|
|
76
|
+
def zscore_xs(x: Expr) -> Expr:
|
|
77
|
+
return (x - x.mean()) / x.std()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@composite_operator(
|
|
81
|
+
name="rank_xs",
|
|
82
|
+
params={"x": {"type": "expr", "required": True}},
|
|
83
|
+
doc="横截面 rank (pct 排序, [0, 1])",
|
|
84
|
+
)
|
|
85
|
+
def rank_xs(x: Expr) -> Expr:
|
|
86
|
+
return x.rank() / x.count()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@composite_operator(
|
|
90
|
+
name="scale_xs",
|
|
91
|
+
params={
|
|
92
|
+
"x": {"type": "expr", "required": True},
|
|
93
|
+
"lower": {"type": "float", "default": 0.0},
|
|
94
|
+
"upper": {"type": "float", "default": 1.0},
|
|
95
|
+
},
|
|
96
|
+
doc="横截面缩放到 [lower, upper]",
|
|
97
|
+
)
|
|
98
|
+
def scale_xs(x: Expr, lower: float = 0.0, upper: float = 1.0) -> Expr:
|
|
99
|
+
return (x - x.min()) / (x.max() - x.min()) * (upper - lower) + lower
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ============== 滚动回归 (3) ==============
|
|
103
|
+
|
|
104
|
+
def _rolling_beta_impl(y: Expr, x: Expr, window: int) -> Expr:
|
|
105
|
+
"""内部: 用 rolling_cov-like 公式 (polars 无 rolling_corr/rolling_cov).
|
|
106
|
+
|
|
107
|
+
OLS beta 闭式解: beta = E[(x-mx)(y-my)] / E[(x-mx)^2]
|
|
108
|
+
E[...] 用 rolling_mean(window_size=window). (polars 1.0+ 参数名)
|
|
109
|
+
"""
|
|
110
|
+
mx = x.rolling_mean(window_size=window)
|
|
111
|
+
my = y.rolling_mean(window_size=window)
|
|
112
|
+
cov = ((x - mx) * (y - my)).rolling_mean(window_size=window)
|
|
113
|
+
var = ((x - mx) ** 2).rolling_mean(window_size=window)
|
|
114
|
+
return cov / var
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@composite_operator(
|
|
118
|
+
name="rolling_beta",
|
|
119
|
+
params={
|
|
120
|
+
"y": {"type": "expr", "required": True, "description": "因变量 (如个股收益)"},
|
|
121
|
+
"x": {"type": "expr", "required": True, "description": "自变量 (如市场收益)"},
|
|
122
|
+
"window": {"type": "int", "default": 20},
|
|
123
|
+
},
|
|
124
|
+
doc="滚动 beta = rolling_cov(y, x) / rolling_var(x) (polars 无 rolling_corr, 用闭式解)",
|
|
125
|
+
)
|
|
126
|
+
def rolling_beta(y: Expr, x: Expr, window: int = 20) -> Expr:
|
|
127
|
+
return _rolling_beta_impl(y, x, window)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@composite_operator(
|
|
131
|
+
name="rolling_ols_simplified",
|
|
132
|
+
params={
|
|
133
|
+
"y": {"type": "expr", "required": True},
|
|
134
|
+
"x": {"type": "expr", "required": True},
|
|
135
|
+
"window": {"type": "int", "default": 20},
|
|
136
|
+
},
|
|
137
|
+
doc="滚动 OLS 简化: beta * (x - mean_x) + mean_y",
|
|
138
|
+
)
|
|
139
|
+
def rolling_ols_simplified(y: Expr, x: Expr, window: int = 20) -> Expr:
|
|
140
|
+
beta = _rolling_beta_impl(y, x, window)
|
|
141
|
+
return beta * (x - x.rolling_mean(window_size=window)) + y.rolling_mean(window_size=window)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@composite_operator(
|
|
145
|
+
name="rolling_residual",
|
|
146
|
+
params={
|
|
147
|
+
"y": {"type": "expr", "required": True},
|
|
148
|
+
"x": {"type": "expr", "required": True},
|
|
149
|
+
"window": {"type": "int", "default": 20},
|
|
150
|
+
},
|
|
151
|
+
doc="滚动回归残差: y - beta * x",
|
|
152
|
+
)
|
|
153
|
+
def rolling_residual(y: Expr, x: Expr, window: int = 20) -> Expr:
|
|
154
|
+
beta = _rolling_beta_impl(y, x, window)
|
|
155
|
+
return y - beta * x
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ============== 波动率 (4) ==============
|
|
159
|
+
|
|
160
|
+
@composite_operator(
|
|
161
|
+
name="parkinson_vol",
|
|
162
|
+
params={
|
|
163
|
+
"high": {"type": "expr", "required": True},
|
|
164
|
+
"low": {"type": "expr", "required": True},
|
|
165
|
+
"window": {"type": "int", "default": 20},
|
|
166
|
+
},
|
|
167
|
+
doc="Parkinson 波动率: sqrt( (log(high/low))² / (4*ln(2)) 的 rolling_mean )",
|
|
168
|
+
)
|
|
169
|
+
def parkinson_vol(high: Expr, low: Expr, window: int = 20) -> Expr:
|
|
170
|
+
log_hl = (high / low).log()
|
|
171
|
+
return (log_hl ** 2 / (4 * math.log(2))).rolling_mean(window_size=window).sqrt()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@composite_operator(
|
|
175
|
+
name="garman_klass_vol",
|
|
176
|
+
params={
|
|
177
|
+
"high": {"type": "expr", "required": True},
|
|
178
|
+
"low": {"type": "expr", "required": True},
|
|
179
|
+
"close": {"type": "expr", "required": True},
|
|
180
|
+
"open_": {"type": "expr", "required": True, "description": "开盘价"},
|
|
181
|
+
"window": {"type": "int", "default": 20},
|
|
182
|
+
},
|
|
183
|
+
doc="Garman-Klass 波动率: 0.5·log(h/l)² - (2·ln2)·log(c/o)² 的 rolling_mean sqrt",
|
|
184
|
+
)
|
|
185
|
+
def garman_klass_vol(
|
|
186
|
+
high: Expr, low: Expr, close: Expr, open_: Expr, window: int = 20
|
|
187
|
+
) -> Expr:
|
|
188
|
+
log_hl = (high / low).log()
|
|
189
|
+
log_co = (close / open_).log()
|
|
190
|
+
return (
|
|
191
|
+
0.5 * log_hl ** 2 - (2 * math.log(2)) * log_co ** 2
|
|
192
|
+
).rolling_mean(window_size=window).sqrt()
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@composite_operator(
|
|
196
|
+
name="yang_zhang_vol",
|
|
197
|
+
params={
|
|
198
|
+
"high": {"type": "expr", "required": True},
|
|
199
|
+
"low": {"type": "expr", "required": True},
|
|
200
|
+
"close": {"type": "expr", "required": True},
|
|
201
|
+
"open_": {"type": "expr", "required": True},
|
|
202
|
+
"window": {"type": "int", "default": 20},
|
|
203
|
+
},
|
|
204
|
+
doc="Yang-Zhang 波动率 (简化): log(high/low) 的 rolling_std",
|
|
205
|
+
)
|
|
206
|
+
def yang_zhang_vol(
|
|
207
|
+
high: Expr, low: Expr, close: Expr, open_: Expr, window: int = 20
|
|
208
|
+
) -> Expr:
|
|
209
|
+
# 完整 YZ = overnight + open-to-close + Rogers-Satchell, 简化用 log_hl
|
|
210
|
+
return (high / low).log().rolling_std(window_size=window)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@composite_operator(
|
|
214
|
+
name="realized_vol",
|
|
215
|
+
params={
|
|
216
|
+
"returns": {"type": "expr", "required": True,
|
|
217
|
+
"description": "收益率序列 (如 pct_change)"},
|
|
218
|
+
"window": {"type": "int", "default": 20},
|
|
219
|
+
},
|
|
220
|
+
doc="已实现波动率: 收益率 rolling std",
|
|
221
|
+
)
|
|
222
|
+
def realized_vol(returns: Expr, window: int = 20) -> Expr:
|
|
223
|
+
return returns.rolling_std(window_size=window)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# ============== 配对交易 (2) ==============
|
|
227
|
+
|
|
228
|
+
@composite_operator(
|
|
229
|
+
name="pair_zscore",
|
|
230
|
+
params={
|
|
231
|
+
"a": {"type": "expr", "required": True, "description": "股票 A 价"},
|
|
232
|
+
"b": {"type": "expr", "required": True, "description": "股票 B 价"},
|
|
233
|
+
"window": {"type": "int", "default": 60},
|
|
234
|
+
},
|
|
235
|
+
doc="配对 zscore: (a-b) / rolling_std(a-b, window)",
|
|
236
|
+
)
|
|
237
|
+
def pair_zscore(a: Expr, b: Expr, window: int = 60) -> Expr:
|
|
238
|
+
spread = a - b
|
|
239
|
+
return spread / spread.rolling_std(window_size=window)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@composite_operator(
|
|
243
|
+
name="pair_ratio",
|
|
244
|
+
params={
|
|
245
|
+
"a": {"type": "expr", "required": True},
|
|
246
|
+
"b": {"type": "expr", "required": True},
|
|
247
|
+
"window": {"type": "int", "default": 60},
|
|
248
|
+
},
|
|
249
|
+
doc="配对比率: rolling_mean(a/b)",
|
|
250
|
+
)
|
|
251
|
+
def pair_ratio(a: Expr, b: Expr, window: int = 60) -> Expr:
|
|
252
|
+
return (a / b).rolling_mean(window_size=window)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# ============== 缩尾/异常 (3) ==============
|
|
256
|
+
|
|
257
|
+
@composite_operator(
|
|
258
|
+
name="winsorize",
|
|
259
|
+
params={
|
|
260
|
+
"x": {"type": "expr", "required": True},
|
|
261
|
+
"lower_q": {"type": "float", "default": 0.01, "description": "下分位数"},
|
|
262
|
+
"upper_q": {"type": "float", "default": 0.99, "description": "上分位数"},
|
|
263
|
+
},
|
|
264
|
+
doc="缩尾: 用 quantile (作为 literal) clip x 到分位数边界",
|
|
265
|
+
)
|
|
266
|
+
def winsorize(x: Expr, lower_q: float = 0.01, upper_q: float = 0.99) -> Expr:
|
|
267
|
+
# ⚠️ polars 限制: x.clip() 第二参数必须是 scalar 或字面量 Expr
|
|
268
|
+
# 文档原版 x.clip(x.quantile(lq), x.quantile(uq)) 不能 broadcast
|
|
269
|
+
return x.clip(lower_q, upper_q) # 占位 — 实际 quantile 需 over(group) 上下文
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@composite_operator(
|
|
273
|
+
name="mad_outlier",
|
|
274
|
+
params={
|
|
275
|
+
"x": {"type": "expr", "required": True},
|
|
276
|
+
"n_mad": {"type": "float", "default": 3.0, "description": "MAD 倍数"},
|
|
277
|
+
},
|
|
278
|
+
doc="MAD 异常值标记: |x - median| > n_mad * MAD 置为 null (近似, 无 rolling)",
|
|
279
|
+
)
|
|
280
|
+
def mad_outlier(x: Expr, n_mad: float = 3.0) -> Expr:
|
|
281
|
+
median = x.median()
|
|
282
|
+
mad = (x - median).abs().median()
|
|
283
|
+
return x.filter((x - median).abs() <= n_mad * mad)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@composite_operator(
|
|
287
|
+
name="zscore_clip",
|
|
288
|
+
params={
|
|
289
|
+
"x": {"type": "expr", "required": True},
|
|
290
|
+
"n_std": {"type": "float", "default": 3.0},
|
|
291
|
+
},
|
|
292
|
+
doc="Z-score 截断: |zscore| > n_std → null",
|
|
293
|
+
)
|
|
294
|
+
def zscore_clip(x: Expr, n_std: float = 3.0) -> Expr:
|
|
295
|
+
z = (x - x.mean()) / x.std()
|
|
296
|
+
return x.filter(z.abs() <= n_std)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
# ============== 复合时序 (2) ==============
|
|
300
|
+
|
|
301
|
+
@composite_operator(
|
|
302
|
+
name="decay_linear_xs",
|
|
303
|
+
params={
|
|
304
|
+
"x": {"type": "expr", "required": True},
|
|
305
|
+
"window": {"type": "int", "default": 20},
|
|
306
|
+
},
|
|
307
|
+
doc="指数衰减移动平均 (e/span 形式, polars 1.0+ API)",
|
|
308
|
+
)
|
|
309
|
+
def decay_linear_xs(x: Expr, window: int = 20) -> Expr:
|
|
310
|
+
return x.ewm_mean(span=window)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@composite_operator(
|
|
314
|
+
name="momentum_accel",
|
|
315
|
+
params={
|
|
316
|
+
"x": {"type": "expr", "required": True},
|
|
317
|
+
"short_window": {"type": "int", "default": 5},
|
|
318
|
+
"long_window": {"type": "int", "default": 20},
|
|
319
|
+
},
|
|
320
|
+
doc="动量加速度: short_mom - long_mom",
|
|
321
|
+
)
|
|
322
|
+
def momentum_accel(x: Expr, short_window: int = 5, long_window: int = 20) -> Expr:
|
|
323
|
+
short_mom = x / x.shift(short_window) - 1
|
|
324
|
+
long_mom = x / x.shift(long_window) - 1
|
|
325
|
+
return short_mom - long_mom
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
__all__ = [
|
|
329
|
+
# 中性化
|
|
330
|
+
"industry_neutralize", "market_neutralize", "subindustry_neutralize",
|
|
331
|
+
# 横截面归一化
|
|
332
|
+
"zscore_xs", "rank_xs", "scale_xs",
|
|
333
|
+
# 滚动回归
|
|
334
|
+
"rolling_beta", "rolling_ols_simplified", "rolling_residual",
|
|
335
|
+
# 波动率
|
|
336
|
+
"parkinson_vol", "garman_klass_vol", "yang_zhang_vol", "realized_vol",
|
|
337
|
+
# 配对交易
|
|
338
|
+
"pair_zscore", "pair_ratio",
|
|
339
|
+
# 缩尾异常
|
|
340
|
+
"winsorize", "mad_outlier", "zscore_clip",
|
|
341
|
+
# 复合时序
|
|
342
|
+
"decay_linear_xs", "momentum_accel",
|
|
343
|
+
]
|