Skip to content

praphull-purohit/scala-finance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages