API Docs

Manual, tutorials and complete function reference

optimization_constraint_allWeights

Adds portfolio optimization constraint restricting all optimal portfolio's position weights to a certain range.


Usage
optimization_constraint_allWeights(optimizer,
				constraintType,
				constraintValue)
optimizer
Optimizer object created using optimization_goal function
constraintType
Optimization constraint type:
  • "=" - an equality constraint
  • ">=" - an inclusive lower bound constraint
  • "<=" - an inclusive upper bound constraint
constraintValue
Value to be used as a constraint equality or boundary.

Return Value
Original optimizer object.
Examples
# load data
data(goog.data)
data(aapl.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_allWeights(optimizer,'>=',0)

# 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_allWeights(optimizer,'>=',0)

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