backtrader.errors module¶
Framework and research exceptions share this module. Research failures derive
from ResearchError and BacktraderError. ResearchConfigError keeps
structured research diagnostics and ValueError compatibility; the framework
ConfigError remains a separate category.
Exception Classes Module - Custom exceptions for backtrader.
This module defines the exception hierarchy used throughout the backtrader framework.
- Classes:
BacktraderError: Base exception for all backtrader exceptions. StrategySkipError: Raised to skip a strategy during optimization. ModuleImportError: Raised when a required module cannot be imported. FromModuleImportError: Raised when a from-style import fails. DataError: Raised for data-feed/parsing problems. BrokerError: Raised for broker/execution problems. OrderError: Raised for order-related problems (subclass of BrokerError). ConfigError: Raised for invalid configuration/parameters. ResearchError: Base class for typed native-research failures. ResearchConfigError: Raised for invalid research configuration. DatasetError: Raised for invalid or unsupported research input data. DependencyError: Raised when a research dependency is unavailable. DataQualityError: Raised when a research quality bound is exceeded. FactorComputationError: Raised for unexpected native factor failures. FactorComputationContext: Attributes strict failures to their factor context.
示例
Raising StrategySkipError during optimization: >>> class MyStrategy(bt.Strategy): ... params = (('period', 20),) ... ... def __init__(self): ... if self.p.period < 5: ... raise bt.errors.StrategySkipError()
- exception backtrader.errors.BacktraderError[源代码]¶
基类:
ExceptionBase exception for all backtrader exceptions.
- exception backtrader.errors.StrategySkipError[源代码]¶
-
Requests the platform to skip this strategy for backtesting. To be raised during the initialization (
__init__) phase of the instance
- exception backtrader.errors.DataError[源代码]¶
-
Raised for data-feed problems: loading, parsing, or alignment failures.
- exception backtrader.errors.BrokerError[源代码]¶
-
Raised for broker/execution problems: cash, margin, or matching failures.
- exception backtrader.errors.OrderError[源代码]¶
基类:
BrokerErrorRaised for order-related problems: invalid size/price or rejected orders.
- exception backtrader.errors.ResearchError[源代码]¶
-
Base class for stable, machine-readable research failures.
- default_code = 'RESEARCH_ERROR'¶
- exception backtrader.errors.ResearchConfigError[源代码]¶
-
Invalid or unsupported research configuration.
- default_code = 'INVALID_CONFIG'¶
- exception backtrader.errors.DatasetError[源代码]¶
-
Invalid, incomplete, or unsupported research input data.
- default_code = 'INVALID_DATASET'¶
- exception backtrader.errors.DependencyError[源代码]¶
-
A required runtime or public dependency is unavailable.
- default_code = 'DEPENDENCY_UNAVAILABLE'¶
- exception backtrader.errors.DataQualityError[源代码]¶
-
A requested quality bound is exceeded by the collected dataset.
- default_code = 'LOSS_LIMIT_EXCEEDED'¶
- exception backtrader.errors.FactorComputationError[源代码]¶
基类:
ResearchError,RuntimeErrorAn unexpected native factor or line calculation failure.
__cause__is kept by normal Python exception chaining. Callers should raise the result ofFactorComputationContext.wrap()withfromthe original exception so its type and traceback remain available.- default_code = 'FACTOR_COMPUTATION_FAILED'¶
- class backtrader.errors.FactorComputationContext[源代码]¶
基类:
objectDuck-typed strict policy context propagated through one native factor.
The core only needs the public
phase,asset_forandwrapprotocol. Feed and output-line references are retained by identity so an error is attributed only when one asset can be identified unambiguously.- factor¶
- phase¶
- failed¶
- error¶
- asset_for(operation=None)[源代码]¶
Resolve an asset from an operation or its direct data operands.
Cross-sectional operations touching multiple assets intentionally return
None; callers must not guess one member of the panel.
- wrap(exc, *, phase=None, asset=None)[源代码]¶
Build a safe structured error; preserve
excviaraise from.- 参数:
exc (BaseException)
phase (str | None)
asset (str | None)
- 返回类型: