Skip to content

Instantly share code, notes, and snippets.

@javouhey
Created February 20, 2014 18:35
Show Gist options
  • Save javouhey/9120284 to your computer and use it in GitHub Desktop.
Save javouhey/9120284 to your computer and use it in GitHub Desktop.
module CallPrice
function callprice(S0, K, r, T, sigma, paths)
Csum = 0.0
for j = 1:paths
Zs = randn()
Zj = T*(r-sigma.^2/2) + Zs*T.^0.5*sigma
STj = exp(Zj)*S0
Csum += exp(-r*T)*max(STj - K,0.0)
end
return Csum/paths
end
function timecallprice(n)
price = @parallel (+) for i = 1:n
callprice(100.0,100.0,0.1,1.0,0.1,1000000)
end
println("Call price: ", price/n)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment