开始使用免费开始使用

定义投资组合优化问题

我们将定义一个投资组合优化问题:在满足全额投资和仅做多约束的前提下,最小化投资组合的标准差。本题将基于该问题设置投资组合规范。后续练习将以这里建立的初始投资组合规范为基础逐步展开。

本练习是课程的一部分

R 中级投资组合分析

查看课程

练习说明

  • 使用 asset_returns 数据集中的资产创建一个投资组合规范对象,并将其命名为 port_spec
  • port_spec 对象添加全额投资约束,使权重之和等于 1。
  • port_spec 对象添加仅做多约束,使单个资产权重介于 0 到 1 之间。
  • port_spec 对象添加一个目标,使投资组合标准差最小化。
  • 打印该投资组合规范对象。

交互式实操练习

通过完成这段示例代码来试试这个练习。


# Create the portfolio specification


# Add a full investment constraint such that the weights sum to 1


# Add a long only constraint such that the weight of an asset is between 0 and 1


# Add an objective to minimize portfolio standard deviation


# Print the portfolio specification
编辑并运行代码