Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. St<-20
  2. K<-21
  3. t<-0.25
  4. r<-0.01
  5. sigma<-0.2
  6.  
  7. ## First we use the Black-Scholes Formula
  8.  
  9. d1<-(log(St/K) + (r+(sigma^2)/2)*t)/(sigma*sqrt(t))
  10.  
  11. d2<-d1-sigma*sqrt(t)
  12.  
  13. V<-pnorm(d1)*St - K*exp(-r*t)*pnorm(d2)
  14.  
  15. V
  16.  
  17. n<-2000
  18. ## Now we use a Monte Carlo approach
  19. set.seed(27)
  20.  
  21. norms<-rnorm(n,0,1)
  22. s = St*exp((r-(sigma^2)/2)*t+sigma*sqrt(t)*norms)
  23.  
  24. V2<-mean(exp(-r*t)*pmax(s-K,0))
  25.  
  26. V2
  27.  
  28. all.equal(V, V2, tolerance=0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement