From 00b65ffc71a26fba62a85aa1f90dace5fcf14645 Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Wed, 27 Nov 2024 16:59:23 +0100 Subject: [PATCH] feat: calculate resale values over time --- app/models/Lifetime.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/models/Lifetime.ts b/app/models/Lifetime.ts index b906400..50390c0 100644 --- a/app/models/Lifetime.ts +++ b/app/models/Lifetime.ts @@ -39,6 +39,7 @@ export interface LifetimeData { // gasBillYearly: number; depreciatedHouseResaleValue: number; fairholdLandPurchaseResaleValue: number; + houseAge: number; [key: number]: number; } @@ -79,6 +80,7 @@ export class Lifetime { params.maintenancePercentage * newBuildPriceIterative; let depreciatedHouseResaleValueIterative = params.property.depreciatedBuildPrice; let fairholdLandPurchaseResaleValueIterative = params.fairholdLandPurchase.discountedLandPrice; + let houseAgeIterative = params.property.age; for (let i = 0; i < params.yearsForecast - 1; i++) { incomeYearlyIterative = @@ -103,8 +105,18 @@ export class Lifetime { marketRentYearlyIterative - marketRentLandYearlyIterative; maintenanceCostIterative = newBuildPriceIterative * params.maintenancePercentage; - depreciatedHouseResaleValueIterative = 0// TODO - fairholdLandPurchaseResaleValueIterative = 0// TODO + + /* A new instance of the `Property` class is needed here in order to + re-calculate the depreciated house value as the house gets older*/ + const iterativeProperty = new Property({ + ...params.property, + age: houseAgeIterative + }); + /* Use the `calculateDepreciatedBuildPrice()` method on the new `Property` class + to calculate an updated depreciated house value */ + depreciatedHouseResaleValueIterative = iterativeProperty.calculateDepreciatedBuildPrice() + fairholdLandPurchaseResaleValueIterative = (1 + params.constructionPriceGrowthPerYear) // TODO: replace variable name with cpiGrowthPerYear + houseAgeIterative += 1 if (i < params.marketPurchase.houseMortgage.termYears - 1) { newbuildHouseMortgageYearlyIterative = params.marketPurchase.houseMortgage.yearlyPaymentBreakdown[i].yearlyPayment; @@ -138,7 +150,8 @@ export class Lifetime { marketLandRentYearly: marketRentLandYearlyIterative, marketHouseRentYearly: marketRentHouseYearlyIterative, depreciatedHouseResaleValue: depreciatedHouseResaleValueIterative, - fairholdLandPurchaseResaleValue: fairholdLandPurchaseResaleValueIterative + fairholdLandPurchaseResaleValue: fairholdLandPurchaseResaleValueIterative, + houseAge: houseAgeIterative, }); } return lifetime;