API Docs

Manual, tutorials and complete function reference

optimization_goal

Routine to specify portfolio optimization goal and optimal portfolio value. Returns constructed optimizer object.


Usage
optimization_goal(portfolio,
		goal,
		direction,
		confidenceInterval,
		windowLength, 
		forecastLength,
		forecastType,
		errorInDecimalPoints,
		globalOptimumProbability)
portfolio
Portfolio object created using portfolio_create() function
goal
One of the following optimization goals:
  • "Variance" - portfolio returns variance
  • "VaR" - portfolio Value-at-Risk
  • "CVaR" - portfolio Expected Tail Loss
  • "ExpectedReturn" - portfolio expected return
  • "Return" - portfolio return
  • "SharpeRatio" - portfolio Sharpe Ratio
  • "ModifiedSharpeRatio" - portfolio modified Sharpe Ratio
  • "StarrRatio" - portfolio STARR Ratio
  • "ContraintsOnly" - no optimization is performed. This is used for returning portfolio that meets specified set of constraints
  • "None" - no optimization is performed, constraints are not processes. Portfolio positions are returned with equal weights.
direction
Choose direction of optimization algorithm.
  • "minimize" - portfolio returns variance
  • "maximize" - portfolio Value-at-Risk
confidenceInterval
Confidence interval (in decimals) to be used as a cut-off point (default value is 0.05). Applicable for "VaR", "CVaR", "ModifiedSharpeRatio", "StarrRatio" metrics only.
windowLength
Rolling window length (look-behind interval) for metric estimations and position history used in computing forecast values. Available interval values are: "Xs" - seconds, "Xm" - minutes, "Xh" - hours, "Xd" - trading days (6.5 hours in a trading day), "Xw" - weeks (5 trading days in 1 week), "Xmo" - month (21 trading day in 1 month), "Xy" - years (256 trading days in 1 year), "all" - all observations are used. Default value is "1d" - one trading day .
forecastLength
Forecast time step length (look-ahead duration). Available interval values are: "Xs" - seconds, "Xm" - minutes, "Xh" - hours, "Xd" - trading days (6.5 hours in a trading day), "Xw" - weeks (5 trading days in 1 week), "Xmo" - month (21 trading day in 1 month), "Xy" - years (256 trading days in 1 year), "all" - all observations are used. Default value is "1d" - one trading day .
forecastType
Forecast algorithm type, if user-defined metric forecasts are not provided: "simple" - use last available metric value, "exp_smoothing" - use automatic exponential smoothing Default value is "exp_smoothing".
errorInDecimalPoints
Estimation error in decimal points for computing optimal weights. Smaller value slows down optimization algorithm, but increases precision.
globalOptimumProbability
Required probability level of a global optimum. Higher value slows down optimization algorithm, but increases chance of finding globally optimal solution.

Return Value
Constructed optimizer object.
Examples
# load data
data(aapl.data) 
data(goog.data) 
data(spy.data) 

# create portfolio
portfolio=portfolio_create(priceDataIx=spy.data)
portfolio_settings(portfolio,windowLength = '1h')
portfolio_addPosition(portfolio,'GOOG',goog.data,100)
portfolio_addPosition(portfolio,'AAPL',aapl.data,300)
portfolio_addPosition(portfolio,'SPY',spy.data,150)

# print original portfolio
print(portfolio)

# set optimization goals and constraints
optimizer=optimization_goal(portfolio,'Return','maximize')
optimizer=optimization_constraint_weight(optimizer,'>=',0.8,c('AAPL','GOOG'))

# run optimization and print optimal portfolio
optimalPortfolio=optimization_run(optimizer)
print(optimalPortfolio)
% load data
goog.data=importdata('data_goog.mat'); 
aapl.data=importdata('data_aapl.mat');  
spy.data=importdata('data_spy.mat'); 

% create portfolio
portfolio=portfolio_create(spy.data,1); 
portfolio_settings(portfolio, 'windowLength', '1h');
portfolio_addPosition(portfolio,'GOOG',goog.data,100);
portfolio_addPosition(portfolio,'AAPL',aapl.data,300);
portfolio_addPosition(portfolio,'SPY',aapl.data,150);

% print original portfolio
display(portfolio);

% set optimization goals and constraints
optimizer=optimization_goal(portfolio,'Return','maximize');
optimizer=optimization_constraint_weight(optimizer,'>=',0.8,['AAPL';'GOOG']);

% run optimization and print optimal portfolio 
optimalPortfolio=optimization_run(optimizer);
display(optimalPortfolio);