Skip to content

Commit

Permalink
Merge pull request #157 from theopensystemslab/oz/landToTotalRatio
Browse files Browse the repository at this point in the history
chore: calculate `landToTotalRatio` once and pass it to relevant classes
  • Loading branch information
zz-hh-aa authored Dec 6, 2024
2 parents 39f44da + c9db4b6 commit cb32f66
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 21 deletions.
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

0 comments on commit cb32f66

Please sign in to comment.