Bugfix/fix initial annual interest rate in fire calculator (#3437)

* Fix initial annual interest rate

* Update changelog
This commit is contained in:
Thomas Kaul
2024-05-31 17:29:19 +02:00
committed by GitHub
parent fb326fe0cc
commit 4355c96ab6
2 changed files with 23 additions and 17 deletions

View File

@@ -123,19 +123,6 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
Tooltip
);
this.calculatorForm.setValue(
{
annualInterestRate: this.annualInterestRate,
paymentPerPeriod: this.savingsRate,
principalInvestmentAmount: 0,
projectedTotalAmount: this.projectedTotalAmount,
retirementDate: this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE
},
{
emitEvent: false
}
);
this.calculatorForm.valueChanges
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => {
@@ -169,9 +156,22 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
}
public ngOnChanges() {
this.periodsToRetire = this.getPeriodsToRetire();
if (isNumber(this.fireWealth) && this.fireWealth >= 0) {
this.calculatorForm.setValue(
{
annualInterestRate: this.annualInterestRate,
paymentPerPeriod: this.savingsRate,
principalInvestmentAmount: 0,
projectedTotalAmount: this.projectedTotalAmount,
retirementDate: this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE
},
{
emitEvent: false
}
);
this.periodsToRetire = this.getPeriodsToRetire();
setTimeout(() => {
// Wait for the chartCanvas
this.calculatorForm.patchValue(
@@ -409,9 +409,9 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
if (this.projectedTotalAmount) {
const periods = this.fireCalculatorService.calculatePeriodsToRetire({
P: this.getP(),
totalAmount: this.projectedTotalAmount,
PMT: this.getPMT(),
r: this.getR()
r: this.getR(),
totalAmount: this.projectedTotalAmount
});
return periods;