crossovers
Detect bullish and bearish moving-average crossover events.
Examples
from openbb import obb
# 20/50 SMA crossover events on daily SPY.
data = obb.equity.price.historical(symbol='SPY', start_date='2022-01-01', provider='yfinance').results
events = obb.technical.crossovers(data=data, fast_length=20, slow_length=50)
obb.technical.signals.crossovers(data=[{'date': '2023-01-02', 'open': 110.0, 'high': 120.0, 'low': 100.0, 'close': 115.0, 'volume': 10000.0}, {'date': '2023-01-03', 'open': 165.0, 'high': 180.0, 'low': 150.0, 'close': 172.5, 'volume': 15000.0}, {'date': '2023-01-04', 'open': 146.67, 'high': 160.0, 'low': 133.33, 'close': 153.33, 'volume': 13333.33}, {'date': '2023-01-05', 'open': 137.5, 'high': 150.0, 'low': 125.0, 'close': 143.75, 'volume': 12500.0}, {'date': '2023-01-06', 'open': 132.0, 'high': 144.0, 'low': 120.0, 'close': 138.0, 'volume': 12000.0}])
Parameters
- standard
data: Data | DataFrame | Series | dict | list | list[DataFrame] | list[Data] | list[Series] | ndarray
Input price series.
target: str
Default: close
Column on which to compute moving averages.
index: str
Default: date
Index column name in data.
fast_length: int
Default: 20
Lookback for the fast moving average.
slow_length: int
Default: 50
Lookback for the slow moving average.
mamode: str
Default: sma
Moving-average flavour. sma is the default; ema, wma, hma and zlma are also supported.
Returns
results: list[CrossoverEvent]
Serializable results.
provider: str
Provider name.
warnings: Optional[list[Warning_]]
List of warnings.
chart: Optional[Chart]
Chart object.
extra: dict[str, Any]
Extra info.
Data
- standard
date: date | datetime | str
Date of the crossover bar.
direction: str
bullish when fast crosses above slow, bearish when fast crosses below.
fast_value: float
Fast moving-average value at the crossover bar.
slow_value: float
Slow moving-average value at the crossover bar.
price: float
Target-column price at the crossover bar.
distance: float
fast_value - slow_value. Positive for bullish, negative for bearish crossovers.