Add minute bar feature pipeline
This commit is contained in:
+19
-5
@@ -5,7 +5,7 @@ position weights. Subclasses implement :meth:`signal` — the raw, unnormalized
|
||||
score. The base class turns a signal into cross-sectionally z-scored weights
|
||||
via :meth:`to_weights` (override it for a different normalization).
|
||||
"""
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import ABC
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
@@ -15,15 +15,14 @@ class BaseAlpha(ABC):
|
||||
"""A position-weight alpha over a cross-section of stocks.
|
||||
|
||||
Concrete subclasses must set a unique class-level :attr:`name` (the registry
|
||||
key) and implement :meth:`signal`. Construct subclasses with their own typed
|
||||
parameters (e.g. ``lookback``); the factory passes only the parameters a
|
||||
given ``__init__`` accepts.
|
||||
key) and implement either :meth:`signal` or :meth:`signal_from_data`.
|
||||
Construct subclasses with their own typed parameters (e.g. ``lookback``);
|
||||
the factory passes only the parameters a given ``__init__`` accepts.
|
||||
"""
|
||||
|
||||
#: Unique registry key. Every concrete alpha must set this to a non-empty str.
|
||||
name: str = ""
|
||||
|
||||
@abstractmethod
|
||||
def signal(self, close: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Compute the raw signal.
|
||||
|
||||
@@ -34,6 +33,21 @@ class BaseAlpha(ABC):
|
||||
A wide DataFrame aligned to ``close`` where higher values indicate a
|
||||
stronger long. Use NaN where the signal is undefined.
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
f"{type(self).__name__} must implement signal() or signal_from_data()"
|
||||
)
|
||||
|
||||
def signal_from_data(
|
||||
self,
|
||||
data: pd.DataFrame,
|
||||
close: pd.DataFrame,
|
||||
) -> pd.DataFrame:
|
||||
"""Compute the raw signal from long daily data plus wide closes.
|
||||
|
||||
Feature-aware alphas can override this to pivot joined feature columns
|
||||
from ``data``. The default preserves the existing close-only alpha API.
|
||||
"""
|
||||
return self.signal(close)
|
||||
|
||||
def to_weights(self, signal: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Cross-sectionally z-score a signal into signed position weights.
|
||||
|
||||
Reference in New Issue
Block a user