Correlations (correlations v0.1.0)
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
coefficient()
Specs
coefficient() :: non_neg_integer() | :NaN | :inf
decimal()
Specs
exponent()
Specs
exponent() :: integer()
json()
Specs
json() :: String.t()
sign()
Specs
sign() :: 1 | -1
Specs
t() :: %Decimal{coef: coefficient(), exp: exponent(), sign: sign()}
Link to this section Functions
correlation(x, y)
Specs
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>
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>}], ]
correlation_matrix(list, acc)
json_correlation_matrix(stocks)
JSON Correlation Matrix
returns matrix data in JSON format. Ex frontend usage: (Link)[https://github.com/GunnarPDX/correlation-matrix-chart]
portfolio_correlations_list(stocks, portfolio_size)
Specs
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]} ]
portfolio_correlations_picker(stocks, portfolio_size)
Specs
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]}