inst/examples/mc_gbm.R

# Opt details
matur<-0.9


# Processo (div vol e tassi fissi)
disc<-discFix(-.02)


# Processo (RCPP)
miaopt<-call(mat=matur,strike=1)

# PRIMO METODO: gen construito fuori e passato a mc (forse migliore in quanto piu' flessibile)
gen<-gbmTimeVar_RCPP(to=1,mand=list(final=matur,intermed=c(0.25,0.5,0.75)), f_disc=disc,f_dvd=function(t) .0363, f_sd=function(t) .1963)
mc(N=10000, pathgen=gen, miaopt(s=final), disc(final))


miaopt_asian<-call_asian(mat=matur,strike=1)
mc(N=10000, pathgen=gen, miaopt_asian(s=all), disc(final))






# SECONDO METODO: gen costruito dentro a mc, meno flessibile per gestire payoff
mc_pi(N=10000, Pathgen=gbmTimeVar_RCPP,
                pathgenPar=list(f_disc=disc,f_dvd=function(t) .0363, f_sd=function(t) .1963),
                miaopt,list(s=final), disc(final))







# Valuta con MC una call (se disc non h argg fare in modo che usi final di call, si pua'?)
mc(N=10000, pathgen=gen, call(s=final,strike = 1.0), disc(final))
mc(N=10000, pathgen=gen, digitalCall(s=final,strike = 1.0), disc(final))
mc(N=10000, pathgen=gen, callspread(s=final,strike1 = 1.0,strike2 = 1.1), disc(final))

# Prezzo scomposto
mc(N=10000, pathgen=gen, callspread2(s=final,strike1 = 1.0,strike2 = 1.1), disc(final), nris=3)



# FARE PRICING DOVE PRENDE CON MC L'ULTIMA OBS
gen<-gbmTimeVar(to=1,mand=list(final=matur,intermed=c(0.25,0.5,0.75)), f_disc=disc,f_dvd=function(t) .0363, f_sd=function(t) .1963)





# FARE PAYOFF CON OBS INTERMEDIE.............................






#gen<-gbmTimeVar(to=1,f_disc=disc,f_dvd=function(t) .0363, f_sd=function(t) .1963)


# Prove restituzione path ai mandatory points
path<-gen()
temp<-at_mand(path, environment(gen)$grid$mand_pos)
temp$final

temp<-at_mand(environment(gen)$grid$t, environment(gen)$grid$mand_pos)

# Plot di alcuni path
MCiter<-100
y<-matrix(NA,environment(gen)$N,MCiter)
for(i in 1:MCiter){
    y[,i]<-gen()

}

plot.ts(y,plot.type = 'single', col='lightblue'); grid()





# PROCESSO CON PARAMETRI FISSI (FUNZIONE-SHORTCUT)
genFixPar<-gbmFixed(from=0,to=1,step=3,mand=list(obs=c(.01,.02),obs2=c(.02,.04)),r=-0.02,dvd=.0363,sd=.1963)
MCiter<-100
y<-matrix(NA,environment(genFixPar)$N,MCiter)
for(i in 1:MCiter){
    y[,i]<-genFixPar()

}

plot.ts(y,plot.type = 'single', col='lightblue'); grid()
lampoverde/Der documentation built on Jan. 8, 2018, 12:01 p.m.