Last active
December 17, 2015 11:59
-
-
Save Vijesh2/5605955 to your computer and use it in GitHub Desktop.
Suggest change to GBM example on p37 of F# Deep Dive. In particular, wondered whether parantheses and indentation of lines 17 to 20 need to be amended from book version to those shown on this gist.
This file contains hidden or 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
| #r "../../../packages/MathNet.Numerics.2.5.0/lib/net40/MathNet.Numerics.dll" | |
| #r "../../../packages/MathNet.Numerics.FSharp.2.5.0/lib/net40/MathNet.Numerics.FSharp.dll" | |
| open MathNet.Numerics.Random | |
| open MathNet.Numerics.Distributions | |
| open MathNet.Numerics.Statistics | |
| let get_dW rnd dt N = | |
| let dW = Normal.WithMeanVariance(0.0, dt) | |
| dW.RandomSource <- rnd | |
| (fun () -> Array.init N (fun _ -> dW.Sample())) | |
| let generate_GBM_paths_by_log rnd S0 r sigma T N M = | |
| let dt = T / (float N) | |
| let drift = (r - 0.5 * (sigma**2.0)) * dt | |
| let generator = get_dW rnd dt N | |
| Array.init M (fun _ -> (generator() | |
| |> Array.map (fun dWt -> drift + sigma * dWt) | |
| |> Array.scan (+) 0.0 | |
| |> Array.map (fun x -> S0 * exp(x)) ) ) | |
| generate_GBM_paths_by_log (Random.mersenneTwister()) 100.0 0.06 0.2 0.25 100 3 |
This file contains hidden or 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
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>suugested changes to geometric brownian motion sample from F# Deep Dives</title> | |
| </head> | |
| <body> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment