matlab的portopt,Plotting an Efficient Frontier Using portopt

Plotting an Efficient Frontier Using portopt

This example plots the efficient frontier of a hypothetical

portfolio of three assets. It illustrates how to specify the expected

returns, standard deviations, and correlations of a portfolio of assets,

how to convert standard deviations and correlations into a covariance

matrix, and how to compute and plot the efficient frontier from the

returns and covariance matrix. The example also illustrates how to

randomly generate a set of portfolio weights, and how to add the random

portfolios to an existing plot for comparison with the efficient frontier.

First, specify the expected returns, standard deviations, and

correlation matrix for a hypothetical portfolio of three assets.

Returns = [0.1 0.15 0.12];

STDs = [0.2 0.25 0.18];

Correlations = [ 1 0.3 0.4

0.3 1 0.3

0.4 0.3 1 ];

Convert the standard deviations and correlation matrix into a variance-covariance matrix with

the function corr2cov.

Covariances = corr2cov(STDs, Correlations);

Evaluate and plot the efficient frontier at 20 points along the frontier, using the function

portopt and the expected returns and

corresponding covariance matrix. Although rather elaborate constraints can be placed on the

assets in a portfolio, for simplicity accept the default constraints and scale the total value

of the portfolio to 1 and constrain the weights to be positive (no short-selling).

Note

portopt has been partially removed and will no longer accept

ConSet or varargin arguments. Use Portfolio object instead to solve portfolio problems that are more than a

long-only fully-invested portfolio. For information on the workflow when using Portfolio

objects, see Portfolio Object Workflow. For more information

on migrating portopt code to Portfolio, see portopt Migration to Portfolio Object.

portopt(Returns, Covariances, 20)

c870fe6e0f223054f102f741f2f3169d.png

Now that the efficient frontier is displayed, randomly generate

the asset weights for 1000 portfolios starting from the MATLAB® initial

state.

rng('default')

Weights = rand(1000, 3);

The previous line of code generates three columns of uniformly

distributed random weights, but does not guarantee they sum to 1.

The following code segment normalizes the weights of each portfolio

so that the total of the three weights represent a valid portfolio.

Total = sum(Weights, 2); % Add the weights

Total = Total(:,ones(3,1)); % Make size-compatible matrix

Weights = Weights./Total; % Normalize so sum = 1

Given the 1000 random portfolios created, compute the expected

return and risk of each portfolio associated with the weights.

[PortRisk, PortReturn] = portstats(Returns, Covariances, ...

Weights);

Finally, hold the current graph, and plot the returns and risks

of each portfolio on top of the existing efficient frontier for comparison.

After plotting, annotate the graph with a title and return the graph

to default holding status (any subsequent plots will erase the existing

data). The efficient frontier appears in blue, while the 1000 random

portfolios appear as a set of red dots on or below the frontier.

hold on

plot (PortRisk, PortReturn, '.r')

title('Mean-Variance Efficient Frontier and Random Portfolios')

hold off

eb57cbdc41e04da0e96412b4d21a81a9.png

See Also

Related Topics

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值