GithubHelp home page GithubHelp logo

bradintheusa / dart_finance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ismaeljimenez/finance

0.0 1.0 0.0 307 KB

The fundamental package for financial computing with Dart.

License: Other

Dart 38.10% Kotlin 0.17% Swift 2.39% Objective-C 0.05% CMake 25.88% C++ 31.45% C 1.97%

dart_finance's Introduction

The fundamental package for financial computing with Dart.

Not in pub.dev yet. This fork works with dart 3. This package provides a set of high-level functions and classes that make it easy to compute financial ratios, patterned after spreadsheet computations. It's platform-independent, supports iOS and Android.

Using

The easiest way to use this library is via the top-level functions. They allow you to make financial calculations with minimal hassle:

Future Value calculation

What is the future value after 30 years of saving $1,000 now, with an additional monthly savings of $100. Assume the interest rate is 7% (annually) compounded monthly?

  print(Finance.fv(rate: 0.07 / 12, nper: 30 * 12, pmt: -100, pv: -1000));

Thus, saving $1,000 today and then $100 a month at 7% annual interest leads to $130,113.59 available to spend in 30 years from now.

Payments calculation

What is the monthly payment needed to pay off a $100,000 loan in 10 years at an annual interest rate of 2.5%?

  print(Finance.pmt(rate: 0.025 / 12, nper: 10 * 12, pv: 100000));

Thus, in order to pay-off (i.e., have a future-value of 0) the $100,000 obtained today, a monthly payment of $942.69 would be required. Note that this example illustrates usage of future value having a default value of $0.

Number of period calculation

If we only had $500/month to pay towards the loan, how long would it take to pay-off a loan of $100,000 at 3% annual interest?

  print(Finance.nper(rate: 0.03 / 12, pmt: -500, pv: 10000));

So, over 20 months would be required to pay off the loan.

Principal and Interest payment calculation

What is the amortization schedule for a 1 year loan of $5,000 at 10% interest per year compounded monthly? And the total interest payments?

  final Iterable<Map<String, num>> payments =
      List<int>.generate(12, (int index) => index + 1).map((int per) =>
          <String, num>{
            'per': per,
            'pmt': Finance.pmt(rate: 0.1 / 12, nper: 1 * 12, pv: 5000),
            'ppmt':
                Finance.ppmt(rate: 0.1 / 12, per: per, nper: 1 * 12, pv: 5000),
            'ipmt':
                Finance.ipmt(rate: 0.1 / 12, per: per, nper: 1 * 12, pv: 5000),
          });

  payments.forEach(print);

  final num interestPaid =
      payments.fold(0, (num p, Map<String, num> c) => p + c['ipmt']);
  print(interestPaid);

Thus, the total interest paid are close to $275.

Present Value calculation

What is the present value (e.g., the initial investment) of an investment that needs to total $20,000 after 10 years of saving $100 every month? Assume the interest rate is 7% (annually) compounded monthly.

  print(Finance.pv(rate: 0.05 / 12, nper: 10 * 12, pmt: -100, fv: 15692.93));

So, to end up with $20,000 in 10 years saving $100 a month at 7% annual interest, one's initial deposit should be $1,339.28.

Interest rate calculation

What is the interest rate for a $8,000 loan if the loan term is 5 years and and payments are $152.50 monthly?

  print(Finance.rate(nper: 60, pmt: -152.5, pv: 8000, fv: 0));

The calculated interest rate is 0.45% monthly, or 5.42% annually.

Net present value calculation

What is the Net Present Value of an investment that requires $15,000 deposit now and then makes the following withdrawals at regular (fixed) intervals: $1,500, $2,500, $3,500, $4,500, $6,000?. Assuming the ending value is $0 and a discount rate of 5%.

  print(Finance.npv(rate: 0.05, values: <num>[-15000, 1500, 2500, 3500, 4500, 6000]));

So, this investment is worth $122.894 today.

Internal Rate of Return calculation

What is the Internal Rate of return of an investment that requires $15,000 deposit now and then makes the following withdrawals at regular (fixed) intervals: $1,500, $2,500, $3,500, $4,500, $6,000?. Assuming the ending value is $0.

  print(Finance.irr(rate: 0.05, values: <num>[-15000, 1500, 2500, 3500, 4500, 6000]));

So, the IRR of this investment is 5.24%.

dart_finance's People

Contributors

bradintheusa avatar ismaeljimenez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.