get_correlation(quotes_a, quotes_b, lookback_periods)
||Iterable[Quote]||Iterable(such as list or an object having
• Need help with pandas.DataFrame?
||Iterable[Quote]||Historical quotes (B) must have at least the same matching date elements of
||int||Number of periods (
Historical quotes requirements
You must have at least
N periods for both versions of
quotes to cover the warmup periods. Mismatch histories will produce a
InvalidQuotesException. Historical price quotes should have a consistent frequency (day, hour, minute, etc).
quotes_a is an
Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
- This method returns a time series of all available indicator values for the
CorrelationResultsis just a list of
- It always returns the same number of elements as there are in the historical quotes.
- It does not return a single incremental indicator value.
- The first
N-1periods will have
Nonevalues since there’s not enough data to calculate.
||float, Optional||Variance of A based on
||float, Optional||Variance of B based on
||float, Optional||Covariance of A+B based on
||float, Optional||R-Squared (R²), aka Coefficient of Determination. Simple linear regression models is used (square of Correlation).|
See Utilities and Helpers for more information.
from stock_indicators import indicators # This method is NOT a part of the library. quotes_spx = get_history_from_feed("SPX") quotes_tsla = get_history_from_feed("TSLA") # Calculate 20-period Correlation results = indicators.get_correlation(quotes_spx, quotes_tsla, 20)
About Correlation Coefficient
Correlation Coefficient between two quote histories, based on Close price. R-Squared (R²), Variance, and Covariance are also output. [Discuss]