From 72e4230a7dc6622293cc22292183b0d22b819fc8 Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Fri, 29 Mar 2024 22:36:25 +0530 Subject: [PATCH] Fix IRR Calculator logic --- lib/domain/models/irr_calculator.dart | 12 ++++++------ web/index.html | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/domain/models/irr_calculator.dart b/lib/domain/models/irr_calculator.dart index caddd62..cad7137 100644 --- a/lib/domain/models/irr_calculator.dart +++ b/lib/domain/models/irr_calculator.dart @@ -105,15 +105,15 @@ class IRRCalculator { required final double currentValue, required final DateTime currentValueUpdatedOn, }) { - final double years = currentValueUpdatedOn - .difference(futureDate) - .inDays / 365; - final num irrFactor = pow(1 + irr / 100, years.abs()); - + double years = currentValueUpdatedOn.difference(futureDate).inDays / 365; if (years == 0) { return currentValue; + } else if (years < 1 && years > 0) { + return currentValue / pow(1 + irr / 100, 1); + } else if (years > -1 && years < 0) { + return currentValue / pow(1 + irr / 100, -1); } else { - return currentValue / irrFactor; + return currentValue / pow(1 + irr / 100, years); } } } \ No newline at end of file diff --git a/web/index.html b/web/index.html index 5a5d519..c429d5f 100644 --- a/web/index.html +++ b/web/index.html @@ -1,5 +1,5 @@ - +