View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Using MATLAB to Optimize Portfolios with Financial Toolbox

4.8 | 9 ratings Rate this file 63 Downloads (last 30 days) File Size: 118 KB File ID: #31290 Version:
image thumbnail

Using MATLAB to Optimize Portfolios with Financial Toolbox


Bob Taylor (view profile)


03 May 2011 (Updated )

Scripts and data to demonstrate the new Portfolio object in Financial Toolbox.

| Watch this File

File Information

A .zip file contains a series of scripts that were used in the MathWorks webinar "Using MATLAB to Optimize Portfolios with Financial Toolbox." The scripts demonstrate features of the Portfolio object and follows with case studies that demonstrate how to customize the tools for different tasks, including Sharpe/information ratio optimization and 130/30 portfolios. A readme.txt. file in the .zip folder describes how to use the scripts.

Required Products Financial Toolbox
Optimization Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
22 Sep 2016 mono

mono (view profile)


in the script, the backtest is performed in quarter, then it is converted into annual (times pfactor).

but in figure(1), the input variable 'X' is in month, then [srsk, sret] = p.estimatePortMoments(swgt) gives the risk and result also in month. Then times pfactor convert it into quarterly result but NOT in annual.

Comment only
22 Sep 2016 mono

mono (view profile)

If I understood correctly, in 'part2_strategy.m' file, PortRisk, PortReturn as well as PortMean, PortSigma are converted into quarterly period (times pfactor or sort(pfactor)). So the plotted figure(1) and printed results are also in quarter NOT in annual. Not sure if you mean to do so.

Great scripts.

Comment only
24 Mar 2016 erdek15

Dear Bob,

Thank you very much for this. I have a question regarding the Map variable. When you said "...which assets were in the universe on a given date", does it mean certain assets were simply non-existent at certain point in time (i.e. delisted from the exchange)?

11 Mar 2016 meng wang

Great demo!

22 Sep 2015 Cyrus

Cyrus (view profile)

20 Apr 2015 Ales Kudrna

31 Mar 2015 Chongwu Guo

Amazing model

27 Aug 2014 Bob Taylor

Bob Taylor (view profile)

The Portfolio object has the methods estimateFrontierByReturn and estimateFrontierByRisk, where the former provides portfolios for specified portfolio returns and the latter provides portfolios for specified portfolio risks. Once you have portfolios from these methods, the methods estimatePortReturn and estimatePortRisk provide portfolio returns and risks for specified portfolios.

In a mean-variance framework with normally-distributed asset returns, the periodicity of the data has no impact on the portfolios on the efficient frontier. The portfolio returns and risks, however, will depend upon the periodicity of underlying asset returns.

Comment only
04 Aug 2014 Hua

Hua (view profile)

Dear Bob Taylor,

Could you please help me with this question.

How could I find out for what the risk is for a given target return? (line 130)
I can look at the graph and make an estimation but is there a way to output the exact number??

Also I am working on daily data and plotting an efficient frontier for every three month. would it still work?

I look forward to hear back from you, any help will be high appreciated.


06 May 2014 Narek

Narek (view profile)

12 Apr 2014 Bob Taylor

Bob Taylor (view profile)

The webinar and scripts illustrate various ways to implement portfolio optimization under an assumption that you already have the data you need (gathering, managing, scrubbing, and forming total returns data can be a messy or easy process depending upon which data sources you might be able to access). The MATLAB Datafeed Toolbox has a good selection of sources although some sources require that you to have a license to obtain such data.

The BlueChipStocks file contains monthly total return data for 44 stocks, 1 market index, and 1 cash index. These data are in the variable Data with corresponding asset identifiers in the variable Asset and (month-end) dates in the variable Date. The last variable Map contains indicators that match the pattern of Data to identify which assets were in the universe on a given date.

If you have monthly total return data, you should be able to modify these four variables to suit your requirements and the scripts ought to work with minor modification (for example, you would have to specify the time period for backtests and so forth).

Comment only
08 Apr 2014 Arslan Habib, CFA

The question is how to create the file named bluechipstocks. Please help. I am stuck at this point and its useless I can not define my stocks and time period my choice. Any help will he highly appreciated. You can also send email at

Comment only
08 Apr 2014 Arslan Habib, CFA

In this video you can not change the stocks in the bluechipstocks sheet. How will change the bluechipstocks sheet to use stocks which i want instead of the stocks you have ?

Comment only
23 Feb 2014 rakesh

rakesh (view profile)


11 Oct 2013 Robin

Robin (view profile)

11 Oct 2013 Robin

Robin (view profile)

Many thanks for part1_intro - of great help for my master's thesis' research! Question: in what way does "Confirm that Maximum Sharpe Ratio is a Maximum" fulfill it's purpose as the Sharpe generated there has different values (risk, return) from the one generated in "Maximize the Sharpe Ratio"?

Comment only
24 Jul 2013 Benjamin

where is "map" coming from? There doesn't seem to be any correspondance between map and when the assets were live.

Comment only
04 Mar 2013 oussama salhi

Very good model

Comment only
24 Jan 2012 Raymond Morano

I see the portfolio object in release 2007B

Comment only
01 Sep 2016

Updated license

Contact us