Skip to content

Instantly share code, notes, and snippets.

@OdeToCode
Created December 12, 2013 17:56
Show Gist options
  • Select an option

  • Save OdeToCode/7932390 to your computer and use it in GitHub Desktop.

Select an option

Save OdeToCode/7932390 to your computer and use it in GitHub Desktop.
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
@dahlbyk

dahlbyk commented Dec 12, 2013

Copy link
Copy Markdown

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