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,421 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""因子数据库
|
|
3
|
+
|
|
4
|
+
⚠️ DEPRECATED (v3.0+): 此模块为历史占位, 所有抽象方法返回 0 或 None,
|
|
5
|
+
无生产子类实现。
|
|
6
|
+
|
|
7
|
+
详见 [`docs/33-data-access-architecture.md`](../docs/33-data-access-architecture.md) 第 5 节 "Deprecated L2"。
|
|
8
|
+
|
|
9
|
+
替代方案:
|
|
10
|
+
- SQL 因子存储 → 使用 L1 `database_node/BaseDBNode`
|
|
11
|
+
- 因子元数据 / Wiki → 使用 L7 `research/wiki.py::WikiFactorProxy`
|
|
12
|
+
- Table 4 polars 数据 → 使用 L6 `research/quant_alpha/evaluation/contracts.py::DataLoader`
|
|
13
|
+
|
|
14
|
+
保留原因: 保持向后兼容 (factor_node/__init__.py re-export),
|
|
15
|
+
下个大版本 (v4.0) 将删除此模块。
|
|
16
|
+
|
|
17
|
+
包含 FactorDB(只读接口)和 WritableFactorDB(可写入接口)
|
|
18
|
+
v2.0: 移除 traits 依赖
|
|
19
|
+
"""
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
from typing import Any, Dict, List, Optional
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from QuantNodes.factor_node.quant_nodes_object import QuantNodesObject
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class FactorDB(QuantNodesObject):
|
|
29
|
+
"""因子库基类(只读接口)⚠️ DEPRECATED
|
|
30
|
+
|
|
31
|
+
数据库由若干张因子表组成。
|
|
32
|
+
不支持某个操作时,方法产生错误。
|
|
33
|
+
没有相关数据时,方法返回 None。
|
|
34
|
+
|
|
35
|
+
.. deprecated::
|
|
36
|
+
v3.0+. 所有方法返回 0/None, 无生产实现。
|
|
37
|
+
请使用 `database_node.BaseDBNode` (L1) 或
|
|
38
|
+
`research.wiki.WikiFactorProxy` (L7)。
|
|
39
|
+
"""
|
|
40
|
+
name: str = "FactorDB"
|
|
41
|
+
|
|
42
|
+
def connect(self) -> int:
|
|
43
|
+
"""连接到数据库
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
0 表示成功
|
|
47
|
+
"""
|
|
48
|
+
return 0
|
|
49
|
+
|
|
50
|
+
def disconnect(self) -> int:
|
|
51
|
+
"""断开数据库连接
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
0 表示成功
|
|
55
|
+
"""
|
|
56
|
+
return 0
|
|
57
|
+
|
|
58
|
+
def isAvailable(self) -> bool:
|
|
59
|
+
"""检查数据库是否可用
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
True 表示可用
|
|
63
|
+
"""
|
|
64
|
+
return True
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def TableNames(self) -> List[str]:
|
|
68
|
+
"""获取所有表名
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
表名列表
|
|
72
|
+
"""
|
|
73
|
+
return []
|
|
74
|
+
|
|
75
|
+
def getTable(
|
|
76
|
+
self, table_name: str, args: Optional[Dict[str, Any]] = None
|
|
77
|
+
) -> Optional["FactorTable"]: # noqa: F821
|
|
78
|
+
"""获取因子表对象
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
table_name: 表名
|
|
82
|
+
args: 额外参数
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
FactorTable 对象,不存在返回 None
|
|
86
|
+
"""
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
def getID(self) -> List[str]:
|
|
90
|
+
"""获取 ID 序列
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
ID 列表
|
|
94
|
+
"""
|
|
95
|
+
return []
|
|
96
|
+
|
|
97
|
+
def getDateTime(self) -> List[Any]:
|
|
98
|
+
"""获取时间点序列
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
时间点列表
|
|
102
|
+
"""
|
|
103
|
+
return []
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class WritableFactorDB(FactorDB):
|
|
107
|
+
"""可写入的因子数据库"""
|
|
108
|
+
|
|
109
|
+
def renameTable(self, old_table_name: str, new_table_name: str) -> int:
|
|
110
|
+
"""重命名表
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
old_table_name: 旧表名
|
|
114
|
+
new_table_name: 新表名
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
0 表示成功
|
|
118
|
+
"""
|
|
119
|
+
return 0
|
|
120
|
+
|
|
121
|
+
def deleteTable(self, table_name: str) -> int:
|
|
122
|
+
"""删除表
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
table_name: 表名
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
0 表示成功
|
|
129
|
+
"""
|
|
130
|
+
return 0
|
|
131
|
+
|
|
132
|
+
def setTableMetaData(
|
|
133
|
+
self,
|
|
134
|
+
table_name: str,
|
|
135
|
+
key: Optional[str] = None,
|
|
136
|
+
value: Optional[Any] = None,
|
|
137
|
+
meta_data: Optional[Dict[str, Any]] = None,
|
|
138
|
+
) -> int:
|
|
139
|
+
"""设置表的元数据
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
table_name: 表名
|
|
143
|
+
key: 元数据键
|
|
144
|
+
value: 元数据值
|
|
145
|
+
meta_data: 元数据字典
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
0 表示成功
|
|
149
|
+
"""
|
|
150
|
+
return 0
|
|
151
|
+
|
|
152
|
+
def renameFactor(
|
|
153
|
+
self,
|
|
154
|
+
table_name: str,
|
|
155
|
+
old_factor_name: str,
|
|
156
|
+
new_factor_name: str,
|
|
157
|
+
) -> int:
|
|
158
|
+
"""重命名因子
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
table_name: 表名
|
|
162
|
+
old_factor_name: 旧因子名
|
|
163
|
+
new_factor_name: 新因子名
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
0 表示成功
|
|
167
|
+
"""
|
|
168
|
+
return 0
|
|
169
|
+
|
|
170
|
+
def deleteFactor(self, table_name: str, factor_names: List[str]) -> int:
|
|
171
|
+
"""删除因子
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
table_name: 表名
|
|
175
|
+
factor_names: 因子名列表
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
0 表示成功
|
|
179
|
+
"""
|
|
180
|
+
return 0
|
|
181
|
+
|
|
182
|
+
def setFactorMetaData(
|
|
183
|
+
self,
|
|
184
|
+
table_name: str,
|
|
185
|
+
ifactor_name: str,
|
|
186
|
+
key: Optional[str] = None,
|
|
187
|
+
value: Optional[Any] = None,
|
|
188
|
+
meta_data: Optional[Dict[str, Any]] = None,
|
|
189
|
+
) -> int:
|
|
190
|
+
"""设置因子的元数据
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
table_name: 表名
|
|
194
|
+
ifactor_name: 因子名称
|
|
195
|
+
key: 元数据键
|
|
196
|
+
value: 元数据值
|
|
197
|
+
meta_data: 元数据字典
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
0 表示成功
|
|
201
|
+
"""
|
|
202
|
+
return 0
|
|
203
|
+
|
|
204
|
+
def writeData(
|
|
205
|
+
self,
|
|
206
|
+
data: Any,
|
|
207
|
+
table_name: str,
|
|
208
|
+
if_exists: str = "update",
|
|
209
|
+
data_type: Optional[Dict[str, str]] = None,
|
|
210
|
+
**kwargs,
|
|
211
|
+
) -> int:
|
|
212
|
+
"""写入数据
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
data: 数据
|
|
216
|
+
table_name: 表名
|
|
217
|
+
if_exists: 如果存在 ("append", "update")
|
|
218
|
+
data_type: 数据类型字典 {因子名: 数据类型}
|
|
219
|
+
**kwargs: 其他参数
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
0 表示成功
|
|
223
|
+
"""
|
|
224
|
+
return 0
|
|
225
|
+
|
|
226
|
+
def offsetDateTime(
|
|
227
|
+
self,
|
|
228
|
+
lag: int,
|
|
229
|
+
table_name: str,
|
|
230
|
+
factor_names: List[str],
|
|
231
|
+
args: Optional[Dict[str, Any]] = None,
|
|
232
|
+
) -> int:
|
|
233
|
+
"""时间平移
|
|
234
|
+
|
|
235
|
+
沿着时间轴将所有数据纵向移动 lag 期
|
|
236
|
+
lag > 0 向前移动,lag < 0 向后移动
|
|
237
|
+
空出来的地方填 nan
|
|
238
|
+
|
|
239
|
+
Args:
|
|
240
|
+
lag: 平移期数
|
|
241
|
+
table_name: 表名
|
|
242
|
+
factor_names: 因子名列表
|
|
243
|
+
args: 额外参数
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
0 表示成功
|
|
247
|
+
"""
|
|
248
|
+
if lag == 0:
|
|
249
|
+
return 0
|
|
250
|
+
FT = self.getTable(table_name, args=args)
|
|
251
|
+
if FT is None:
|
|
252
|
+
return -1
|
|
253
|
+
Data = FT.readData(
|
|
254
|
+
factor_names=factor_names,
|
|
255
|
+
ids=self.getID(),
|
|
256
|
+
dts=self.getDateTime(),
|
|
257
|
+
args=args,
|
|
258
|
+
)
|
|
259
|
+
if lag > 0:
|
|
260
|
+
Data.iloc[:, lag:, :] = Data.iloc[:, :-lag, :].values
|
|
261
|
+
Data.iloc[:, :lag, :] = None
|
|
262
|
+
elif lag < 0:
|
|
263
|
+
Data.iloc[:, :lag, :] = Data.iloc[:, -lag:, :].values
|
|
264
|
+
Data.iloc[:, lag:, :] = None
|
|
265
|
+
DataType = FT.getFactorMetaData(
|
|
266
|
+
factor_names, key="DataType", args=args
|
|
267
|
+
).to_dict()
|
|
268
|
+
self.deleteFactor(table_name, factor_names)
|
|
269
|
+
self.writeData(Data, table_name, data_type=DataType)
|
|
270
|
+
return 0
|
|
271
|
+
|
|
272
|
+
def _read_transform_write(
|
|
273
|
+
self,
|
|
274
|
+
table_name: str,
|
|
275
|
+
factor_names: List[str],
|
|
276
|
+
ids: List[str],
|
|
277
|
+
dts: List[Any],
|
|
278
|
+
transform_fn,
|
|
279
|
+
args: Optional[Dict[str, Any]] = None,
|
|
280
|
+
if_exists: str = "update",
|
|
281
|
+
) -> int:
|
|
282
|
+
"""通用读取-变换-写入模式
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
table_name: 表名
|
|
286
|
+
factor_names: 因子名列表
|
|
287
|
+
ids: ID 列表
|
|
288
|
+
dts: 时间点列表
|
|
289
|
+
transform_fn: 变换函数,接收 (Data, FT) 返回变换后的 Data
|
|
290
|
+
args: 额外参数
|
|
291
|
+
if_exists: 写入模式
|
|
292
|
+
|
|
293
|
+
Returns:
|
|
294
|
+
0 表示成功, -1 表示表不存在
|
|
295
|
+
"""
|
|
296
|
+
FT = self.getTable(table_name, args=args)
|
|
297
|
+
if FT is None:
|
|
298
|
+
return -1
|
|
299
|
+
Data = FT.readData(
|
|
300
|
+
factor_names=factor_names, ids=ids, dts=dts, args=args
|
|
301
|
+
)
|
|
302
|
+
Data = transform_fn(Data, FT)
|
|
303
|
+
if Data is not None:
|
|
304
|
+
self.writeData(Data, table_name, if_exists=if_exists)
|
|
305
|
+
return 0
|
|
306
|
+
|
|
307
|
+
def changeData(
|
|
308
|
+
self,
|
|
309
|
+
table_name: str,
|
|
310
|
+
factor_names: List[str],
|
|
311
|
+
ids: List[str],
|
|
312
|
+
dts: List[Any],
|
|
313
|
+
args: Optional[Dict[str, Any]] = None,
|
|
314
|
+
) -> int:
|
|
315
|
+
"""数据变换
|
|
316
|
+
|
|
317
|
+
通过某种变换函数得到新的时间序列和ID序列
|
|
318
|
+
|
|
319
|
+
Args:
|
|
320
|
+
table_name: 表名
|
|
321
|
+
factor_names: 因子名列表
|
|
322
|
+
ids: ID 列表
|
|
323
|
+
dts: 时间点列表
|
|
324
|
+
args: 额外参数
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
0 表示成功
|
|
328
|
+
"""
|
|
329
|
+
def _transform(Data, FT):
|
|
330
|
+
DataType = FT.getFactorMetaData(
|
|
331
|
+
factor_names, key="DataType", args=args
|
|
332
|
+
).to_dict()
|
|
333
|
+
self.deleteFactor(table_name, factor_names)
|
|
334
|
+
self.writeData(Data, table_name, data_type=DataType)
|
|
335
|
+
return None # Already written
|
|
336
|
+
return self._read_transform_write(table_name, factor_names, ids, dts, _transform, args)
|
|
337
|
+
|
|
338
|
+
def fillNA(
|
|
339
|
+
self,
|
|
340
|
+
filled_value: Any,
|
|
341
|
+
table_name: str,
|
|
342
|
+
factor_names: List[str],
|
|
343
|
+
ids: List[str],
|
|
344
|
+
dts: List[Any],
|
|
345
|
+
args: Optional[Dict[str, Any]] = None,
|
|
346
|
+
) -> int:
|
|
347
|
+
"""填充缺失值
|
|
348
|
+
|
|
349
|
+
Args:
|
|
350
|
+
filled_value: 填充值
|
|
351
|
+
table_name: 表名
|
|
352
|
+
factor_names: 因子名列表
|
|
353
|
+
ids: ID 列表
|
|
354
|
+
dts: 时间点列表
|
|
355
|
+
args: 额外参数
|
|
356
|
+
|
|
357
|
+
Returns:
|
|
358
|
+
0 表示成功
|
|
359
|
+
"""
|
|
360
|
+
def _transform(Data, FT):
|
|
361
|
+
Data.fillna(filled_value, inplace=True)
|
|
362
|
+
return Data
|
|
363
|
+
return self._read_transform_write(
|
|
364
|
+
table_name, factor_names, ids, dts, _transform, args
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
def replaceData(
|
|
368
|
+
self,
|
|
369
|
+
old_value: Any,
|
|
370
|
+
new_value: Any,
|
|
371
|
+
table_name: str,
|
|
372
|
+
factor_names: List[str],
|
|
373
|
+
ids: List[str],
|
|
374
|
+
dts: List[Any],
|
|
375
|
+
args: Optional[Dict[str, Any]] = None,
|
|
376
|
+
) -> int:
|
|
377
|
+
"""替换数据
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
old_value: 旧值
|
|
381
|
+
new_value: 新值
|
|
382
|
+
table_name: 表名
|
|
383
|
+
factor_names: 因子名列表
|
|
384
|
+
ids: ID 列表
|
|
385
|
+
dts: 时间点列表
|
|
386
|
+
args: 额外参数
|
|
387
|
+
|
|
388
|
+
Returns:
|
|
389
|
+
0 表示成功
|
|
390
|
+
"""
|
|
391
|
+
def _transform(Data, FT):
|
|
392
|
+
return Data.where(Data != old_value, new_value)
|
|
393
|
+
return self._read_transform_write(
|
|
394
|
+
table_name, factor_names, ids, dts, _transform, args
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
def optimizeData(self, table_name: str, factor_names: List[str]) -> int:
|
|
398
|
+
"""优化数据
|
|
399
|
+
|
|
400
|
+
Args:
|
|
401
|
+
table_name: 表名
|
|
402
|
+
factor_names: 因子名列表
|
|
403
|
+
|
|
404
|
+
Returns:
|
|
405
|
+
0 表示成功
|
|
406
|
+
"""
|
|
407
|
+
return 0
|
|
408
|
+
|
|
409
|
+
def fixData(self, table_name: str, factor_names: List[str]) -> int:
|
|
410
|
+
"""修复数据
|
|
411
|
+
|
|
412
|
+
依赖具体实现,不保证一定修复
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
table_name: 表名
|
|
416
|
+
factor_names: 因子名列表
|
|
417
|
+
|
|
418
|
+
Returns:
|
|
419
|
+
0 表示成功
|
|
420
|
+
"""
|
|
421
|
+
return 0
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
factor_functions - 因子函数实现层
|
|
4
|
+
|
|
5
|
+
本模块包含所有算子的核心实现,按类别拆分为子模块:
|
|
6
|
+
- time_ops: 时间序列算子
|
|
7
|
+
- section_ops: 截面算子
|
|
8
|
+
- math_ops: 数学算子
|
|
9
|
+
- composite_ops: 组合算子
|
|
10
|
+
- talib_ops: TA-Lib 技术指标
|
|
11
|
+
|
|
12
|
+
注册表 API:
|
|
13
|
+
- list_operators()
|
|
14
|
+
- get_operator()
|
|
15
|
+
- operator_info()
|
|
16
|
+
- generate_documentation()
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
22
|
+
|
|
23
|
+
# 导入辅助函数和注册表
|
|
24
|
+
from QuantNodes.factor_node.factor_functions._helpers import (
|
|
25
|
+
_OPERATOR_REGISTRY,
|
|
26
|
+
OperatorCategory,
|
|
27
|
+
register_operator,
|
|
28
|
+
_ensure_expr,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# 导入子模块(触发算子注册)
|
|
32
|
+
from QuantNodes.factor_node.factor_functions import time_ops
|
|
33
|
+
from QuantNodes.factor_node.factor_functions import section_ops
|
|
34
|
+
from QuantNodes.factor_node.factor_functions import math_ops
|
|
35
|
+
from QuantNodes.factor_node.factor_functions import composite_ops
|
|
36
|
+
|
|
37
|
+
# 导入常用函数供直接使用
|
|
38
|
+
from QuantNodes.factor_node.factor_functions.math_ops import (
|
|
39
|
+
ceil, floor, fix, applymap,
|
|
40
|
+
nanargmax, nanargmin, nanmedian, nanquantile, nancount, nanprod,
|
|
41
|
+
astype, replace, fetch,
|
|
42
|
+
abs as ff_abs, log as ff_log, sign, sqrt as ff_sqrt, square, clip,
|
|
43
|
+
isnull, notnull, fill_null, fill_zero, nan_to_null,
|
|
44
|
+
pow as ff_pow,
|
|
45
|
+
nanmax, nanmin, nanmean, nansum, nanstd, nanvar,
|
|
46
|
+
where, fillna,
|
|
47
|
+
add, sub, mul, div,
|
|
48
|
+
log1p, if_then_else, market_cap,
|
|
49
|
+
weighted_sum, combine,
|
|
50
|
+
book_to_market, earnings_to_market,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
from QuantNodes.factor_node.factor_functions.time_ops import (
|
|
54
|
+
rolling_mean, rolling_std, rolling_max, rolling_min, rolling_sum,
|
|
55
|
+
rolling_median, rolling_var,
|
|
56
|
+
rolling_prod, rolling_skew, rolling_kurt, rolling_count,
|
|
57
|
+
rolling_argmax, rolling_argmin,
|
|
58
|
+
rolling_corr, rolling_cov, rolling_quantile, rolling_rank,
|
|
59
|
+
ewm_var, ewm_mean, ewm_std, ewm_corr, ewm_cov,
|
|
60
|
+
expanding_mean, expanding_std, expanding_sum,
|
|
61
|
+
expanding_max, expanding_min, expanding_median, expanding_count,
|
|
62
|
+
expanding_var, expanding_kurt, expanding_skew, expanding_quantile,
|
|
63
|
+
expanding_corr, expanding_cov,
|
|
64
|
+
ts_mean, ts_std, ts_corr, ts_cov, ts_rank, ts_delta, ts_lag,
|
|
65
|
+
ts_argmax, ts_argmin, ts_lead, ts_pct_change,
|
|
66
|
+
decay_linear, decay_exp, vwap, rolling_change_rate,
|
|
67
|
+
regress, zscored, ts_shift, diff, lag, delay, ref, shift,
|
|
68
|
+
delta, pct_change,
|
|
69
|
+
correlation, covariance,
|
|
70
|
+
ts_prod,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
from QuantNodes.factor_node.factor_functions.section_ops import (
|
|
74
|
+
rank, zscore, winsorize, neutralize, neutralize_market, scale,
|
|
75
|
+
ic, rank_ic, group_norm, group_winsorize,
|
|
76
|
+
standardizeZScore, orthogonalize, mad,
|
|
77
|
+
fillNaNByFun, fillNaNByRegress,
|
|
78
|
+
cross_sectional_rank, cross_sectional_zscore,
|
|
79
|
+
cross_sectional_mean, cross_sectional_std, cross_sectional_sum,
|
|
80
|
+
standardizeRank, weightStandardize,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
from QuantNodes.factor_node.factor_functions.composite_ops import (
|
|
84
|
+
aggregate, disaggregate,
|
|
85
|
+
aggr_sum, aggr_mean, aggr_max, aggr_min, aggr_std, aggr_var,
|
|
86
|
+
aggr_median, aggr_count, aggr_prod, aggr_quantile,
|
|
87
|
+
merge, chg_ids, blend, nav, rebase,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# 为测试兼容性导出 (shadow builtins)
|
|
91
|
+
abs = ff_abs
|
|
92
|
+
log = ff_log
|
|
93
|
+
pow = ff_pow
|
|
94
|
+
sqrt = ff_sqrt
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ==============================================================================
|
|
98
|
+
# 注册表查询 API
|
|
99
|
+
# ==============================================================================
|
|
100
|
+
|
|
101
|
+
def list_operators(category: Optional[str] = None, include_custom: bool = True) -> List[str]:
|
|
102
|
+
"""列出所有算子名称
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
category: 可选,限定分类
|
|
106
|
+
include_custom: 是否包含自定义算子(默认 True)
|
|
107
|
+
"""
|
|
108
|
+
if include_custom:
|
|
109
|
+
from QuantNodes.operators.registry import _CustomOperatorRegistry
|
|
110
|
+
|
|
111
|
+
custom = _CustomOperatorRegistry.list(category)
|
|
112
|
+
builtin = list(_OPERATOR_REGISTRY.get(category, {}).keys()) if category else [
|
|
113
|
+
name for cat in _OPERATOR_REGISTRY for name in _OPERATOR_REGISTRY[cat]
|
|
114
|
+
]
|
|
115
|
+
seen = set()
|
|
116
|
+
result = []
|
|
117
|
+
for name in custom + builtin:
|
|
118
|
+
if name not in seen:
|
|
119
|
+
seen.add(name)
|
|
120
|
+
result.append(name)
|
|
121
|
+
return result
|
|
122
|
+
|
|
123
|
+
if category:
|
|
124
|
+
return list(_OPERATOR_REGISTRY.get(category, {}).keys())
|
|
125
|
+
return [name for cat in _OPERATOR_REGISTRY for name in _OPERATOR_REGISTRY[cat]]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def get_operator(name: str, category: Optional[str] = None) -> Optional[Callable]:
|
|
129
|
+
"""根据名称获取算子函数(级联查询:先自定义注册表,再内置注册表)"""
|
|
130
|
+
from QuantNodes.operators.registry import _CustomOperatorRegistry
|
|
131
|
+
|
|
132
|
+
func = _CustomOperatorRegistry.get(name, category)
|
|
133
|
+
if func is not None:
|
|
134
|
+
return func
|
|
135
|
+
|
|
136
|
+
if category:
|
|
137
|
+
op = _OPERATOR_REGISTRY.get(category, {}).get(name)
|
|
138
|
+
return op["func"] if op else None
|
|
139
|
+
|
|
140
|
+
for cat in _OPERATOR_REGISTRY:
|
|
141
|
+
if name in _OPERATOR_REGISTRY[cat]:
|
|
142
|
+
return _OPERATOR_REGISTRY[cat][name]["func"]
|
|
143
|
+
return None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def operator_info(name: str, category: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
|
147
|
+
"""获取算子详细信息(级联查询:先自定义注册表,再内置注册表)"""
|
|
148
|
+
from QuantNodes.operators.registry import _CustomOperatorRegistry
|
|
149
|
+
|
|
150
|
+
info = _CustomOperatorRegistry.info(name)
|
|
151
|
+
if info is not None:
|
|
152
|
+
return info
|
|
153
|
+
|
|
154
|
+
if category:
|
|
155
|
+
op = _OPERATOR_REGISTRY.get(category, {}).get(name)
|
|
156
|
+
return op if op else None
|
|
157
|
+
|
|
158
|
+
for cat in _OPERATOR_REGISTRY:
|
|
159
|
+
if name in _OPERATOR_REGISTRY[cat]:
|
|
160
|
+
return _OPERATOR_REGISTRY[cat][name]
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def generate_documentation(output_format: str = "markdown", category: Optional[str] = None) -> str:
|
|
165
|
+
"""生成算子文档"""
|
|
166
|
+
if category:
|
|
167
|
+
ops = {category: _OPERATOR_REGISTRY.get(category, {})}
|
|
168
|
+
else:
|
|
169
|
+
ops = _OPERATOR_REGISTRY
|
|
170
|
+
|
|
171
|
+
if output_format == "json":
|
|
172
|
+
import json
|
|
173
|
+
serializable = {}
|
|
174
|
+
for cat, cat_ops in ops.items():
|
|
175
|
+
serializable[cat] = {}
|
|
176
|
+
for name, info in cat_ops.items():
|
|
177
|
+
serializable[cat][name] = {k: v for k, v in info.items() if k != "func"}
|
|
178
|
+
return json.dumps(serializable, indent=2, ensure_ascii=False)
|
|
179
|
+
|
|
180
|
+
lines = []
|
|
181
|
+
for cat, cat_ops in ops.items():
|
|
182
|
+
if not cat_ops:
|
|
183
|
+
continue
|
|
184
|
+
lines.append(f"\n## {cat.upper()}")
|
|
185
|
+
lines.append(f"共 {len(cat_ops)} 个算子\n")
|
|
186
|
+
for name, info in sorted(cat_ops.items()):
|
|
187
|
+
lines.append(f"### {name}")
|
|
188
|
+
if info.get("doc"):
|
|
189
|
+
lines.append(f"{info['doc']}")
|
|
190
|
+
lines.append(f"- 参数: {info.get('parameters', [])}")
|
|
191
|
+
lines.append(f"- 签名: {info.get('signature', '')}")
|
|
192
|
+
lines.append("")
|
|
193
|
+
|
|
194
|
+
return "\n".join(lines)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
__all__ = [
|
|
198
|
+
"list_operators",
|
|
199
|
+
"get_operator",
|
|
200
|
+
"operator_info",
|
|
201
|
+
"generate_documentation",
|
|
202
|
+
"register_operator",
|
|
203
|
+
"OperatorCategory",
|
|
204
|
+
"_OPERATOR_REGISTRY",
|
|
205
|
+
"_ensure_expr",
|
|
206
|
+
# math_ops
|
|
207
|
+
"ceil", "floor", "fix", "applymap",
|
|
208
|
+
"nanargmax", "nanargmin", "nanmedian", "nanquantile", "nancount", "nanprod",
|
|
209
|
+
"astype", "replace", "fetch",
|
|
210
|
+
"ff_abs", "ff_log", "sign", "ff_sqrt", "square", "clip",
|
|
211
|
+
"isnull", "notnull", "fill_null", "fill_zero", "nan_to_null",
|
|
212
|
+
"ff_pow",
|
|
213
|
+
"nanmax", "nanmin", "nanmean", "nansum", "nanstd", "nanvar",
|
|
214
|
+
"where", "fillna",
|
|
215
|
+
"add", "sub", "mul", "div",
|
|
216
|
+
"log1p", "if_then_else", "market_cap",
|
|
217
|
+
"weighted_sum", "combine", "book_to_market", "earnings_to_market",
|
|
218
|
+
# time_ops
|
|
219
|
+
"rolling_mean", "rolling_std", "rolling_max", "rolling_min", "rolling_sum",
|
|
220
|
+
"rolling_median", "rolling_var",
|
|
221
|
+
"rolling_prod", "rolling_skew", "rolling_kurt", "rolling_count",
|
|
222
|
+
"rolling_argmax", "rolling_argmin",
|
|
223
|
+
"rolling_corr", "rolling_cov", "rolling_quantile", "rolling_rank",
|
|
224
|
+
"ewm_var", "ewm_mean", "ewm_std", "ewm_corr", "ewm_cov",
|
|
225
|
+
"expanding_mean", "expanding_std", "expanding_sum",
|
|
226
|
+
"expanding_max", "expanding_min", "expanding_median", "expanding_count",
|
|
227
|
+
"expanding_var", "expanding_kurt", "expanding_skew", "expanding_quantile",
|
|
228
|
+
"expanding_corr", "expanding_cov",
|
|
229
|
+
"ts_mean", "ts_std", "ts_corr", "ts_cov", "ts_rank", "ts_delta", "ts_lag",
|
|
230
|
+
"ts_argmax", "ts_argmin", "ts_lead", "ts_pct_change",
|
|
231
|
+
"decay_linear", "decay_exp", "vwap", "rolling_change_rate",
|
|
232
|
+
"regress", "zscored", "ts_shift", "diff", "lag", "delay", "ref", "shift",
|
|
233
|
+
"delta", "pct_change", "correlation", "covariance", "ts_prod",
|
|
234
|
+
# section_ops
|
|
235
|
+
"rank", "zscore", "winsorize", "neutralize", "neutralize_market", "scale",
|
|
236
|
+
"ic", "rank_ic", "group_norm", "group_winsorize",
|
|
237
|
+
"standardizeZScore", "orthogonalize", "mad",
|
|
238
|
+
"fillNaNByFun", "fillNaNByRegress",
|
|
239
|
+
"cross_sectional_rank", "cross_sectional_zscore",
|
|
240
|
+
"cross_sectional_mean", "cross_sectional_std", "cross_sectional_sum",
|
|
241
|
+
"standardizeRank", "weightStandardize",
|
|
242
|
+
# composite_ops
|
|
243
|
+
"aggregate", "disaggregate",
|
|
244
|
+
"aggr_sum", "aggr_mean", "aggr_max", "aggr_min", "aggr_std", "aggr_var",
|
|
245
|
+
"aggr_median", "aggr_count", "aggr_prod", "aggr_quantile",
|
|
246
|
+
"merge", "chg_ids", "blend", "nav", "rebase",
|
|
247
|
+
# submodules for side-effect registration
|
|
248
|
+
"time_ops",
|
|
249
|
+
"section_ops",
|
|
250
|
+
"math_ops",
|
|
251
|
+
"composite_ops",
|
|
252
|
+
]
|