# 使用R语言构造投资组合

# 载入 quatnmod 包require(quantmod) # 下载 QQQ/SPY/YHOO 交易数据getSymbols(c('QQQ','SPY','YHOO'))

# 计算收益率序列QQQ_ret=dailyReturn(QQQ)  SPY_ret=dailyReturn(SPY)YHOO_ret=dailyReturn(YHOO)

dat=merge(QQQ_ret,SPY_ret,YHOO_ret)

## 转化为 timeSeries 类require(timeSeries)dat=as.timeSeries(dat)  ## 载入 fPortfoliorequire(fPortfolio)## 求frontier Frontier = portfolioFrontier(dat)Frontier

Title:
MV Portfolio Frontier
Estimator:         covEstimator
Solver:            solveRquadprog
Optimize:          minRisk
Constraints:       LongOnly
Portfolio Points:  5 of 50 Portfolio Weights:
daily.returns daily.returns.1 daily.returns.21         0.0000          1.0000          0.000013        0.2409          0.7541          0.005025        0.4853          0.5090          0.005737        0.7296          0.2640          0.006550        1.0000          0.0000          0.0000Covariance Risk Budgets:
daily.returns daily.returns.1 daily.returns.21         0.0000          1.0000          0.000013        0.2355          0.7596          0.004925        0.4877          0.5065          0.005837        0.7390          0.2545          0.006550        1.0000          0.0000          0.0000Target Return and Risks:
mean     mu    Cov  Sigma   CVaR    VaR1  0.0002 0.0002 0.0151 0.0151 0.0368 0.023313 0.0003 0.0003 0.0149 0.0149 0.0361 0.023025 0.0003 0.0003 0.0148 0.0148 0.0358 0.023437 0.0004 0.0004 0.0149 0.0149 0.0356 0.024150 0.0005 0.0005 0.0152 0.0152 0.0357 0.0249Description:
Fri Aug 09 11:21:31 2013 by user: Owner 

plot(Frontier)Make a plot selection (or 0 to exit):

1:   Plot Efficient Frontier
2:   Add Minimum Risk Portfolio
3:   Add Tangency Portfolio
4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]

Selection: 1Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 2Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 3Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 4Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 5Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 6Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 7Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]
Selection: 8Make a plot selection (or 0 to exit): 1:   Plot Efficient Frontier2:   Add Minimum Risk Portfolio3:   Add Tangency Portfolio4:   Add Risk/Return of Single Assets5:   Add Equal Weights Portfolio6:   Add Two Asset Frontiers [LongOnly Only]7:   Add Monte Carlo Portfolios8:   Add Sharpe Ratio [Markowitz PF Only]

822 篇文章214 人订阅

0 条评论

## 相关文章

2159

3196

1303

### Java每日一练（2017/6/3）

Java基础 | 数据库 | Android | 学习视频 | 学习资料下载 课前导读 ●回复"每日一练"获取以前的题目！ ●答案公布时间：为每期发布题目的第二...

2836

### 从MapX到MapXtreme2004[4]-标注AutoLabel

好日子一去不复返了，原来总觉得Mapx很多地方设计得不是很自然，比如，feature和具体的feature之间的某些属性的关系，有时令人迷惑。但...

2148

### Q122 Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on...

3535

2102

### carla无人驾驶模拟中文项目 carla_simulator_Chinese

https://github.com/xfqbuaa/carla_simulator_Chinese

1333

4658

### BZOJ1061: [Noi2008]志愿者招募(线性规划)

申奥成功后，布布经过不懈努力，终于成为奥组委下属公司人力资源部门的主管。布布刚上任就遇到了一个难

1504