Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null-safety upgrade #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main(List<String> arguments) {

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

// What is the present value (e.g., the initial investment) of an investment that
Expand Down
66 changes: 33 additions & 33 deletions lib/finance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class Finance {
/// http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
/// OpenDocument-formula-20090508.odt
static num fv(
{@required num rate,
@required num nper,
@required num pmt,
@required num pv,
{required num rate,
required num nper,
required num pmt,
required num pv,
bool end = true}) {
final int when = end ? 0 : 1;
final num temp = pow(1 + rate, nper);
Expand Down Expand Up @@ -98,9 +98,9 @@ class Finance {
/// http://www.oasis-open.org/committees/documents.php
/// ?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt
static num pmt(
{@required num rate,
@required num nper,
@required num pv,
{required num rate,
required num nper,
required num pv,
num fv = 0,
bool end = true}) {
final int when = end ? 0 : 1;
Expand Down Expand Up @@ -135,9 +135,9 @@ class Finance {
/// but if ``rate = 0`` then::
/// fv + pv + pmt*nper = 0
static num nper(
{@required num rate,
@required num pmt,
@required num pv,
{required num rate,
required num pmt,
required num pv,
num fv = 0,
bool end = true}) {
final int when = end ? 0 : 1;
Expand Down Expand Up @@ -171,10 +171,10 @@ class Finance {
/// of each period. (default=true).
///
static num ipmt(
{@required num rate,
@required num per,
@required num nper,
@required num pv,
{required num rate,
required num per,
required num nper,
required num pv,
num fv = 0,
bool end = true}) {
final num totalPmt = pmt(rate: rate, nper: nper, pv: pv, fv: fv, end: end);
Expand All @@ -189,10 +189,10 @@ class Finance {
// function to not interfere with the 'fv' keyword argument within the 'ipmt'
// function. It is the 'remaining balance on loan'.
static num _rbl(
{@required num rate,
@required num per,
@required num pmt,
@required num pv,
{required num rate,
required num per,
required num pmt,
required num pv,
bool end = true}) {
return fv(rate: rate, nper: per - 1, pmt: pmt, pv: pv, end: end);
}
Expand All @@ -216,10 +216,10 @@ class Finance {
/// of each period. (default=true).
///
static num ppmt(
{@required num rate,
@required num per,
@required num nper,
@required num pv,
{required num rate,
required num per,
required num nper,
required num pv,
num fv = 0,
bool end = true}) {
final num total = pmt(rate: rate, nper: nper, pv: pv, fv: fv, end: end);
Expand Down Expand Up @@ -263,10 +263,10 @@ class Finance {
/// http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
/// OpenDocument-formula-20090508.odt
static num pv(
{@required num rate,
@required num nper,
@required num pmt,
@required num fv,
{required num rate,
required num nper,
required num pmt,
required num fv,
bool end = true}) {
final int when = end ? 0 : 1;
final num temp = pow(1 + rate, nper);
Expand Down Expand Up @@ -336,10 +336,10 @@ class Finance {
/// http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
/// OpenDocument-formula-20090508.odt
static num rate(
{@required num nper,
@required num pmt,
@required num pv,
@required num fv,
{required num nper,
required num pmt,
required num pv,
required num fv,
bool end = true,
num guess = 0.1,
num tol = 1e-6,
Expand Down Expand Up @@ -380,13 +380,13 @@ class Finance {
/// ----------
/// .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
/// Addison-Wesley, 2003, pg. 346.
static num npv({@required num rate, @required List<num> values}) {
static num npv({required num rate, required List<num> values}) {
return List<int>.generate(values.length, (int index) => index)
.map((int index) => values[index] / pow(1 + rate, index))
.fold(0, (num p, num c) => p + c);
}

static num _npvPrime({@required num rate, @required List<num> values}) {
static num _npvPrime({required num rate, required List<num> values}) {
return List<int>.generate(values.length, (int index) => index)
.map((int index) => -index * values[index] / pow(1 + rate, index + 1))
.fold(0, (num p, num c) => p + c);
Expand Down Expand Up @@ -427,7 +427,7 @@ class Finance {
/// g'(r) is the derivative with respect to r.

static num irr(
{@required List<num> values,
{required List<num> values,
num guess = 0.1,
num tol = 1e-6,
num maxIter = 100}) {
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: finance
description: The fundamental package for financial computing with Dart.
version: 0.1.0
version: 0.2.0
author: "Ismael Jiménez <[email protected]>"
homepage: https://github.com/ismaelJimenez/finance

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
meta: ^1.1.7
meta: ^1.8.0

dev_dependencies:
test: '>=1.3.0 <1.6.8'
mockito: ^4.1.0
pedantic: ^1.8.0+1
test: ^1.23.1
mockito: ^5.3.2
pedantic: ^1.11.1