Lean  $LEAN_TAG$
QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel Class Reference

Provides an implementation of Black-Litterman portfolio optimization. The model adjusts equilibrium market returns by incorporating views from multiple alpha models and therefore to get the optimal risky portfolio reflecting those views. If insights of all alpha models have None magnitude or there are linearly dependent vectors in link matrix of views, the expected return would be the implied excess equilibrium return. The interval of weights in optimization method can be changed based on the long-short algorithm. The default model uses the 0.0025 as weight-on-views scalar parameter tau. The optimization method maximizes the Sharpe ratio with the weight range from -1 to 1. More...

Inheritance diagram for QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel:
[legend]

Public Member Functions

 BlackLittermanOptimizationPortfolioConstructionModel (TimeSpan timeSpan, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
 BlackLittermanOptimizationPortfolioConstructionModel (Resolution rebalanceResolution=Resolution.Daily, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
 BlackLittermanOptimizationPortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
 BlackLittermanOptimizationPortfolioConstructionModel (IDateRule rebalancingDateRules, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
 BlackLittermanOptimizationPortfolioConstructionModel (PyObject rebalance, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
 BlackLittermanOptimizationPortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort, int lookback=1, int period=63, Resolution resolution=Resolution.Daily, double riskFreeRate=0.0, double delta=2.5, double tau=0.05, IPortfolioOptimizer optimizer=null)
 Initialize the model More...
 
override void OnSecuritiesChanged (QCAlgorithm algorithm, SecurityChanges changes)
 Event fired each time the we add/remove securities from the data feed More...
 
virtual double[] GetEquilibriumReturns (double[,] returns, out double[,] Σ)
 Calculate equilibrium returns and covariance More...
 
- Public Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
 PortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc)
 Initialize a new instance of PortfolioConstructionModel More...
 
 PortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc=null)
 Initialize a new instance of PortfolioConstructionModel More...
 
virtual IEnumerable< IPortfolioTargetCreateTargets (QCAlgorithm algorithm, Insight[] insights)
 Create portfolio targets from the specified insights More...
 

Protected Member Functions

override bool ShouldCreateTargetForInsight (Insight insight)
 Method that will determine if the portfolio construction model should create a target for this insight More...
 
override Dictionary< Insight, double > DetermineTargetPercent (List< Insight > lastActiveInsights)
 Will determine the target percent for each insight More...
 
override List< InsightGetTargetInsights ()
 Gets the target insights to calculate a portfolio target percent for More...
 
bool TryGetViews (ICollection< Insight > insights, out double[,] P, out double[] Q)
 Generate views from multiple alpha models More...
 
- Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
void SetPythonWrapper (PortfolioConstructionModelPythonWrapper pythonWrapper)
 Used to set the PortfolioConstructionModelPythonWrapper instance if any More...
 
void SetRebalancingFunc (PyObject rebalance)
 Python helper method to set the rebalancing function. This is required due to a python net limitation not being able to use the base type constructor, and also because when python algorithms use C# portfolio construction models, it can't convert python methods into func nor resolve the correct constructor for the date rules, timespan parameter. For performance we prefer python algorithms using the C# implementation More...
 
virtual bool IsRebalanceDue (Insight[] insights, DateTime algorithmUtc)
 Determines if the portfolio should be rebalanced base on the provided rebalancing func, if any security change have been taken place or if an insight has expired or a new insight arrived If the rebalancing function has not been provided will return true. More...
 
void RefreshRebalance (DateTime algorithmUtc)
 Refresh the next rebalance time and clears the security changes flag More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
static Insight[] FilterInvalidInsightMagnitude (IAlgorithm algorithm, Insight[] insights)
 Helper class that can be used by the different IPortfolioConstructionModel implementations to filter Insight instances with an invalid Insight.Magnitude value based on the IAlgorithmSettings More...
 
- Protected Attributes inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
PortfolioConstructionModelPythonWrapper PythonWrapper
 This is required due to a limitation in PythonNet to resolved overriden methods. When Python calls a C# method that calls a method that's overriden in python it won't run the python implementation unless the call is performed through python too. More...
 
- Properties inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
virtual bool RebalanceOnSecurityChanges = true [get, set]
 True if should rebalance portfolio on security changes. True by default More...
 
virtual bool RebalanceOnInsightChanges = true [get, set]
 True if should rebalance portfolio on new insights or expiration of insights. True by default More...
 
IAlgorithm Algorithm [get]
 The algorithm instance More...
 

Detailed Description

Provides an implementation of Black-Litterman portfolio optimization. The model adjusts equilibrium market returns by incorporating views from multiple alpha models and therefore to get the optimal risky portfolio reflecting those views. If insights of all alpha models have None magnitude or there are linearly dependent vectors in link matrix of views, the expected return would be the implied excess equilibrium return. The interval of weights in optimization method can be changed based on the long-short algorithm. The default model uses the 0.0025 as weight-on-views scalar parameter tau. The optimization method maximizes the Sharpe ratio with the weight range from -1 to 1.

Definition at line 38 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Constructor & Destructor Documentation

◆ BlackLittermanOptimizationPortfolioConstructionModel() [1/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( TimeSpan  timeSpan,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
timeSpanRebalancing frequency
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

Definition at line 63 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

◆ BlackLittermanOptimizationPortfolioConstructionModel() [2/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( Resolution  rebalanceResolution = Resolution.Daily,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
rebalanceResolutionRebalancing frequency
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

Definition at line 88 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

◆ BlackLittermanOptimizationPortfolioConstructionModel() [3/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( Func< DateTime, DateTime >  rebalancingFunc,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
rebalancingFuncFor a given algorithm UTC DateTime returns the next expected rebalance UTC time. Returning current time will trigger rebalance. If null will be ignored
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

Definition at line 114 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

◆ BlackLittermanOptimizationPortfolioConstructionModel() [4/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( IDateRule  rebalancingDateRules,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
rebalancingDateRulesThe date rules used to define the next expected rebalance time in UTC
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

Definition at line 148 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

◆ BlackLittermanOptimizationPortfolioConstructionModel() [5/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( PyObject  rebalance,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
rebalanceRebalancing func or if a date rule, timedelta will be converted into func. For a given algorithm UTC DateTime the func returns the next expected rebalance time or null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance. If null will be ignored
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

This is required since python net can not convert python methods into func nor resolve the correct constructor for the date rules parameter. For performance we prefer python algorithms using the C# implementation

Definition at line 179 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ BlackLittermanOptimizationPortfolioConstructionModel() [6/6]

QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.BlackLittermanOptimizationPortfolioConstructionModel ( Func< DateTime, DateTime?>  rebalancingFunc,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
int  lookback = 1,
int  period = 63,
Resolution  resolution = Resolution.Daily,
double  riskFreeRate = 0.0,
double  delta = 2.5,
double  tau = 0.05,
IPortfolioOptimizer  optimizer = null 
)

Initialize the model

Parameters
rebalancingFuncFor a given algorithm UTC DateTime returns the next expected rebalance time or null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance.
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
lookbackHistorical return lookback period
periodThe time interval of history price to calculate the weight
resolutionThe resolution of the history price
riskFreeRateThe risk free rate
deltaThe risk aversion coeffficient of the market portfolio
tauThe model parameter indicating the uncertainty of the CAPM prior
optimizerThe portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.

Definition at line 207 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Member Function Documentation

◆ ShouldCreateTargetForInsight()

override bool QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.ShouldCreateTargetForInsight ( Insight  insight)
protectedvirtual

Method that will determine if the portfolio construction model should create a target for this insight

Parameters
insightThe insight to create a target for
Returns
True if the portfolio should create a target for the insight

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 238 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetermineTargetPercent()

override Dictionary<Insight, double> QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.DetermineTargetPercent ( List< Insight lastActiveInsights)
protectedvirtual

Will determine the target percent for each insight

Parameters
lastActiveInsightsThe active insights to generate a target for
Returns
A target percent for each insight

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 248 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ GetTargetInsights()

override List<Insight> QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.GetTargetInsights ( )
protectedvirtual

Gets the target insights to calculate a portfolio target percent for

Returns
An enumerable of the target insights

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 302 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ OnSecuritiesChanged()

override void QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.OnSecuritiesChanged ( QCAlgorithm  algorithm,
SecurityChanges  changes 
)
virtual

Event fired each time the we add/remove securities from the data feed

Parameters
algorithmThe algorithm instance that experienced the change in securities
changesThe security additions and removals from the algorithm

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 319 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ GetEquilibriumReturns()

virtual double [] QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.GetEquilibriumReturns ( double  returns[,],
out double  Σ[,] 
)
virtual

Calculate equilibrium returns and covariance

Parameters
returnsMatrix of returns where each column represents a security and each row returns for the given date/time (size: K x N)
ΣMulti-dimensional array of double with the portfolio covariance of returns (size: K x K).
Returns
Array of double of equilibrium returns

Definition at line 355 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ TryGetViews()

bool QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel.TryGetViews ( ICollection< Insight insights,
out double  P[,],
out double[]  Q 
)
protected

Generate views from multiple alpha models

Parameters
insightsArray of insight that represent the investors' views
PA matrix that identifies the assets involved in the views (size: K x N)
QA view vector (size: K x 1)

Definition at line 377 of file BlackLittermanOptimizationPortfolioConstructionModel.cs.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: