Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Call option formula for Geometric Laplace distributed stock
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
# Call option formula for Laplace distributed outcomes call <- function(r,S0,vol,K) { b<-vol/sqrt(2) d<-(log(S0/K)+r+log(1-b^2))/b if (d>0) { return(S0-K*exp(-r)+(b/(2*(1+b)))*K*exp(-r-d)) } else { return((b/(2*(1-b)))*K*exp(-r+d)) } } range<-0.5+1.5*ppoints(100) range2<-ppoints(12)/4 x<-c() for (vol in range2) { y<-c() for (k in range) { y<-c(y,call(0,1,vol,k))} x<-rbind(x,y) } matplot(range,t(x),type='l',xlab='Strikes',main='Call option prices for GLM') # Call option price through Monte Carlo for Laplace distributed outcomes call2 <- function(r,S0,vol,K,nsim) { b<-vol/sqrt(2) U<-runif(nsim)-0.5 L<--sign(U)*log(1-2*abs(U)) S<-S0*exp(r+log(1-b^2)+b*L) return(mean(exp(-r)*pmax(S-K,0))) } z<-c() for (vol in range2) { y<-c() for (k in range) { y<-c(y,call2(0,1,vol,k,10000))} z<-rbind(z,y) } matplot(range,t(z),type='l',xlab='Strikes',main='Call option prices (Monte Carlo)')
[
+
]
Show input
Absolute running time: 5.86 sec, cpu time: 9.4 sec, memory peak: 36 Mb, absolute service time: 5,89 sec
edit mode
|
history
|
discussion