Skip to content

Commit

Permalink
Fix Investment future value calculation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Mar 30, 2024
1 parent cd1705f commit edbdd90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/domain/models/investment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ class Investment {
? maturityDate
: date;

final payments = getPayments(
till: futureDate, considerFuturePayments: considerFuturePayments);

final value = this.value;
final irr = this.irr;
if (value != null) {
final payments = getPayments(till: DateTime.now());
final irr = IRRCalculator().calculateIRR(
payments: payments, value: value, valueUpdatedOn: DateTime.now());
return IRRCalculator().calculateValueOnIRR(
Expand All @@ -79,6 +77,8 @@ class Investment {
currentValue: value,
currentValueUpdatedOn: DateTime.now());
} else if (irr != null) {
final payments = getPayments(
till: futureDate, considerFuturePayments: considerFuturePayments);
return IRRCalculator().calculateFutureValueOnIRR(
payments: payments, irr: irr, futureDate: futureDate);
} else {
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,27 @@ class _DashboardPage
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text('Progress:', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: AppDimen.minPadding),
_buildInvestmentProgress(
investedAmount: snapshot.invested,
valueOfInvestment: snapshot.currentValue,
irr: snapshot.overallIRR),
const SizedBox(height: AppDimen.defaultPadding),
Text('Basket Composition:',
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: AppDimen.minPadding),
_buildBarChart(snapshot.basketComposition.entries.toList()),
const SizedBox(height: AppDimen.defaultPadding),
Text('Risk Composition:',
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: AppDimen.minPadding),
_buildPieChart(snapshot.riskComposition),
const SizedBox(height: AppDimen.minPadding),
Text('IRR Composition:',
const SizedBox(height: AppDimen.defaultPadding),
Text('Basket IRR:',
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: AppDimen.minPadding),
_buildIrrContribution(data: snapshot.basketIrr.entries.toList()),
const SizedBox(height: AppDimen.minPadding),
const SizedBox(height: AppDimen.defaultPadding),
Text('Investment Over Time:',
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: AppDimen.minPadding),
Expand Down Expand Up @@ -178,7 +181,7 @@ class _DashboardPage
return SfCartesianChart(
primaryXAxis: const CategoryAxis(),
series: [
ColumnSeries(
BarSeries(
dataSource: contribution,
xValueMapper: (data, _) => data.key,
yValueMapper: (data, _) => data.value,
Expand Down

0 comments on commit edbdd90

Please sign in to comment.