turtle_quant_1.strategies.base¶
turtle_quant_1.strategies.base
¶
Base classes for trading strategies.
BaseStrategy
¶
Bases: ABC
Base class for trading strategies.
Initialize the strategy.
Source code in src/turtle_quant_1/strategies/base.py
generate_historical_scores
abstractmethod
¶
Generate a historical score array for a symbol based on market data.
NOTE: Assume that the data is sorted by datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data containing columns: ['datetime', 'Open', 'High', 'Low', 'Close', 'Volume'] |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Score array with each value between -1.0 (strong sell) and +1.0 (strong buy), |
Series
|
indexed by the original data's index. 0.0 represents hold/neutral. |
Source code in src/turtle_quant_1/strategies/base.py
generate_prediction_score
abstractmethod
¶
Generate the latest score for prediction for a symbol based on market data.
NOTE: Assume that the data is sorted by datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data containing columns: ['datetime', 'Open', 'High', 'Low', 'Close', 'Volume'] |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Score between -1.0 (strong sell) and +1.0 (strong buy). |
float
|
0.0 represents hold/neutral. |
Source code in src/turtle_quant_1/strategies/base.py
validate_data
¶
Validate that the input data has the required format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data format is invalid. |
Source code in src/turtle_quant_1/strategies/base.py
BaseStrategyEngine
¶
BaseStrategyEngine(
strategies: List[BaseStrategy],
weights: Dict[str, float] = {},
buy_unit_threshold: float = 0.3,
sell_threshold: float = -0.3,
)
Bases: ABC
Base class for strategy engines that aggregate multiple strategies.
Initialize the strategy engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategies
|
List[BaseStrategy]
|
List of strategies to aggregate. |
required |
weights
|
Dict[str, float]
|
Optional dict mapping strategy class names to weights. If empty, equal weights are used for all strategies. |
{}
|
Source code in src/turtle_quant_1/strategies/base.py
aggregate_scores
abstractmethod
¶
Aggregate scores from all strategies using weighted average.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Aggregated score between -1.0 and +1.0. |
Source code in src/turtle_quant_1/strategies/base.py
generate_signal
abstractmethod
¶
generate_signal(data: DataFrame, symbol: str) -> Signal
Generate a trading signal by aggregating all strategies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
Signal
|
Signal object containing action, score, and contributing strategies. |
Source code in src/turtle_quant_1/strategies/base.py
get_breakdown
¶
Get individual scores from each strategy for analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dictionary mapping strategy names to their scores. |
Source code in src/turtle_quant_1/strategies/base.py
Signal
¶
Bases: BaseModel
Trading signal with comprehensive information.
Attributes:
| Name | Type | Description |
|---|---|---|
strategies |
List[str]
|
List of strategy names that contributed to this signal. |
action |
SignalAction
|
The trading action (BUY, HOLD, or SELL). |
score |
float
|
The final aggregated score between -1.0 and +1.0. |
SignalAction
¶
Bases: Enum
Trading signal actions.