relative_rotation
Calculate the Relative Strength Ratio and Relative Strength Momentum for a group of symbols against a benchmark.
Examples
from openbb import obb
# Calculate the Relative Strength Ratio and Relative Strength Momentum for a group of symbols against a benchmark.
stock_data = obb.equity.price.historical(symbol='AAPL,MSFT,GOOGL,META,AMZN,TSLA,SPY', start_date='2022-01-01', provider='yfinance')
rr_data = obb.technical.relative_rotation(data=stock_data.results, benchmark='SPY')
rs_ratios = rr_data.results.rs_ratios
rs_momentum = rr_data.results.rs_momentum
# When the assets are not traded 252 days per year,adjust the momentum and volatility periods accordingly.
crypto_data = obb.crypto.price.historical( symbol='BTCUSD,ETHUSD,SOLUSD', start_date='2021-01-01', provider='yfinance')
rr_data = obb.technical.relative_rotation(data=crypto_data.results, benchmark='BTCUSD', long_period=365, short_period=30, window=30, trading_periods=365)
# Note that the mock data displayed here is insufficient. It must contain multiple symbols, with the benchmark, and be daily data at least 1 year in length.
obb.technical.relative_rotation(benchmark='SPY', 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
| Name | Type | Description | Default | Optional |
|---|---|---|---|---|
| data | list[Data] | The data to be used for the relative rotation calculations. | False | |
| benchmark | str | The symbol to be used as the benchmark. | False | |
| study | Literal[price, volume, volatility] | The data point for the calculations. If 'price', the closing price will be used. | False | |
| long_period | int, optional | The length of the long period for momentum calculation, by default 252. | False | |
| short_period | int, optional | The length of the short period for momentum calculation, by default 21. | False | |
| window | int, optional | The length of window for the standard deviation calculation, by default 21. | False | |
| trading_periods | int, optional | The number of trading periods per year, for the standard deviation calculation, by default 252. | False | |
| chart_params | dict[str, Any], optional | Additional parameters to pass when chart=True and the openbb-charting extension is installed. | False | |
| date | str, optional | A target end date within the data to use for the chart, by default is the last date in the data. | False | |
| show_tails | bool | Show the tails on the chart, by default True. | False | |
| tail_periods | int | Number of periods to show in the tails, by default 16. | False | |
| tail_interval | Literal[day, week, month] | Interval to show the tails, by default 'week'. | False | |
| title | str, optional | Title of the chart. | False | |
| results | RelativeRotationData | symbols : list[str]: | False | |
| benchmark | str | The benchmark symbol. | False | |
| study | Literal[price, volume, volatility] | The data point for the selected. | False | |
| long_period | int | The length of the long period for momentum calculation, as entered by the user. | False | |
| short_period | int | The length of the short period for momentum calculation, as entered by the user. | False | |
| window | int | The length of window for the standard deviation calculation. | False | |
| trading_periods | int | The number of trading periods per year, for the standard deviation calculation. | False | |
| start_date | str | The start date of the data after adjusting the length of the data for the calculations. | False | |
| end_date | str | The end date of the data. | False | |
| symbols_data | list[Data] | The data representing the selected 'study' for each symbol. | False | |
| benchmark_data | list[Data] | The data representing the selected 'study' for the benchmark. | False | |
| rs_ratios | list[Data] | The normalized relative strength ratios data. | False | |
| rs_momentum | list[Data] | The normalized relative strength momentum data. | False |
Returns
OBBject
results : RelativeRotationData
results : RelativeRotationData