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: pass tenures ForecastParameters instead of just children #79

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions app/models/Household.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ export class Household {
newBuildPrice: this.property.newBuildPrice,
depreciatedBuildPrice: this.property.depreciatedBuildPrice,
landPrice: this.property.landPrice,
propertyPriceGrowthPerYear:
this.forecastParameters.propertyPriceGrowthPerYear,
constructionPriceGrowthPerYear:
this.forecastParameters.constructionPriceGrowthPerYear,
yearsForecast: this.forecastParameters.yearsForecast,
maintenanceCostPercentage:
this.forecastParameters.maintenanceCostPercentage,
forecastParameters: this.forecastParameters,
});

const marketRent = new MarketRent({
Expand All @@ -74,14 +68,7 @@ export class Household {
depreciatedBuildPrice: this.property.depreciatedBuildPrice,
landPrice: this.property.landPrice,
incomeYearly: this.incomeYearly,
propertyPriceGrowthPerYear:
this.forecastParameters.propertyPriceGrowthPerYear,
constructionPriceGrowthPerYear:
this.forecastParameters.constructionPriceGrowthPerYear,
yearsForecast: this.forecastParameters.yearsForecast,
maintenanceCostPercentage:
this.forecastParameters.maintenanceCostPercentage,
rentGrowthPerYear: this.forecastParameters.rentGrowthPerYear,
forecastParameters: this.forecastParameters,
});

const socialRent = new SocialRent({
Expand All @@ -95,12 +82,7 @@ export class Household {
const fairholdLandPurchase = new FairholdLandPurchase({
newBuildPrice: this.property.newBuildPrice,
depreciatedBuildPrice: this.property.depreciatedBuildPrice,
constructionPriceGrowthPerYear:
this.forecastParameters.constructionPriceGrowthPerYear,
yearsForecast: this.forecastParameters.yearsForecast,
maintenanceCostPercentage:
this.forecastParameters.maintenanceCostPercentage,
incomeGrowthPerYear: this.forecastParameters.incomeGrowthPerYear,
forecastParameters: this.forecastParameters,
affordability: marketPurchase.affordability,
fairhold: new Fairhold({
affordability: marketPurchase.affordability,
Expand All @@ -115,17 +97,7 @@ export class Household {
depreciatedBuildPrice: this.property.depreciatedBuildPrice, // depreciated building price
landPrice: this.property.landPrice, // land price
incomeYearly: this.incomeYearly, // income
affordabilityThresholdIncomePercentage:
this.forecastParameters.affordabilityThresholdIncomePercentage, // affordability threshold percentage
propertyPriceGrowthPerYear:
this.forecastParameters.propertyPriceGrowthPerYear, // property price growth per year
constructionPriceGrowthPerYear:
this.forecastParameters.constructionPriceGrowthPerYear, // construction price growth per year
yearsForecast: this.forecastParameters.yearsForecast, // years forecast
maintenanceCostPercentage:
this.forecastParameters.maintenanceCostPercentage, // maintenance cost percentage
incomeGrowthPerYear: this.forecastParameters.incomeGrowthPerYear, // income growth per year
rentGrowthPerYear: this.forecastParameters.rentGrowthPerYear, // rent growth per year
forecastParameters: this.forecastParameters,

fairhold: new Fairhold({
affordability: marketRent.affordability,
Expand Down
8 changes: 6 additions & 2 deletions app/models/tenure/FairholdLandPurchase.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { Fairhold } from "../Fairhold";
import { DEFAULT_FORECAST_PARAMETERS } from "../ForecastParameters";
import { DEFAULT_FORECAST_PARAMETERS, ForecastParameters } from "../ForecastParameters";
import { FairholdLandPurchase } from "./FairholdLandPurchase";

let tenureFairholdLandPurchase: FairholdLandPurchase;

beforeEach(() => {
const forecastParameters: ForecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
};

tenureFairholdLandPurchase = new FairholdLandPurchase({
//incomeYearly: 45816,
//averagePrice: 218091.58,
newBuildPrice: 186560,
depreciatedBuildPrice: 110717.45,
//landPrice: 31531.579,
...DEFAULT_FORECAST_PARAMETERS,
affordability: 0.2,
fairhold: new Fairhold({
affordability: 0.2,
landPriceOrRent: 31531.579,
}),
forecastParameters: forecastParameters,
});
});

Expand Down
8 changes: 4 additions & 4 deletions app/models/tenure/FairholdLandPurchase.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Fairhold } from "../Fairhold";
import { Mortgage } from "../Mortgage";
import { ForecastParameters } from '../ForecastParameters';

interface FairholdLandPurchaseParams {
newBuildPrice: number;
depreciatedBuildPrice: number;
constructionPriceGrowthPerYear: number;
yearsForecast: number;
maintenanceCostPercentage: number;
incomeGrowthPerYear: number;
affordability: number;
fairhold: Fairhold;
forecastParameters: ForecastParameters;
}

export class FairholdLandPurchase {
params: FairholdLandPurchaseParams;
discountedLandPrice: number;
discountedLandMortgage: Mortgage;
depreciatedHouseMortgage: Mortgage;

constructor(params: FairholdLandPurchaseParams) {
this.params = params;
this.discountedLandPrice = params.fairhold.discountedLandPriceOrRent;

this.discountedLandMortgage = new Mortgage({
Expand Down
7 changes: 6 additions & 1 deletion app/models/tenure/FairholdLandRent.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Fairhold } from "../Fairhold";
import { DEFAULT_FORECAST_PARAMETERS } from "../ForecastParameters";
import { DEFAULT_FORECAST_PARAMETERS, ForecastParameters } from "../ForecastParameters";
import { FairholdLandRent } from "./FairholdLandRent";

let tenureFairholdLandRent: FairholdLandRent;

beforeEach(() => {
const forecastParameters: ForecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
};

tenureFairholdLandRent = new FairholdLandRent({
averageRentYearly: 20000,
incomeYearly: 45816,
Expand All @@ -17,6 +21,7 @@ beforeEach(() => {
affordability: 0.2,
landPriceOrRent: 20000,
}),
forecastParameters: forecastParameters,
});
});

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

interface FairholdLandRentParams {
averageRentYearly: number;
Expand All @@ -9,23 +10,19 @@ interface FairholdLandRentParams {
depreciatedBuildPrice: number;
landPrice: number;
incomeYearly: number;
affordabilityThresholdIncomePercentage: number;
propertyPriceGrowthPerYear: number;
constructionPriceGrowthPerYear: number;
yearsForecast: number;
maintenanceCostPercentage: number;
incomeGrowthPerYear: number;
rentGrowthPerYear: number;
fairhold: Fairhold;
forecastParameters: ForecastParameters;
}

export class FairholdLandRent {
params: FairholdLandRentParams;
/** Mortgage on the depreciated value of the house */
depreciatedHouseMortgage: Mortgage;
/** discounted value of the monthly land rent according to fairhold */
discountedLandRentMonthly: number;

constructor(params: FairholdLandRentParams) {
this.params = params;
this.depreciatedHouseMortgage = new Mortgage({
propertyValue: params.depreciatedBuildPrice,
});
Expand Down
17 changes: 4 additions & 13 deletions app/models/tenure/MarketPurchase.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { MarketPurchase } from "./MarketPurchase";
import { DEFAULT_FORECAST_PARAMETERS, ForecastParameters } from "../ForecastParameters";

let tenureMarketPurchase: MarketPurchase;

beforeEach(() => {
const forecastParameters = {
maintenanceCostPercentage: 0.0125, // percentage maintenance cost
incomeGrowthPerYear: 0.04, // 4% income growth per year
constructionPriceGrowthPerYear: 0.025, // 2.5%
rentGrowthPerYear: 0.03, // 3%
propertyPriceGrowthPerYear: 0.05, // 5%
yearsForecast: 40, // 40 years
affordabilityThresholdIncomePercentage: 0.35, // percentage of imcome to afford rent or purchase
const forecastParameters: ForecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
};

tenureMarketPurchase = new MarketPurchase({
Expand All @@ -19,11 +14,7 @@ beforeEach(() => {
newBuildPrice: 186560,
depreciatedBuildPrice: 110717.45,
landPrice: 31531.579,
propertyPriceGrowthPerYear: forecastParameters.propertyPriceGrowthPerYear,
constructionPriceGrowthPerYear:
forecastParameters.constructionPriceGrowthPerYear,
yearsForecast: forecastParameters.yearsForecast,
maintenanceCostPercentage: forecastParameters.maintenanceCostPercentage,
forecastParameters: forecastParameters,
});
});

Expand Down
18 changes: 11 additions & 7 deletions app/models/tenure/MarketPurchase.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { Mortgage } from "../Mortgage";
import { MONTHS_PER_YEAR } from "../constants";
import { ForecastParameters, DEFAULT_FORECAST_PARAMETERS } from '../ForecastParameters';

interface ConstructorParams {
interface MarketPurchaseParams {
averagePrice: number;
newBuildPrice: number;
depreciatedBuildPrice: number;
landPrice: number;
incomeYearly: number;
propertyPriceGrowthPerYear: number;
constructionPriceGrowthPerYear: number;
yearsForecast: number;
maintenanceCostPercentage: number;
forecastParameters: ForecastParameters;
}

export class MarketPurchase {
params: MarketPurchaseParams;
public affordability: number;
public houseMortgage: Mortgage;
public landMortgage: Mortgage;

constructor(params: ConstructorParams) {
constructor(params: MarketPurchaseParams) {
this.params = params;
this.params.forecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
...params.forecastParameters
};
this.houseMortgage = new Mortgage({
propertyValue: params.newBuildPrice,
});
Expand All @@ -30,7 +34,7 @@ export class MarketPurchase {
this.affordability = this.calculateAffordability(params);
}

private calculateAffordability({ incomeYearly }: ConstructorParams) {
private calculateAffordability({ incomeYearly }: MarketPurchaseParams) {
const affordability =
(this.landMortgage.monthlyPayment * MONTHS_PER_YEAR +
this.houseMortgage.monthlyPayment * MONTHS_PER_YEAR) /
Expand Down
18 changes: 4 additions & 14 deletions app/models/tenure/MarketRent.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { MarketRent } from "./MarketRent";
import { DEFAULT_FORECAST_PARAMETERS, ForecastParameters } from "../ForecastParameters";

let tenureMarketRent: MarketRent;

beforeEach(() => {
const forecastParameters = {
maintenanceCostPercentage: 0.0125, // percentage maintenance cost
incomeGrowthPerYear: 0.04, // 4% income growth per year
constructionPriceGrowthPerYear: 0.025, // 2.5%
rentGrowthPerYear: 0.03, // 3%
propertyPriceGrowthPerYear: 0.05, // 5%
yearsForecast: 40, // 40 years
affordabilityThresholdIncomePercentage: 0.35, // percentage of imcome to afford rent or purchase
const forecastParameters: ForecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
};

tenureMarketRent = new MarketRent({
Expand All @@ -20,12 +15,7 @@ beforeEach(() => {
newBuildPrice: 186560,
depreciatedBuildPrice: 110717.45,
landPrice: 31531.579,
propertyPriceGrowthPerYear: forecastParameters.propertyPriceGrowthPerYear,
constructionPriceGrowthPerYear:
forecastParameters.constructionPriceGrowthPerYear,
yearsForecast: forecastParameters.yearsForecast,
maintenanceCostPercentage: forecastParameters.maintenanceCostPercentage,
rentGrowthPerYear: forecastParameters.rentGrowthPerYear,
forecastParameters: forecastParameters,
});
});

Expand Down
20 changes: 11 additions & 9 deletions app/models/tenure/MarketRent.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { MONTHS_PER_YEAR } from "../constants";

interface ConstructorParams {
import { ForecastParameters, DEFAULT_FORECAST_PARAMETERS } from '../ForecastParameters';
interface MarketRentParams {
averageRentYearly: number;
averagePrice: number;
newBuildPrice: number;
depreciatedBuildPrice: number;
landPrice: number;
incomeYearly: number;
propertyPriceGrowthPerYear: number;
constructionPriceGrowthPerYear: number;
yearsForecast: number;
maintenanceCostPercentage: number;
rentGrowthPerYear: number;
forecastParameters: ForecastParameters;
}

export class MarketRent {
params: MarketRentParams;
public affordability: number;
public averageRentMonthly: number;
public averageRentLandMonthly: number;
public averageRentHouseMonthly: number;

constructor(params: ConstructorParams) {
constructor(params: MarketRentParams) {
this.params = params;
this.params.forecastParameters = {
...DEFAULT_FORECAST_PARAMETERS,
...params.forecastParameters
};
const {
averageRentMonthly,
averageRentLandMonthly,
Expand All @@ -39,7 +41,7 @@ export class MarketRent {
averagePrice,
incomeYearly,
averageRentYearly,
}: ConstructorParams) {
}: MarketRentParams) {
const averageRentMonthly = averageRentYearly / MONTHS_PER_YEAR;
const landToTotalRatio = landPrice / averagePrice;
const averageRentLandMonthly = averageRentMonthly * landToTotalRatio;
Expand Down
Loading