FinancialSharp 1.0.1

dotnet add package FinancialSharp --version 1.0.1                
NuGet\Install-Package FinancialSharp -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FinancialSharp" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FinancialSharp --version 1.0.1                
#r "nuget: FinancialSharp, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FinancialSharp as a Cake Addin
#addin nuget:?package=FinancialSharp&version=1.0.1

// Install FinancialSharp as a Cake Tool
#tool nuget:?package=FinancialSharp&version=1.0.1                

FinancialSharp

Build status NuGet

Simple and zero-dependency library, written entirely in F#, inspired by numpy-financial and financial.

The library contains a collection of elementary financial functions.

Functions

  • fv(): compute the future value
  • pmt(): compute the payment against loan principal plus interest
  • nper(): compute the number of periodic payments
  • ipmt(): compute the interest portion of a payment
  • ppmt(): compute the payment against loan principal
  • pv(): compute the present value
  • rate(): compute the rate of interest per period
  • irr(): compute the internal rate of return
  • npv(): compute the net present value of a cash flow series
  • mirr(): compute the modified internal rate of return

Add package

If you want to add this package to your project, execute the following command:

dotnet add package FinancialSharp --version 1.0.0

Build on your machine

If you want to build this library on your machine, execute the following commands:

git clone https://github.com/galassie/financial-sharp.git
cd financial-sharp
dotnet build

If you want to run the tests, execute the following command:

dotnet test

Build in Docker

Required:

  • Install Docker for your system

Build a Docker image called financial-sharp. This will work without any local .NET Core installation.

docker build -t financial-sharp .

Use the following to instantiate a Docker container from the financial-sharp image and run the tests inside:

docker run --rm financial-sharp dotnet test

Usage

You can see the some examples in the folder "samples" (both in F# and C#).

Here how it looks a simple F# program that uses this library:

open FinancialSharp

[<EntryPoint>]
let main argv  =
    printfn "FinancialSharp!\n"

    Financial.Nper(0.075, -2000.0, 0.0, 100000.0, PaymentDuePeriod.Begin)
    |> printfn "Number of periodic payments: %f"

    Financial.Fv(0.075, 20.0, -2000.0, 0.0, PaymentDuePeriod.End)
    |> printfn "Future value: %f"

    Financial.Npv(0.05, [|-15000.0; 1500.0; 2500.0; 3500.0; 4500.0; 6000.0|])
    |> printfn "Net present value of a cash flow series: %f"

    Financial.Pv(0.0, 20.0, 12000.0, 0.0)
    |> printfn "Present value: %f"
    0

This program will output the following text:

This is a series of examples on how to use FinancialSharp!

Number of periodic payments: 20.761564
Future value: 86609.362673
Net present value of a cash flow series: 122.894855
Present value: -240000.000000

With F# 5.0, it is possible to use Open Type Declarations for a more concise usage. For example:

open type FinancialSharp.Financial
open type FinancialSharp.PaymentDuePeriod

[<EntryPoint>]
let main argv  =
    printfn "FinancialSharp with Open Type declarations!\n"
    
    Nper(0.075, -2000.0, 0.0, 100000.0, Begin)
    |> printfn "Number of periodic payments: %f"

    Fv(0.075, 20.0, -2000.0, 0.0, End)
    |> printfn "Future value: %f"

    Npv(0.05, [|-15000.0; 1500.0; 2500.0; 3500.0; 4500.0; 6000.0|])
    |> printfn "Net present value of a cash flow series: %f"

    Pv(0.0, 20.0, 12000.0, 0.0)
    |> printfn "Present value: %f"
    0

It is possible to use this library also in a C# project:

using System;

namespace FinancialSharp.CSharp.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var nper = Financial.Nper(0.075, -2000.0, 0.0, 100000.0, PaymentDuePeriod.Begin);
            Console.WriteLine($"Number of periodic payments: {nper}");

            var fv = Financial.Fv(0.075, 20.0, -2000.0, 0.0, PaymentDuePeriod.End);
            Console.WriteLine($"Future value: {fv}");

            var npv = Financial.Npv(0.05, new[] { -15000.0, 1500.0, 2500.0, 3500.0, 4500.0, 6000.0 });
            Console.WriteLine($"Net present value of a cash flow series: {npv}");

            var pv = Financial.Pv(0.0, 20.0, 12000.0, 0.0);
            Console.WriteLine($"Present value: {pv}");
        }
    }
}

Contributing

Code contributions are more than welcome! 😻

Please commit any pull requests against the master branch.
If you find any issue, please report it!

License

This project is licensed under The MIT License (MIT).

Author: Enrico Galassi

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 849 11/23/2022
1.0.0 498 3/10/2022
1.0.0-beta002 268 3/19/2021
1.0.0-beta001 241 3/14/2021