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,290 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
截面算子
|
|
4
|
+
|
|
5
|
+
本模块包含所有截面(cross-sectional)相关的因子运算算子。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Optional, Union
|
|
11
|
+
|
|
12
|
+
import polars as pl
|
|
13
|
+
from polars import Expr
|
|
14
|
+
|
|
15
|
+
from QuantNodes.factor_node.factor_functions._helpers import (
|
|
16
|
+
OperatorCategory,
|
|
17
|
+
register_operator,
|
|
18
|
+
_ensure_expr,
|
|
19
|
+
_make_alias,
|
|
20
|
+
_make_nan_wrapper,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# ==============================================================================
|
|
25
|
+
# 截面算子
|
|
26
|
+
# ==============================================================================
|
|
27
|
+
|
|
28
|
+
@register_operator(OperatorCategory.SECTION)
|
|
29
|
+
def standardizeZScore(f: Union[Expr, str], eps: float = 1e-8, **kwargs) -> Expr:
|
|
30
|
+
"""Z-score 标准化"""
|
|
31
|
+
e = _ensure_expr(f)
|
|
32
|
+
mean = e.mean()
|
|
33
|
+
std = e.std()
|
|
34
|
+
return (e - mean) / (std + eps)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
_make_alias("zscore", standardizeZScore, "Z-score 标准化 (standardizeZScore 别名)",
|
|
38
|
+
category=OperatorCategory.SECTION)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@register_operator(OperatorCategory.SECTION)
|
|
42
|
+
def rank(f: Union[Expr, str], method: str = "dense", **kwargs) -> Expr:
|
|
43
|
+
"""截面排名 (归一化到 0-1)"""
|
|
44
|
+
e = _ensure_expr(f)
|
|
45
|
+
if method == "dense":
|
|
46
|
+
return (e.rank() - 1) / (e.count() - 1)
|
|
47
|
+
elif method == "ordinal":
|
|
48
|
+
return e.rank()
|
|
49
|
+
elif method == "min":
|
|
50
|
+
r = e.rank()
|
|
51
|
+
return (r - r.min()) / (r.max() - r.min())
|
|
52
|
+
elif method == "average":
|
|
53
|
+
return (e.rank() - 1) / (e.count() - 1)
|
|
54
|
+
else:
|
|
55
|
+
return e.rank() / e.count()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@register_operator(OperatorCategory.SECTION)
|
|
59
|
+
def winsorize(f: Union[Expr, str], lower: float = 0.01,
|
|
60
|
+
upper: float = 0.01, method: str = "quantile", **kwargs) -> Expr:
|
|
61
|
+
"""去极值"""
|
|
62
|
+
e = _ensure_expr(f)
|
|
63
|
+
if method == "quantile":
|
|
64
|
+
lower_bound = e.quantile(lower)
|
|
65
|
+
upper_bound = e.quantile(1 - upper)
|
|
66
|
+
else:
|
|
67
|
+
mean = e.mean()
|
|
68
|
+
std = e.std()
|
|
69
|
+
lower_bound = mean - lower * std
|
|
70
|
+
upper_bound = mean + upper * std
|
|
71
|
+
return e.clip(lower_bound, upper_bound)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@register_operator(OperatorCategory.SECTION)
|
|
75
|
+
def neutralize(f: Union[Expr, str],
|
|
76
|
+
group: Optional[Union[Expr, str]] = None, **kwargs) -> Expr:
|
|
77
|
+
"""行业中性的 (减去行业均值)"""
|
|
78
|
+
e = _ensure_expr(f)
|
|
79
|
+
if group is not None:
|
|
80
|
+
g = _ensure_expr(group)
|
|
81
|
+
group_mean = e.mean().over(g)
|
|
82
|
+
return e - group_mean
|
|
83
|
+
return e - e.mean()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@register_operator(OperatorCategory.SECTION)
|
|
87
|
+
def neutralize_market(f: Union[Expr, str], **kwargs) -> Expr:
|
|
88
|
+
"""市场中性 (减去市场均值)"""
|
|
89
|
+
e = _ensure_expr(f)
|
|
90
|
+
return e - e.mean()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@register_operator(OperatorCategory.SECTION)
|
|
94
|
+
def scale(f: Union[Expr, str], method: str = "zscore", **kwargs) -> Expr:
|
|
95
|
+
"""归一化"""
|
|
96
|
+
e = _ensure_expr(f)
|
|
97
|
+
col_name = f if isinstance(f, str) else None
|
|
98
|
+
|
|
99
|
+
if method == "zscore":
|
|
100
|
+
result = standardizeZScore(e)
|
|
101
|
+
else:
|
|
102
|
+
e_min = e.min()
|
|
103
|
+
e_max = e.max()
|
|
104
|
+
diff = e_max - e_min
|
|
105
|
+
result = pl.when(diff == 0).then(pl.lit(0.0)).otherwise((e - e_min) / diff)
|
|
106
|
+
|
|
107
|
+
if col_name:
|
|
108
|
+
return result.alias(col_name)
|
|
109
|
+
return result
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@register_operator(OperatorCategory.SECTION)
|
|
113
|
+
def ic(f: Union[Expr, str], target: Union[Expr, str], **kwargs) -> Expr:
|
|
114
|
+
"""IC (Pearson 相关系数)"""
|
|
115
|
+
e = _ensure_expr(f)
|
|
116
|
+
t = _ensure_expr(target)
|
|
117
|
+
e_mean = e.mean()
|
|
118
|
+
t_mean = t.mean()
|
|
119
|
+
e_centered = e - e_mean
|
|
120
|
+
t_centered = t - t_mean
|
|
121
|
+
cov = (e_centered * t_centered).mean()
|
|
122
|
+
e_std = e_centered.std(ddof=0)
|
|
123
|
+
t_std = t_centered.std(ddof=0)
|
|
124
|
+
return cov / (e_std * t_std + 1e-8)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@register_operator(OperatorCategory.SECTION)
|
|
128
|
+
def rank_ic(f: Union[Expr, str], target: Union[Expr, str], **kwargs) -> Expr:
|
|
129
|
+
"""Rank IC (Spearman 相关系数)"""
|
|
130
|
+
e = _ensure_expr(f)
|
|
131
|
+
t = _ensure_expr(target)
|
|
132
|
+
e_rank = e.rank()
|
|
133
|
+
t_rank = t.rank()
|
|
134
|
+
e_mean = e_rank.mean()
|
|
135
|
+
t_mean = t_rank.mean()
|
|
136
|
+
e_centered = e_rank - e_mean
|
|
137
|
+
t_centered = t_rank - t_mean
|
|
138
|
+
cov = (e_centered * t_centered).mean()
|
|
139
|
+
e_std = e_centered.std(ddof=0)
|
|
140
|
+
t_std = t_centered.std(ddof=0)
|
|
141
|
+
return cov / (e_std * t_std + 1e-8)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@register_operator(OperatorCategory.SECTION)
|
|
145
|
+
def group_norm(f: Union[Expr, str], group: Union[Expr, str],
|
|
146
|
+
method: str = "zscore", **kwargs) -> Expr:
|
|
147
|
+
"""分组标准化"""
|
|
148
|
+
e = _ensure_expr(f)
|
|
149
|
+
g = _ensure_expr(group)
|
|
150
|
+
if method == "zscore":
|
|
151
|
+
group_mean = e.mean().over(g)
|
|
152
|
+
group_std = e.std().over(g)
|
|
153
|
+
return (e - group_mean) / (group_std + 1e-8)
|
|
154
|
+
else:
|
|
155
|
+
group_min = e.min().over(g)
|
|
156
|
+
group_max = e.max().over(g)
|
|
157
|
+
return (e - group_min) / (group_max - group_min + 1e-8)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@register_operator(OperatorCategory.SECTION)
|
|
161
|
+
def group_winsorize(f: Union[Expr, str], group: Union[Expr, str],
|
|
162
|
+
lower: float = 0.01, upper: float = 0.01, **kwargs) -> Expr:
|
|
163
|
+
"""分组去极值"""
|
|
164
|
+
e = _ensure_expr(f)
|
|
165
|
+
g = _ensure_expr(group)
|
|
166
|
+
lower_bound = e.quantile(lower).over(g)
|
|
167
|
+
upper_bound = e.quantile(1 - upper).over(g)
|
|
168
|
+
return e.clip(lower_bound, upper_bound)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@register_operator(OperatorCategory.SECTION)
|
|
172
|
+
def orthogonalize(f: Union[Expr, str], reference: Union[Expr, str], **kwargs) -> Expr:
|
|
173
|
+
"""正交化:从因子 f 中剔除 reference 的影响"""
|
|
174
|
+
f = _ensure_expr(f)
|
|
175
|
+
reference = _ensure_expr(reference)
|
|
176
|
+
cov = (f * reference).mean() - f.mean() * reference.mean()
|
|
177
|
+
var_ref = (reference ** 2).mean() - reference.mean() ** 2
|
|
178
|
+
beta = cov / (var_ref + 1e-10)
|
|
179
|
+
return f - beta * reference
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@register_operator(OperatorCategory.SECTION)
|
|
183
|
+
def fillNaNByFun(f: Union[Expr, str], value: Any = 0, **kwargs) -> Expr:
|
|
184
|
+
"""NaN 填充"""
|
|
185
|
+
return _ensure_expr(f).fill_nan(value)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@register_operator(OperatorCategory.SECTION)
|
|
189
|
+
def fillNaNByRegress(f: Union[Expr, str], reference: Union[Expr, str], **kwargs) -> Expr:
|
|
190
|
+
"""NaN 填充:用 reference 回归拟合"""
|
|
191
|
+
f = _ensure_expr(f)
|
|
192
|
+
ref = _ensure_expr(reference)
|
|
193
|
+
mask = f.is_not_null()
|
|
194
|
+
f_clean = f.filter(mask)
|
|
195
|
+
ref_clean = ref.filter(mask)
|
|
196
|
+
beta = (f_clean * ref_clean).mean() / (ref_clean ** 2).mean()
|
|
197
|
+
return pl.when(mask).then(f).otherwise(beta * ref)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
_make_nan_wrapper("nanmax", "max", "截面最大值(忽略 NaN)")
|
|
201
|
+
_make_nan_wrapper("nanmin", "min", "截面最小值(忽略 NaN)")
|
|
202
|
+
_make_nan_wrapper("nanmean", "mean", "截面均值(忽略 NaN)")
|
|
203
|
+
_make_nan_wrapper("nansum", "sum", "截面求和(忽略 NaN)")
|
|
204
|
+
_make_nan_wrapper("nanstd", "std", "截面标准差(忽略 NaN)")
|
|
205
|
+
_make_nan_wrapper("nanvar", "var", "截面方差(忽略 NaN)")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@register_operator(OperatorCategory.SECTION)
|
|
209
|
+
def mad(f: Union[Expr, str], **kwargs) -> Expr:
|
|
210
|
+
"""Median Absolute Deviation (中位绝对偏差)"""
|
|
211
|
+
f = _ensure_expr(f)
|
|
212
|
+
median = f.median()
|
|
213
|
+
return (f - median).abs().median() * 1.4826
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@register_operator(OperatorCategory.SECTION)
|
|
217
|
+
def cross_sectional_rank(f: Union[Expr, str], **kwargs) -> Expr:
|
|
218
|
+
"""截面排名"""
|
|
219
|
+
return rank(f, **kwargs)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@register_operator(OperatorCategory.SECTION)
|
|
223
|
+
def cross_sectional_zscore(f: Union[Expr, str], **kwargs) -> Expr:
|
|
224
|
+
"""截面 Z-score"""
|
|
225
|
+
return standardizeZScore(f, **kwargs)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@register_operator(OperatorCategory.SECTION)
|
|
229
|
+
def cross_sectional_mean(f: Union[Expr, str], **kwargs) -> Expr:
|
|
230
|
+
"""截面均值"""
|
|
231
|
+
return _ensure_expr(f).mean()
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
@register_operator(OperatorCategory.SECTION)
|
|
235
|
+
def cross_sectional_std(f: Union[Expr, str], **kwargs) -> Expr:
|
|
236
|
+
"""截面标准差"""
|
|
237
|
+
return _ensure_expr(f).std()
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@register_operator(OperatorCategory.SECTION)
|
|
241
|
+
def cross_sectional_sum(f: Union[Expr, str], **kwargs) -> Expr:
|
|
242
|
+
"""截面求和"""
|
|
243
|
+
return _ensure_expr(f).sum()
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
@register_operator(OperatorCategory.SECTION)
|
|
247
|
+
def standardizeRank(f: Union[Expr, str], **kwargs) -> Expr:
|
|
248
|
+
"""排名标准化 (0-1 归一化)"""
|
|
249
|
+
return rank(f, method="dense", **kwargs)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@register_operator(OperatorCategory.SECTION)
|
|
253
|
+
def weightStandardize(f: Union[Expr, str], weight: Union[Expr, str] = None,
|
|
254
|
+
**kwargs) -> Expr:
|
|
255
|
+
"""加权标准化"""
|
|
256
|
+
e = _ensure_expr(f)
|
|
257
|
+
if weight is not None:
|
|
258
|
+
w = _ensure_expr(weight)
|
|
259
|
+
w_sum = w.sum()
|
|
260
|
+
w_norm = w / w_sum
|
|
261
|
+
weighted_mean = (e * w_norm).sum()
|
|
262
|
+
weighted_std = (((e - weighted_mean) ** 2) * w_norm).sum().sqrt()
|
|
263
|
+
return (e - weighted_mean) / (weighted_std + 1e-8)
|
|
264
|
+
else:
|
|
265
|
+
return standardizeZScore(e)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
# ==============================================================================
|
|
269
|
+
# QuantAlpha M1 新增别名(Alpha 101 IndNeutralize 命名约定)
|
|
270
|
+
# ==============================================================================
|
|
271
|
+
# IndNeutralize 是 Alpha 101 的命名约定。
|
|
272
|
+
# 直接用 polars 的 over() 实现,避免与 composite_dag_ops 的循环导入。
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@register_operator(OperatorCategory.SECTION, "IndNeutralize")
|
|
276
|
+
def IndNeutralize(
|
|
277
|
+
f: Union[Expr, str],
|
|
278
|
+
ind_class: str = "citic_1",
|
|
279
|
+
**kwargs,
|
|
280
|
+
) -> Expr:
|
|
281
|
+
"""行业中性化(Alpha 101 命名约定)
|
|
282
|
+
|
|
283
|
+
IndNeutralize(x, ind_class) = x - mean(x) grouped by ind_class
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
f: 输入表达式
|
|
287
|
+
ind_class: 行业分类列名(默认 'citic_1' 一级行业)
|
|
288
|
+
"""
|
|
289
|
+
e = _ensure_expr(f)
|
|
290
|
+
return e - e.mean().over(ind_class)
|