@ -285,6 +285,7 @@ export class FireCalculatorComponent
private getChartData() {
private getChartData() {
const currentYear = new Date ( ) . getFullYear ( ) ;
const currentYear = new Date ( ) . getFullYear ( ) ;
const labels = [ ] ;
const labels = [ ] ;
let t : number ;
// Principal investment amount
// Principal investment amount
const P : number =
const P : number =
@ -296,11 +297,29 @@ export class FireCalculatorComponent
// Annual interest rate
// Annual interest rate
const r : number = this . calculatorForm . get ( 'annualInterestRate' ) . value / 100 ;
const r : number = this . calculatorForm . get ( 'annualInterestRate' ) . value / 100 ;
// Time
// Target net worth
const t = this . calculatorForm . get ( 'time' ) . value ;
const targetNetWorth = this . calculatorForm . get ( 'retirementNetWorth' ) . value ;
const targetNetWorth = this . calculatorForm . get ( 'retirementNetWorth' ) . value ;
// Calculate retirement date
const periodsToRetire = this . fireCalculatorService . calculatePeriodsToRetire (
{
P ,
totalAmount : targetNetWorth ,
PMT ,
r
}
) ;
const yearsToRetire = Math . floor ( periodsToRetire / 12 ) ;
const monthsToRetire = periodsToRetire % 12 ;
// Time
if ( targetNetWorth ) {
// +1 to take into account the current year
t = yearsToRetire + 1 ;
} else {
t = this . calculatorForm . get ( 'time' ) . value ;
}
for ( let year = currentYear ; year < currentYear + t ; year ++ ) {
for ( let year = currentYear ; year < currentYear + t ; year ++ ) {
labels . push ( year ) ;
labels . push ( year ) ;
}
}
@ -353,22 +372,9 @@ export class FireCalculatorComponent
}
}
}
}
// Calculate retirement date
const periodsToRetire = this . fireCalculatorService . calculatePeriodsToRetire (
{
P ,
totalAmount : targetNetWorth ,
PMT ,
r
}
) ;
const years = Math . floor ( periodsToRetire / 12 ) ;
const months = periodsToRetire % 12 ;
const retirementDate = add ( new Date ( ) , {
const retirementDate = add ( new Date ( ) , {
years ,
years : yearsToRetire ,
months
months : monthsToRetire
} ) ;
} ) ;
this . retirementDate = format ( retirementDate , 'MMMM yyyy' ) ;
this . retirementDate = format ( retirementDate , 'MMMM yyyy' ) ;