Browse Source

Merge 95ab429f08 into 2b2ff0b883

pull/7069/merge
VJSai 2 days ago
committed by GitHub
parent
commit
bd541b4f11
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 32
      libs/ui/src/lib/fire-calculator/fire-calculator.service.spec.ts
  3. 2
      libs/ui/src/lib/fire-calculator/fire-calculator.service.ts

1
CHANGELOG.md

@ -270,6 +270,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed a negative number of periods returned by the _FIRE_ calculator when the goal is already met with no interest rate
- Fixed an issue with the localization of the country names
- Fixed an issue in the data provider service where quotes could be missing for symbols that exist in multiple data sources by keying the quotes response by the asset profile identifier

32
libs/ui/src/lib/fire-calculator/fire-calculator.service.spec.ts

@ -32,6 +32,38 @@ describe('FireCalculatorService', () => {
expect(periodsToRetire).toBe(9);
});
it('should return 0 with no interest rate when the goal is already met', async () => {
const r = 0;
const P = 2000;
const totalAmount = 1900;
const PMT = 100;
const periodsToRetire = fireCalculatorService.calculatePeriodsToRetire({
P,
r,
PMT,
totalAmount
});
expect(periodsToRetire).toBe(0);
});
it('should return the correct positive amount of periods to retire with no interest rate', async () => {
const r = 0;
const P = 1000;
const totalAmount = 5000;
const PMT = 250;
const periodsToRetire = fireCalculatorService.calculatePeriodsToRetire({
P,
r,
PMT,
totalAmount
});
expect(periodsToRetire).toBe(16);
});
it('should return the 0 when total amount is 0', async () => {
const r = 0.05;
const P = 100000;

2
libs/ui/src/lib/fire-calculator/fire-calculator.service.ts

@ -52,7 +52,7 @@ export class FireCalculatorService {
}) {
if (r === 0) {
// No compound interest
return (totalAmount - P) / PMT;
return Math.max(0, (totalAmount - P) / PMT);
} else if (totalAmount <= P) {
return 0;
}

Loading…
Cancel
Save