Created
December 12, 2013 17:56
-
-
Save OdeToCode/7932390 to your computer and use it in GitHub Desktop.
This file contains 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
let PeriodValue payment rate period = | |
payment / ((1.0 + rate) ** period) | |
let PresentValue (factors: AnnuityFactors) = | |
[1 .. factors.Periods] | |
|> List.map (fun period -> PeriodValue factors.Payment factors.InterestRate (float period)) | |
|> List.sum |
You can also make this lazy, though that would only make a difference for large values of Periods
:
let PresentValue (factors: AnnuityFactors) =
seq { 1 .. factors.Periods }
|> Seq.map (float >> PeriodValue factors.Payment factors.InterestRate)
|> Seq.sum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More idiomatic than the lambda would be function composition and partial application:
Also, functions are generally camelCased.