Correlations (correlations v0.1.1)

Documentation for Correlations.

Link to this section Summary

Functions

Correlation

Finds the correlation coefficient between two lists of decimals

Correlation Matrix

Creates a correlation matrix from a list of products

JSON Correlation Matrix

returns matrix data in JSON format. Ex frontend usage: (Link)[https://github.com/GunnarPDX/correlation-matrix-chart]

Portfolio Correlations List

Creates a list of portfolio combinations with correlation coefficients

Portfolio Correlations Picker

Picks the optimal portfolio combination with lowest correlation coefficient

Link to this section Types

Link to this type

coefficient()

Specs

coefficient() :: non_neg_integer() | :NaN | :inf

Specs

decimal() :: t() | integer() | String.t()

Specs

exponent() :: integer()

Specs

json() :: String.t()

Specs

sign() :: 1 | -1

Specs

t() :: %Decimal{coef: coefficient(), exp: exponent(), sign: sign()}

Link to this section Functions

Link to this function

correlation(x, y)

Specs

correlation([decimal()], [decimal()]) :: decimal()

Correlation

Finds the correlation coefficient between two lists of decimals

Examples

iex> list1 = [#Decimal<124.400002>, #Decimal<121.099998>, ...]
...

iex> list2 = [#Decimal<569.039978>, #Decimal<569.929993>, ...]
...

iex> correlation(list1, list2)
#Decimal<0.809616345>
Link to this function

correlation_matrix(stocks)

Specs

correlation_matrix([{atom(), [decimal()]}]) :: [[{atom(), atom(), decimal()}]]
correlation_matrix([{atom(), [decimal()]}]) :: json()

Correlation Matrix

Creates a correlation matrix from a list of products

Examples

iex> stocks = [aapl: [#Decimal<124.400002>, #Decimal<121.099998>, ...], nvda: [#Decimal<552.460022>, ...], ... ]
...

iex> correlation_matrix(stocks)
[
  [{:aapl, :nvda, #Decimal<0.809616347>},{:aapl, :tsla, #Decimal<0.104192125>},{:aapl, :amzn, #Decimal<0.674977695>}],
  [{:nvda, :tsla, #Decimal<0.198672188>}, {:nvda, :amzn, #Decimal<0.867990063>}],
  [{:tsla, :amzn, #Decimal<0.236184044>}],
]
Link to this function

json_correlation_matrix(stocks)

JSON Correlation Matrix

returns matrix data in JSON format. Ex frontend usage: (Link)[https://github.com/GunnarPDX/correlation-matrix-chart]

Link to this function

portfolio_correlations_list(stocks, portfolio_size)

Specs

portfolio_correlations_list([{atom(), [decimal()]}], integer()) :: [
  {decimal(), [atom()]}
]

Portfolio Correlations List

Creates a list of portfolio combinations with correlation coefficients

Examples

iex> stocks = [aapl: [#Decimal<124.400002>, #Decimal<121.099998>, ...], nvda: [#Decimal<552.460022>, ...], ... ]
...

iex> size = 2
2

iex> portfolio_correlations_list(stocks, portfolio_size)
[
  {#Decimal<0.809616345>, [:aapl, :nvda]},
  {#Decimal<0.104192125>, [:aapl, :tsla]},
  {#Decimal<0.674977695>, [:aapl, :amzn]},
  {#Decimal<0.198672188>, [:nvda, :tsla]},
  {#Decimal<0.867990065>, [:amzn, :nvda]},
  {#Decimal<0.236184044>, [:amzn, :tsla]}
]
Link to this function

portfolio_correlations_picker(stocks, portfolio_size)

Specs

portfolio_correlations_picker([{atom(), [decimal()]}], integer()) ::
  {decimal(), [atom()]}

Portfolio Correlations Picker

Picks the optimal portfolio combination with lowest correlation coefficient

Examples

iex> stocks = [aapl: [#Decimal<124.400002>, #Decimal<121.099998>, ...], nvda: [#Decimal<552.460022>, ...], ... ]
...

iex> size = 2
2

iex> portfolio_correlations_picker(stocks, portfolio_size)
{#Decimal<0.104192125>, [:aapl, :tsla]}