This is a library of commonly used financial function implementation in Scala.
Include the following dependency in build.sbt
"com.praphull" %% "scala-finance" % "0.0.1"
The library cross compiles to Scala 2.11, 2.12 and 2.13. Use sbt +test
to run the tests.
The functions can be accessed in various manners:
- By importing package
com.praphull.finance
(see XIRR for example) - By extending the trait
FinancialFunctions
in your own class/function library (see XNPV for example)
To work with dates, a helper representation DateRep
is provided, which can be constructed in the following manners:
DateRep(year: Int, month: Int, date: Int)
DateRep(date: DateTime)
- From org.joda.time.DateTime (Joda Time)DateRep(date: Long)
- milliseconds since 1970-01-01T00:00:00 UTC+0000DateRep(date: Date)
- From java.util.DateDateRep(string: String)
- From date string (Uses DateTime.parse internally)
Usage:
import com.praphull.finance.{DateRep, _}
xirr(List(
DateRep(2008, 1, 1) -> -10000,
DateRep(2008, 10, 30) -> 4250,
DateRep(2008, 3, 1) -> 2750,
DateRep(2009, 4, 1) -> 2750,
DateRep(2009, 2, 15) -> 3250
), Some(0.05))
Microsoft Support - XIRR
Usage:
import com.praphull.finance.{DateRep, FinancialFunctions}
object MyLibrary extends FinancialFunctions {
def myOwnFunction = ???
}
MyLibrary.xnpv(List(
DateRep(2008, 1, 1) -> -10000,
DateRep(2008, 10, 30) -> 4250,
DateRep(2008, 3, 1) -> 2750,
DateRep(2009, 4, 1) -> 2750,
DateRep(2009, 2, 15) -> 3250
), 0.45)
Microsoft Support - XNPV