样本矩估计
用于估计投资组合矩的默认方法是样本法。optimize.portfolio() 会调用传入 momentFUN 参数的函数来计算矩。momentFUN 的默认值是 set.portfolio.moments(),其默认计算样本矩。随后,这些矩将作为目标函数的输入。需要估计哪些矩取决于目标。例如,最小化投资组合标准差的目标只需要第二阶矩的估计。相比之下,最大化夏普比率的目标需要估计第一阶矩和第二阶矩。样本矩估计也有缺点,包括估计误差和维度灾难。随着资产维度和待估参数数量增加,估计误差的风险也会提高。
本练习是课程的一部分
R 中级投资组合分析
练习说明
- 添加一个收益目标,目标名称为
"mean"。 - 使用
set.portfolio.moments计算样本矩。将结果赋给名为moments的变量。 - 检查第一阶矩是否等于平均收益的样本估计值。
- 添加一个风险目标,目标名称为
"StdDev"。 - 使用
set.portfolio.moments计算样本矩。将结果赋给名为moments的变量。 - 检查第二阶矩是否等于方差-协方差矩阵的样本估计值。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Add a return objective with "mean" as the objective name
port_spec <- add.objective(portfolio = port_spec, type = ___, name = ___)
# Calculate the sample moments
moments <- set.portfolio.moments(R = ___, portfolio = ___)
# Check if moments$mu is equal to the sample estimate of mean returns
moments$mu == colMeans(asset_returns)
# Add a risk objective with "StdDev" as the objective name
port_spec <- add.objective(portfolio = port_spec, type = ___, name = ___)
# Calculate the sample moments using set.portfolio.moments. Assign to a variable named moments.
moments <- set.portfolio.moments(R = ___, portfolio = ___)
# Check if moments$sigma is equal to the sample estimate of the variance-covariance matrix
moments$sigma == cov(asset_returns)