Hi, in this video, we are going to talk about portfolio optimization. The problem exists
because we want to find the best investment based on our risk preferences and investment constraints.
And I am going to show how to find the portfolio weights that maximize the Sharpe ratio based on mean-variance portfolio optimization
in just 8 lines of MATLAB code.
When we want to analyze anything in finance, we usually begin with market data.
So the first step is to import the market data, which can be in the form of files, database, or datafeed.
Then, we can create portfolio, estimate mean and covariance, set investment constraints, and run portfolio optimization.
Now let’s see it in MATLAB.
First of all, let’s open the data file. This file contain the daily prices of Dow Jones Industrial Average and its members for the period of one year. Now I am now going to bring this dataset into MATLAB.
This file contain the daily prices of Dow Jones Industrial Average and its members for the period of one year.
Now I am now going to bring this dataset into MATLAB.
Extract the symbol of index members from the table.
Convert prices into returns in just one command using tick2ret function.
The data is now ready, so we can define p as a portfolio of 30 stocks.
Here we are going to set risk-free rate to be 1% per annum.
Now we can estimate means and covariances of all assets by using just one line of MATLAB code.
Then set default constraints
so that we can’t short the asset and you have to invest 100% of your money. Nothing more and nothing less.
Finally, we are using estimateMaxSharpeRatio and estimatePortMoments to find the optimal weights together with its risk and return.
Here are the optimal weights
and the optimal risk and return.
As we can see here, these built-in functions in Financial Toolbox enable us as financial experts to spend more time working on
interesting financial problems instead of re- inventing the wheel and writing code.
Now we can copy the code into live script, which I have already written some commands for visualizing the result.
The graph here is the efficient frontier, which is mainly drawn by using plotfrontier function.
And this table contains the weights of optimal portfolio, which was plot as a yellow star in the efficient frontier.
In summary, I hope you can see how easy it is to perform portfolio optimization in MATLAB together with Financial Toolbox.
There are a lot of things you can do in portfolio optimization with MATLAB such as
implementing many types of constraints or changing types of portfolio optimization.
With MATLAB documentation, video, and webinar, you will find it is very easy to perform portfolio optimization using MATLAB.
Besides portfolio optimization, you can do much more with MATLAB ranging from applications such as
time series analysis, to risk analysis, and even algorithmic trading.
In case that you need more information, you can watch more videos on this page.
Or you can request a trial on MATLAB to start a trial immediately. Thank you very much for watching this video presentation.