kaesler / scala-finance

Financial functions in Scala (e.g. XIRR, XNPV)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Financial Functions

This is a library of commonly used financial function implementation in Scala.

Usage

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 FinancialFunctionsin 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+0000
  • DateRep(date: Date) - From java.util.Date
  • DateRep(string: String) - From date string (Uses DateTime.parse internally)

Implemented methods

XIRR

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))
Reference

Microsoft Support - XIRR

XNPV

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)
Reference

Microsoft Support - XNPV

About

Financial functions in Scala (e.g. XIRR, XNPV)

License:Apache License 2.0


Languages

Language:Scala 100.0%