# Correlation Coefficient

Created by Karl Pearson, the Correlation Coefficient depicts the linear statistical correlation between two quote histories. R-Squared (R²), Variance, and Covariance are also output. [Discuss]

```
// usage
IEnumerable<CorrResult> results =
quotesA.GetCorrelation(quotesB, lookbackPeriods);
```

## Parameters

`quotesB`

* IEnumerable<TQuote>* - Historical quotes (B) must have at least the same matching date elements of

`quotesA`

.`lookbackPeriods`

* int* - Number of periods (

`N`

) in the lookback period. Must be greater than 0 to calculate; however we suggest a larger period for statistically appropriate sample size.### 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).

`quotesA`

is an `IEnumerable<TQuote>`

collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

## Response

```
IEnumerable<CorrResult>
```

- This method returns a time series of all available indicator values for the
`quotes`

provided. - 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-1`

periods will have`null`

values since there’s not enough data to calculate.

### CorrResult

`Date`

* DateTime* - Date from evaluated

`TQuote`

`VarianceA`

* double* - Variance of A

`VarianceB`

* double* - Variance of B

`Covariance`

* double* - Covariance of A+B

`Correlation`

* double* - Correlation

`R`

`RSquared`

* double* - R-Squared (R²), aka Coefficient of Determination. Simple linear regression models is used (square of Correlation).

### Utilities

See Utilities and helpers for more information.

## Chaining

This indicator may be generated from any chain-enabled indicator or method.

```
// example
var results = quotes
.Use(CandlePart.HL2)
.GetCorrelation(quotesMarket.Use(CandlePart.HL2),20);
```

Warning!Both`quotesA`

and`quotesB`

arguments must contain the same number of elements and be the results of a chainable indicator or`.Use()`

method.

Results can be further processed on `Correlation`

with additional chain-enabled indicators.

```
// example
var results = quotes
.GetCorrelation(..)
.GetSlope(..);
```