我想为我的硕士论文编写代码,但是为此,我需要使用多级alpha。如何为多级alpha调整以下代码?我的意思是代替alpha = 0.05,我需要alphas = c(0.01,0.05,0.1)。请帮助我,这对我的论文真的很重要。
风险=函数(密度,alpha,方法){ #以密度估算n个交易日的alpha风险价值和预期短缺 #densities =具有n个交易日(行)的经验分布(列)的矩阵
output = matrix(data = vector(length = length(densities[1,]) * 2) , nrow = length(densities[1,]), ncol = 2)
colnames(output) = c("VaR","ES")
len = length(densities[,1])
if(method == "FHS"){
i = (1 - alpha * 2) * len
output[,1] = sqrt(densities[i,])
output[,2] = apply(sqrt(densities[i:len,]), 2, mean)
}
else{
i = alpha * len
output[,1] = -densities[i,]
output[,2] = apply(-densities[1:i,] , 2, mean)
}
return (output)
}