Code covered by the BSD License  

Highlights from
Enhancing e-Infrastructures with Advanced Technical Computing: Parallel MATLAB® on the Grid

Demo6_task_optim_script.m
%% Parfor version of Portfolio Optimization 
%
% This demo uses the Parallel Computing Toolbox(TM) to perform a mean-variance 
% portfolio optimization of a stock portfolio, and generates an efficient
% frontier.  The portfolios on the frontier are optimal in the sense that they
% offer the minimal risk for some given level of expected return.
%
% We are given the daily returns of a group of stocks over a fixed 
% time period, and try to choose a portfolio such that it achieves some given
% return mu, and has minimal risk in the mean-variance sense.
% This leads us to solve a quadratic minimization problem with equality
% constraints.  Solving this minimization problem for a range of values of 
% mu gives us the efficient frontier.
%

%% Demo Setup
% This function gives us the desired returns, |muVec|, for which we should
% find the minimal risk. The demo difficulty level controls the length of the
% vector |muVec|.  Additionally, the function |Demo6_setup_optim| displays
% for reference a graph of the daily returns of a few of the stocks in the
% portfolio. 

difficulty = 1; 
[fig, muVec, covMat, expRet ] = Demo6_setup_optim(difficulty);

%% Running the optimization that uses a parfor

tic
[risk, ret] = Demo6_task_optim_parfor(covMat, expRet, muVec);
elapsedTimeParallel = toc;

%% Clear all variables that I don't want to send back

clearvars -except risk ret elapsedTimeParallel

Contact us at files@mathworks.com