Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate totalInterest in Mortgage class #119

Merged
merged 8 commits into from
Oct 17, 2024
3 changes: 3 additions & 0 deletions app/models/Household.ts
Original file line number Diff line number Diff line change
@@ -88,6 +88,7 @@ export class Household {
affordability: marketPurchase.affordability,
landPriceOrRent: this.property.landPrice,
}),
marketPurchase: this.tenure.marketPurchase
});

const fairholdLandRent = new FairholdLandRent({
@@ -103,6 +104,8 @@ export class Household {
affordability: marketRent.affordability,
landPriceOrRent: averageRentYearly,
}), // fairhold object

marketPurchase: this.tenure.marketPurchase
});

return {
7 changes: 7 additions & 0 deletions app/models/Mortgage.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ export class Mortgage {
monthlyPayment: number;
totalMortgageCost: number;
yearlyPaymentBreakdown: MortgageBreakdown;
totalInterest: number;

constructor(params: MortgageParams) {
this.propertyValue = params.propertyValue;
@@ -51,6 +52,7 @@ export class Mortgage {
this.totalMortgageCost = totalMortgageCost;

this.yearlyPaymentBreakdown = this.calculateYearlyPaymentBreakdown();
this.totalInterest = this.calculateTotalInterest();
}

private calculateMortgagePrinciple() {
@@ -110,4 +112,9 @@ export class Mortgage {

return yearlyPaymentBreakdown;
}
private calculateTotalInterest() {
const totalInterest = parseFloat((this.principal * this.interestRate * this.termYears).toFixed(2))
console.log("Total interest: ", totalInterest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Leftover console.log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

return totalInterest
}
}
19 changes: 19 additions & 0 deletions app/models/tenure/FairholdLandPurchase.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { Fairhold } from "../Fairhold";
import { Mortgage } from "../Mortgage";
import { ForecastParameters } from '../ForecastParameters';
import { MarketPurchase } from "./MarketPurchase";

interface FairholdLandPurchaseParams {
newBuildPrice: number;
depreciatedBuildPrice: number;
affordability: number;
fairhold: Fairhold;
forecastParameters: ForecastParameters;
marketPurchase: MarketPurchase;
}

export class FairholdLandPurchase {
params: FairholdLandPurchaseParams;
discountedLandPrice: number;
discountedLandMortgage: Mortgage;
depreciatedHouseMortgage: Mortgage;
interestPaid: number;
/** interest saved relative to market purchase, pounds */
interestSaved: number;

constructor(params: FairholdLandPurchaseParams) {
this.params = params;
@@ -27,6 +32,20 @@ export class FairholdLandPurchase {
this.depreciatedHouseMortgage = new Mortgage({
propertyValue: params.depreciatedBuildPrice,
});

this.interestPaid =
this.calculateInterestPaid();

this.interestSaved =
this.calculateInterestSaved(params.marketPurchase);
}

private calculateInterestPaid() {
return this.depreciatedHouseMortgage.totalInterest + this.discountedLandMortgage.totalInterest;
}

private calculateInterestSaved(marketPurchase: MarketPurchase): number {
return marketPurchase.interestPaid - this.interestPaid;
}

}
19 changes: 19 additions & 0 deletions app/models/tenure/FairholdLandRent.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { MONTHS_PER_YEAR } from "../constants";
import { Fairhold } from "../Fairhold";
import { Mortgage } from "../Mortgage";
import { ForecastParameters } from '../ForecastParameters';
import { MarketPurchase } from "./MarketPurchase";

interface FairholdLandRentParams {
averageRentYearly: number;
@@ -12,6 +13,7 @@ interface FairholdLandRentParams {
incomeYearly: number;
fairhold: Fairhold;
forecastParameters: ForecastParameters;
marketPurchase: MarketPurchase;
}

export class FairholdLandRent {
@@ -20,6 +22,9 @@ export class FairholdLandRent {
depreciatedHouseMortgage: Mortgage;
/** discounted value of the monthly land rent according to fairhold */
discountedLandRentMonthly: number;
interestPaid: number;
/** interest saved relative to market purchase, pounds */
interestSaved: number;

constructor(params: FairholdLandRentParams) {
this.params = params;
@@ -29,6 +34,12 @@ export class FairholdLandRent {

this.discountedLandRentMonthly =
this.calculateDiscountedLandRentMonthly(params);

this.interestPaid =
this.calculateInterestPaid();

this.interestSaved =
this.calculateInterestSaved(params.marketPurchase);
}

private calculateDiscountedLandRentMonthly({
@@ -51,4 +62,12 @@ export class FairholdLandRent {

return discountedLandRentMonthly;
}

private calculateInterestPaid() {
return this.depreciatedHouseMortgage.totalInterest;
}

private calculateInterestSaved(marketPurchase: MarketPurchase): number {
return marketPurchase.interestPaid - this.interestPaid;
}
}
7 changes: 7 additions & 0 deletions app/models/tenure/MarketPurchase.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ export class MarketPurchase {
public affordability: number;
public houseMortgage: Mortgage;
public landMortgage: Mortgage;
public interestPaid: number;

constructor(params: MarketPurchaseParams) {
this.params = params;
@@ -32,6 +33,8 @@ export class MarketPurchase {
});

this.affordability = this.calculateAffordability(params);

this.interestPaid = this.calculateInterestPaid();
}

private calculateAffordability({ incomeYearly }: MarketPurchaseParams) {
@@ -42,4 +45,8 @@ export class MarketPurchase {
return affordability;
}

private calculateInterestPaid() {
return this.houseMortgage.totalInterest + this.landMortgage.totalInterest
}

}