library(MASS)
x = SP500/100
fit=spdfit(x, upper=0.9, lower=0.1)
## rspd -
par(mfrow = c(2, 2), cex = 0.7)
r = rspd(n = 1000, fit)
hist(r, n = 100, probability = TRUE, xlab = "r",
col = "steelblue", border = "white",main = "Density")
box()
## dspd -
# Plot empirical density and compare with true density:
r = rspd(n = 1000, fit)
hist(r, n = 100, probability = TRUE, xlab = "r",
col = "steelblue", border = "white",main = "Density")
box()
x = seq(-0.3, 0.3, length.out = 1000)
lines(x, dspd(x, fit), col = "darkorange",lwd=2)
## pspd -
# Plot df and compare with true df:
plot(sort(r), (1:length(r)/length(r)),
ylim = c(0, 1), pch = 19,
cex = 0.5, ylab = "p", xlab = "q", main = "CDF")
grid()
q = seq(-0.3, 0.3, length.out = 1000)
lines(q, pspd(q, fit), col = "darkorange",lwd=2)
Run the code above in your browser using DataLab