API Docs

Manual, tutorials and complete function reference

optimization_run

Runs portfolio optimization algorithm with provided constraints.


Usage
optimization_run(optimizer)
optimizer
Optimizer object created using optimization_goal function

Return Value
Optimal portfolio.
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,10000,'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,10000,'Return','maximize');
optimizer=optimization_constraint_weight(optimizer,'>=',0.8,['AAPL';'GOOG']);

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