Created
December 6, 2017 18:35
-
-
Save WilsonMongwe/23b21bf00ba84f9526d2eaeb59dce0fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DEoptim) | |
# Parameters | |
mu_= 0.05 | |
ss_= 0.3 | |
lambda_= 25 | |
mu2_=0.01 | |
sigma_=0.1 | |
TotalTime = 50 | |
delta=1/252 | |
simulationSize = 100 | |
# Store the results | |
par = matrix(0,simulationSize,5) | |
lower = c(-100,0.00001,0.00001,-100,0.001) #lower bounds of the search | |
upper = c(100,100,100,100,100) #upper bounds of the search | |
for(i in 1:simulationSize) | |
{ | |
print(paste("Simulation Number :",i)) | |
#Simulate the path | |
set.seed( as.integer((as.double(Sys.time())*1000+Sys.getpid()) %% 2^31) ) | |
x = diff(simulateJump(mu_,ss_,lambda_,mu2_,sigma_,TotalTime,delta)[,2]) | |
#Using the default settings for DEoptim | |
set.seed(1234) | |
outDEoptim = DEoptim(nll_jumps, lower = lower,upper = upper) | |
#Store the parameters | |
par[i,] = outDEoptim$optim$bestmem | |
} | |
# Convergence plot | |
plot(outDEoptim, plot.type = "bestvalit", type = 'b') | |
mean(par[,1]) | |
mean(par[,2]) | |
mean(par[,3]) | |
mean(par[,4]) | |
mean(par[,5]) | |
sd(par[,1]) | |
sd(par[,2]) | |
sd(par[,3]) | |
sd(par[,4]) | |
sd(par[,5]) | |
hist(par[,1], | |
main="Histogram for the drift", | |
xlab=expression(mu), | |
border="blue", | |
xlim=c(-0.2,0.2), | |
las=1, | |
breaks=10,prob=TRUE) | |
abline(v=0.05,col="red") | |
lines(density(par[,1]),col="black") | |
legend("topright", legend=c("True value"), | |
col=c("red"), lty=1:2, cex=0.8) | |
hist(par[,2], | |
main="Histogram for the diffusive vol", | |
xlab=expression(sigma), | |
border="blue", | |
xlim=c(0.29,0.31), | |
las=1, | |
breaks=8,prob=TRUE) | |
abline(v=0.3,col="red") | |
lines(density(par[,2]),col="black") | |
legend("topright", legend=c("True value"), | |
col=c("red"), lty=1:2, cex=0.8) | |
hist(par[,3], | |
main="Histogram for the jump intensity", | |
xlab=expression(lambda), | |
border="blue", | |
xlim=c(21,28), | |
las=1, | |
breaks=10,prob=TRUE) | |
abline(v=25,col="red") | |
lines(density(par[,3]),col="black") | |
legend("topright", legend=c("True value"), | |
col=c("red"), lty=1:2, cex=0.8) | |
hist(par[,4], | |
main="Histogram for the mean jump size", | |
xlab= "mean jump size", | |
border="blue", | |
xlim=c(0.001,0.02), | |
breaks=10,prob=TRUE) | |
abline(v=0.01,col="red") | |
lines(density(par[,4]),col="black") | |
legend("topright", legend=c("True value"), | |
col=c("red"), lty=1:2, cex=0.8) | |
hist(par[,5], | |
main="Histogram for the jump size standard deviation", | |
xlab="jump size standard deviation", | |
border="blue", | |
xlim=c(0.085,0.11), | |
las=1, | |
breaks=10,prob=TRUE) | |
abline(v=0.1,col="red") | |
lines(density(par[,5]),col="black") | |
legend("topright", legend=c("True value"), | |
col=c("red"), lty=1:2, cex=0.8) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment