Hi there, I'm writing a thesis in econometrics. I'm analyzing financial timeseries and I'm forecasting Value at Risk-estimates with GARCH-models.
Now, I don't consider myself as a newbie in R, but this problem is really bothering me. I've tried to look around in the forum, because I know this has been asked about before.
My problem is, that I get the following error:
#Initializing env_sp500 <- new.env() getSymbols("^GSPC", env = env_sp500 , src = "yahoo", from = as.Date("2016-01-01"), to = as.Date("2020-01-01"), warnings = FALSE) sp500_close <- sp500$GSPC.Close sp500_returns <- Return.calculate(sp500_close, method = "discrete") #GARCH specification model.spec = ugarchspec(variance.model = list(model = 'sGARCH', garchOrder = c(1,1)), mean.model = list(armaOrder = c(0,0))) model.fit = ugarchfit(spec = model.spec, data = sp500_returns, solver = 'solnp') #Forecasting model.roll = ugarchroll(spec = model.spec, data = sp500_returns, n.start = 500, refit.every = 50, refit.window = 'moving') fitdist(distribution = 'norm', x = sp500_returns) Var95_norm <- mean(sp500_returns) + model.roll@forecast$density[,'Sigma']*qdist(distribution = 'norm', p = 0.05) ptest <- (qplot(y = Var95_norm, x = 1:500, geom = 'line') + geom_point(aes(x = 1:500, y = sp500_returns[507:1006], color = as.factor(sp500_returns[507:1006] < Var95_norm))) + scale_color_manual(values = c('gray', 'red')) + labs(y = 'Returns', x = 'Test Observations') + ggtitle('Backtesting') + theme(plot.title = element_text(hjust = 0.5))) Error: Fejl: Aesthetics must be either length 1 or the same as the data (506): x
I have absolutely no clue how to fix this issue, not even by trying the fixes from before with this issue... Thanks in advance.