Skip to content

Instantly share code, notes, and snippets.

@cmbrown1598
Created November 30, 2017 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbrown1598/c59fabe169ca988c71f5aead72fd3abf to your computer and use it in GitHub Desktop.
Save cmbrown1598/c59fabe169ca988c71f5aead72fd3abf to your computer and use it in GitHub Desktop.
type Compounding =
| TimesPerYear of float
| Constant
type InterestCalculationOptions = {
Compounding : Compounding
Rate : float
Principal : float
TermInYears : float
}
let compound options =
let core r e =
options.Principal * (r ** e)
match options.Compounding with
| Constant -> core System.Math.E (options.Rate * options.TermInYears)
| TimesPerYear f -> let rate = options.Rate / f
core (1.0 + rate) (f * options.TermInYears)
let fry = compound { Compounding = TimesPerYear 1.0
Rate = 0.0225
Principal = 0.93
TermInYears = 1000.0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment