【发布时间】:2017-05-03 23:41:58
【问题描述】:
我已经为我所在的课程启动了一个项目,当我尝试显示我想要的特定统计信息时,我遇到了错误。我正在使用 R 编程语言对 R Studio 中的统计数据进行编码。这是我的代码:
boot = do(20)*
{
horizon = 20
totalwealth = 10000
pweights = c(0.5, 0, 0, 0, 0.5)
holdings = pweights * totalwealth
wealthtracker = rep(0, horizon) # Set up a placeholder to track total wealth
for(today in 1:horizon) {
return.today = resample(myreturns, 1, orig.ids=FALSE)
holdings = holdings*(1+return.today)
totalwealth = sum(holdings)
wealthtracker[today] = totalwealth
}
VaR = unname(quantile(wealthtracker, p=0.05))
VaR
}
hist(boot$VaR)
当我尝试从样本统计数据(在本例中为 VaR)获取数据或构建直方图时,会发生我遇到的错误。
每当我输入“boot$”时,接下来出现的应该是“VaR”和我的自举模型中的其他统计信息,但唯一显示的是“结果”。当我在引导程序 (bootstrap$VaR) 的上下文中输入命令以返回任何带有 VaR 的内容时,我返回此错误 - 'x' 必须是数字。这里的问题是我已经通过应用 unname 函数确保“x”是数字。非常感谢这里的任何帮助。
谢谢。
【问题讨论】:
-
你使用什么包?像
myreturns这样的变量是如何定义的?如果您向reproducible example 提供示例输入数据,则最容易提供帮助。
标签: r statistics montecarlo statistics-bootstrap