Created
May 28, 2015 18:16
-
-
Save glaucocustodio/58f86d7e5f184f7b6f2c to your computer and use it in GitHub Desktop.
Excel PMT Formula in Swift
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
class ExcelFormulas { | |
class func pmt(rate : Double, nper : Double, pv : Double, fv : Double = 0, type : Double = 0) -> Double { | |
return ((-pv * pvif(rate, nper: nper) - fv) / ((1.0 + rate * type) * fvifa(rate, nper: nper))) | |
} | |
class func pow1pm1(x : Double, y : Double) -> Double { | |
return (x <= -1) ? pow((1 + x), y) - 1 : exp(y * log(1.0 + x)) - 1 | |
} | |
class func pow1p(x : Double, y : Double) -> Double { | |
return (abs(x) > 0.5) ? pow((1 + x), y) : exp(y * log(1.0 + x)) | |
} | |
class func pvif(rate : Double, nper : Double) -> Double { | |
return pow1p(rate, y: nper) | |
} | |
class func fvifa(rate : Double, nper : Double) -> Double { | |
return (rate == 0) ? nper : pow1pm1(rate, y: nper) / rate | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for code!