/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For 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.</param> /// <param name="portfolioBias">Specifies the bias of the portfolio (Short, Long/Short, Long)</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public 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) : base(rebalancingFunc) { _lookback = lookback; _period = period; _resolution = resolution; _riskFreeRate = riskFreeRate; _delta = delta; _tau = tau; var lower = portfolioBias == PortfolioBias.Long ? 0 : -1; var upper = portfolioBias == PortfolioBias.Short ? 0 : 1; _optimizer = optimizer ?? new MaximumSharpeRatioPortfolioOptimizer(lower, upper, riskFreeRate); _portfolioBias = portfolioBias; _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
/// <summary> /// Initialize the model /// </summary> /// <param name="timeSpan">Rebalancing frequency</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(TimeSpan timeSpan, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : this(dt => dt.Add(timeSpan), lookback, period, resolution, targetReturn, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingDateRules">The date rules used to define the next expected rebalance time /// in UTC</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(IDateRule rebalancingDateRules, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : this(rebalancingDateRules.ToFunc(), lookback, period, resolution, targetReturn, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalanceResolution">Rebalancing frequency</param> /// <param name="portfolioBias">Specifies the bias of the portfolio (Short, Long/Short, Long)</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(Resolution rebalanceResolution = Resolution.Daily, PortfolioBias portfolioBias = PortfolioBias.LongShort, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : this(rebalanceResolution.ToTimeSpan(), portfolioBias, lookback, period, resolution, targetReturn, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingParam">Rebalancing 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</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> /// <remarks>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</remarks> public MeanVarianceOptimizationPortfolioConstructionModel(PyObject rebalancingParam, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : this((Func <DateTime, DateTime?>)null, lookback, period, resolution, targetReturn, optimizer) { SetRebalancingFunc(rebalancingParam); }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalanceResolution">Rebalancing frequency</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public BlackLittermanOptimizationPortfolioConstructionModel(Resolution rebalanceResolution = Resolution.Daily, 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) : this(rebalanceResolution.ToTimeSpan(), lookback, period, resolution, riskFreeRate, delta, tau, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingParam">Rebalancing 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</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> /// <remarks>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</remarks> public BlackLittermanOptimizationPortfolioConstructionModel(PyObject rebalancingParam, 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) : this((Func <DateTime, DateTime?>)null, lookback, period, resolution, riskFreeRate, delta, tau, optimizer) { SetRebalancingFunc(rebalancingParam); }
/// <summary> /// Initialize the model /// </summary> /// <param name="timeSpan">Rebalancing frequency</param> /// <param name="portfolioBias">Specifies the bias of the portfolio (Short, Long/Short, Long)</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public 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) : this(dt => dt.Add(timeSpan), portfolioBias, lookback, period, resolution, riskFreeRate, delta, tau, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingDateRules">The date rules used to define the next expected rebalance time /// in UTC</param> /// <param name="portfolioBias">Specifies the bias of the portfolio (Short, Long/Short, Long)</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public 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) : this(rebalancingDateRules.ToFunc(), portfolioBias, lookback, period, resolution, riskFreeRate, delta, tau, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For a given algorithm UTC DateTime returns the next expected rebalance UTC time. /// Returning current time will trigger rebalance. If null will be ignored</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(Func <DateTime, DateTime> rebalancingFunc, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : this(rebalancingFunc != null ? (Func <DateTime, DateTime?>)(timeUtc => rebalancingFunc(timeUtc)) : null, lookback, period, resolution, targetReturn, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For 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.</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(Func <DateTime, DateTime?> rebalancingFunc, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : base(rebalancingFunc) { _lookback = lookback; _period = period; _resolution = resolution; _optimizer = optimizer ?? new MinimumVariancePortfolioOptimizer(targetReturn: targetReturn); _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
/// <summary> /// Initialize the model /// </summary> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel( int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null ) { _lookback = lookback; _period = period; _resolution = resolution; _optimizer = optimizer ?? new MinimumVariancePortfolioOptimizer(targetReturn: targetReturn); _pendingRemoval = new List <Symbol>(); _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For a given algorithm UTC DateTime returns the next expected rebalance UTC time. /// Returning current time will trigger rebalance. If null will be ignored</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public BlackLittermanOptimizationPortfolioConstructionModel(Func <DateTime, DateTime> rebalancingFunc, 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) : this(rebalancingFunc != null ? (Func <DateTime, DateTime?>)(timeUtc => rebalancingFunc(timeUtc)) : null, lookback, period, resolution, riskFreeRate, delta, tau, optimizer) { }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For a given algorithm UTC DateTime returns the next expected rebalance UTC time</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="delta">The risk aversion coeffficient of the market portfolio</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public BlackLittermanOptimizationPortfolioConstructionModel(Func <DateTime, DateTime> rebalancingFunc, 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) : base(time => rebalancingFunc?.Invoke(time) ?? time) { _lookback = lookback; _period = period; _resolution = resolution; _riskFreeRate = riskFreeRate; _delta = delta; _tau = tau; _optimizer = optimizer ?? new MaximumSharpeRatioPortfolioOptimizer(riskFreeRate: riskFreeRate); _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
/// <summary> /// Initialize the model /// </summary> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="riskFreeRate">The risk free rate</param> /// <param name="tau">The model parameter indicating the uncertainty of the CAPM prior</param> /// <param name="optimizer">The portfolio optimization algorithm. If no algorithm is explicitly provided then the default will be max Sharpe ratio optimization.</param> public BlackLittermanOptimizationPortfolioConstructionModel( int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double riskFreeRate = 0.0, double tau = 0.025, IPortfolioOptimizer optimizer = null ) { _lookback = lookback; _period = period; _resolution = resolution; _riskFreeRate = riskFreeRate; _tau = tau; _optimizer = optimizer ?? new MaximumSharpeRatioPortfolioOptimizer(riskFreeRate: riskFreeRate); _pendingRemoval = new List <Symbol>(); _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
/// <summary> /// Initialize the model /// </summary> /// <param name="rebalancingFunc">For 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.</param> /// <param name="portfolioBias">Specifies the bias of the portfolio (Short, Long/Short, Long)</param> /// <param name="lookback">Historical return lookback period</param> /// <param name="period">The time interval of history price to calculate the weight</param> /// <param name="resolution">The resolution of the history price</param> /// <param name="targetReturn">The target portfolio return</param> /// <param name="optimizer">The portfolio optimization algorithm. If the algorithm is not provided then the default will be mean-variance optimization.</param> public MeanVarianceOptimizationPortfolioConstructionModel(Func <DateTime, DateTime?> rebalancingFunc, PortfolioBias portfolioBias = PortfolioBias.LongShort, int lookback = 1, int period = 63, Resolution resolution = Resolution.Daily, double targetReturn = 0.02, IPortfolioOptimizer optimizer = null) : base(rebalancingFunc) { _lookback = lookback; _period = period; _resolution = resolution; _portfolioBias = portfolioBias; var lower = portfolioBias == PortfolioBias.Long ? 0 : -1; var upper = portfolioBias == PortfolioBias.Short ? 0 : 1; _optimizer = optimizer ?? new MinimumVariancePortfolioOptimizer(lower, upper, targetReturn); _symbolDataDict = new Dictionary <Symbol, ReturnsSymbolData>(); }
public BLOPCM(IPortfolioOptimizer optimizer) : base(optimizer: optimizer) { }
public BLOPCM(IPortfolioOptimizer optimizer, PortfolioBias portfolioBias) : base(optimizer: optimizer, portfolioBias: portfolioBias) { }