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

chore: calculate landToTotalRatio once and pass it to relevant classes #157

Merged
merged 3 commits into from
Dec 6, 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
6 changes: 2 additions & 4 deletions app/models/Household.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ export class Household {

const marketRent = new MarketRent({
averageRentYearly: averageRentYearly,
averagePrice: this.property.averageMarketPrice,
newBuildPrice: this.property.newBuildPrice,
depreciatedBuildPrice: this.property.depreciatedBuildPrice,
landPrice: this.property.landPrice,
incomeYearly: this.incomeYearly,
landToTotalRatio: this.property.landToTotalRatio,
forecastParameters: this.forecastParameters,
});

Expand All @@ -95,11 +94,10 @@ export class Household {

const fairholdLandRent = new FairholdLandRent({
averageRentYearly: averageRentYearly,
averagePrice: this.property.averageMarketPrice,
newBuildPrice: this.property.newBuildPrice,
depreciatedBuildPrice: this.property.depreciatedBuildPrice,
landPrice: this.property.landPrice,
incomeYearly: this.incomeYearly,
landToTotalRatio: this.property.landToTotalRatio,
forecastParameters: this.forecastParameters,

fairhold: new Fairhold({
Expand Down
3 changes: 1 addition & 2 deletions app/models/tenure/FairholdLandRent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ beforeEach(() => {
tenureFairholdLandRent = new FairholdLandRent({
averageRentYearly: 20000,
incomeYearly: 45816,
averagePrice: 218091.58,
newBuildPrice: 186560,
depreciatedBuildPrice: 110717.45,
landPrice: 31531.579,
landToTotalRatio: 0.1446,
...DEFAULT_FORECAST_PARAMETERS,
fairhold: new Fairhold({
affordability: 0.2,
Expand Down
9 changes: 2 additions & 7 deletions app/models/tenure/FairholdLandRent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { MarketPurchase } from "./MarketPurchase";

interface FairholdLandRentParams {
averageRentYearly: number;
averagePrice: number;
newBuildPrice: number;
depreciatedBuildPrice: number;
landPrice: number;
incomeYearly: number;
landToTotalRatio: number;
fairhold: Fairhold;
forecastParameters: ForecastParameters;
marketPurchase: MarketPurchase;
Expand Down Expand Up @@ -48,13 +47,9 @@ export class FairholdLandRent {
private calculateDiscountedLandRentMonthly({
incomeYearly,
averageRentYearly,
landPrice,
averagePrice,
landToTotalRatio,
}: FairholdLandRentParams) {
const marketRentAffordability = incomeYearly / averageRentYearly;
/*TODO: landToTotalRatio is calculated elsewhere too, eg when instantiating socialRent in Property...
can we just calculate it once?*/
const landToTotalRatio = landPrice / averagePrice;
const averageRentLandMonthly =
(averageRentYearly / MONTHS_PER_YEAR) * landToTotalRatio;

Expand Down
3 changes: 1 addition & 2 deletions app/models/tenure/MarketRent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ beforeEach(() => {
tenureMarketRent = new MarketRent({
averageRentYearly: 20000,
incomeYearly: 45816,
averagePrice: 218091.58,
newBuildPrice: 186560,
depreciatedBuildPrice: 110717.45,
landPrice: 31531.579,
landToTotalRatio: 0.1446,
forecastParameters: forecastParameters,
});
});
Expand Down
8 changes: 2 additions & 6 deletions app/models/tenure/MarketRent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { MONTHS_PER_YEAR } from "../constants";
import { ForecastParameters, DEFAULT_FORECAST_PARAMETERS } from '../ForecastParameters';
interface MarketRentParams {
averageRentYearly: number;
averagePrice: number;
newBuildPrice: number;
depreciatedBuildPrice: number;
landPrice: number;
incomeYearly: number;
landToTotalRatio: number;
forecastParameters: ForecastParameters;
}

Expand Down Expand Up @@ -37,14 +36,11 @@ export class MarketRent {
}

private calculateAverageRentLandAndHouse({
landPrice,
averagePrice,
landToTotalRatio,
incomeYearly,
averageRentYearly,
}: MarketRentParams) {
const averageRentMonthly = averageRentYearly / MONTHS_PER_YEAR;
// TODO: landToTotalRatio is calculated multiple times in multiple places, can we just do it once?
const landToTotalRatio = landPrice / averagePrice;
const averageRentLandMonthly = averageRentMonthly * landToTotalRatio;
const averageRentHouseMonthly = averageRentMonthly - averageRentLandMonthly;
const affordability = averageRentYearly / incomeYearly;
Expand Down
Loading