Skip to content

Commit

Permalink
Merge pull request #256 from msmobility/pricingModelWithMaxVac
Browse files Browse the repository at this point in the history
Pricing model with max vac
  • Loading branch information
mergify[bot] authored Oct 24, 2019
2 parents f0f9eb3 + a1608bb commit 01afd69
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,85 @@ public class DefaultPricingStrategy extends JavaScriptCalculator<Double> impleme

private final static Reader reader = new InputStreamReader(ScriptInputProvider.getPricingScriptInput());

private double inflectionLow;
private double inflectionHigh;
private double slopeLow;
private double slopeMain;
private double slopeHigh;
private double maxDelta;
private double maxVacancyRateForPriceChange;

public DefaultPricingStrategy() {
super(reader);
inflectionLow = getLowInflectionPoint();
inflectionHigh = getHighInflectionPoint();
slopeLow = getLowerSlope();
slopeMain = getMainSlope();
slopeHigh = getHighSlope();
maxDelta = getMaximumChange();
maxVacancyRateForPriceChange = getMaxVacancyRateForPriceChange();
}

public double getLowInflectionPoint() {
private double getMaxVacancyRateForPriceChange() {
return super.calculate("getMaxVacancyRateForPriceChange");
}


public boolean shouldUpdatePrice(Dwelling dd) {
return true;
}

@Override
public double getPriceChangeRate(double vacancyRateAtThisRegion, double structuralVacancyRate) {
double changeRate;
float structuralVacLow = (float) (structuralVacancyRate * inflectionLow);
float structuralVacHigh = (float) (structuralVacancyRate * inflectionHigh);
if (vacancyRateAtThisRegion > maxVacancyRateForPriceChange){
//vacancy is higher than the maximum value to change price. Do not change price.
changeRate = 1f;
} else if (vacancyRateAtThisRegion < structuralVacLow) {
// vacancy is particularly low, prices need to rise steeply
changeRate = 1 - structuralVacLow * slopeLow +
(-structuralVacancyRate * slopeMain + structuralVacLow * slopeMain) +
slopeLow * vacancyRateAtThisRegion;
} else if (vacancyRateAtThisRegion < structuralVacHigh) {
// vacancy is within a normal range, prices change gradually
changeRate = 1 - structuralVacancyRate * slopeMain + slopeMain * vacancyRateAtThisRegion;
} else {
// vacancy is very high but under the maximum value to change price, prices do not change much
changeRate = 1 - structuralVacHigh * slopeHigh +
(-structuralVacancyRate * slopeMain + structuralVacHigh * slopeMain) +
slopeHigh * vacancyRateAtThisRegion;
}
changeRate = Math.min(changeRate, 1f + maxDelta);
changeRate = Math.max(changeRate, 1f - maxDelta);

return changeRate;
}

private double getLowInflectionPoint() {
return super.calculate("getLowInflectionPoint");
}

public double getHighInflectionPoint() {
private double getHighInflectionPoint() {
return super.calculate("getHighInflectionPoint");
}

public double getLowerSlope() {
private double getLowerSlope() {
return super.calculate("getLowerSlope");
}

public double getMainSlope() {
private double getMainSlope() {
return super.calculate("getMainSlope");
}

public double getHighSlope() {
private double getHighSlope() {
return super.calculate("getHighSlope");
}

public double getMaximumChange() {
private double getMaximumChange() {
return super.calculate("getMaximumChange");
}

@Override
public boolean shouldUpdatePrice(Dwelling dd) {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public final class PricingModelImpl extends AbstractModel implements PricingMode
private final static Logger logger = Logger.getLogger(PricingModelImpl.class);
private final PricingStrategy strategy;

private double inflectionLow;
private double inflectionHigh;
private double slopeLow;
private double slopeMain;
private double slopeHigh;
private double maxDelta;


public PricingModelImpl(DataContainer dataContainer, Properties properties, PricingStrategy strategy, Random rnd) {
super(dataContainer, properties, rnd);
Expand All @@ -35,12 +30,7 @@ public PricingModelImpl(DataContainer dataContainer, Properties properties, Pric

@Override
public void setup() {
inflectionLow = strategy.getLowInflectionPoint();
inflectionHigh = strategy.getHighInflectionPoint();
slopeLow = strategy.getLowerSlope();
slopeMain = strategy.getMainSlope();
slopeHigh = strategy.getHighSlope();
maxDelta = strategy.getMaximumChange();

}

@Override
Expand Down Expand Up @@ -72,29 +62,15 @@ private void updateRealEstatePrices(int year) {
continue;
}
int dto = dwellingTypes.indexOf(dd.getType());
float structuralVacancyRate = dd.getType().getStructuralVacancyRate();
float structuralVacLow = (float) (structuralVacancyRate * inflectionLow);
float structuralVacHigh = (float) (structuralVacancyRate * inflectionHigh);
int currentPrice = dd.getPrice();

int region = dataContainer.getGeoData().getZones().get(dd.getZoneId()).getRegion().getId();
double changeRate;
if (vacRate[dto][region] < structuralVacLow) {
// vacancy is particularly low, prices need to rise steeply
changeRate = 1 - structuralVacLow * slopeLow +
(-structuralVacancyRate * slopeMain + structuralVacLow * slopeMain) +
slopeLow * vacRate[dto][region];
} else if (vacRate[dto][region] < structuralVacHigh) {
// vacancy is within a normal range, prices change gradually
changeRate = 1 - structuralVacancyRate * slopeMain + slopeMain * vacRate[dto][region];
} else {
// vacancy is very low, prices do not change much anymore
changeRate = 1 - structuralVacHigh * slopeHigh +
(-structuralVacancyRate * slopeMain + structuralVacHigh * slopeMain) +
slopeHigh * vacRate[dto][region];
}
changeRate = Math.min(changeRate, 1f + maxDelta);
changeRate = Math.max(changeRate, 1f - maxDelta);
double vacancyRateAtThisRegion = vacRate[dto][region];
float structuralVacancyRate = dd.getType().getStructuralVacancyRate();
double changeRate = strategy.getPriceChangeRate(vacancyRateAtThisRegion, structuralVacancyRate);




double newPrice = currentPrice * changeRate;

if (dd.getId() == SiloUtil.trackDd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
import de.tum.bgu.msm.data.dwelling.Dwelling;

public interface PricingStrategy {
double getLowInflectionPoint();

double getHighInflectionPoint();

double getLowerSlope();

double getMainSlope();

double getHighSlope();

double getMaximumChange();

boolean shouldUpdatePrice(Dwelling dd);

double getPriceChangeRate(double vacancyRateAtThisRegion, double structuralVacancyRate);
}
8 changes: 8 additions & 0 deletions siloCore/src/main/resources/de/tum/bgu/msm/models/PricingCalc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var getHighInflectionPoint = function() {
return 2.;
}

var getMaxVacancyRateForPriceChange = function() {
// This value defines the vacancy rate (not multiplied by structural vacancies) from which the price will not change at all.
// For vacancies rates above 10% (if set to 0.1) the price will not decrease any more.
// This value applies for all dwelling types.
return 0.1;
}


var getLowerSlope = function() {
// describes the steep slope that is used for vacancies below the lower inflection point
return -10.;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.tum.bgu.msm.models.realEstate;

import de.tum.bgu.msm.models.realEstate.pricing.DefaultPricingStrategy;
import de.tum.bgu.msm.models.realEstate.pricing.PricingModel;
import de.tum.bgu.msm.models.realEstate.pricing.PricingStrategy;
import org.junit.Test;

public class PricingStrategyTest {



@Test
public final void pricingStrategyTest(){


PricingStrategy strategy = new DefaultPricingStrategy();

double structuralVacancy = 0.02;

double intervalWidth = 0.001;
// for (int i = 0; i < 100; i++){
//
// double vacancyRateAtThisRegion = i * intervalWidth;
// double changeRate = strategy.getPriceChangeRate(vacancyRateAtThisRegion, structuralVacancy);
// System.out.println(vacancyRateAtThisRegion + "," + changeRate);
// }





}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ id,zone,type,hhID,bedrooms,quality,monthlyCost,yearBuilt,coordX,coordY
22,873,"SFA",22,3,4,623,1990,NULL,NULL
23,921,"SFA",23,3,4,623,1992,NULL,NULL
24,861,"SFA",24,3,4,623,1990,NULL,NULL
25,1072,"SFD",25,2,4,453,1936,NULL,NULL
26,1057,"SFD",-1,2,4,453,1933,NULL,NULL
27,1069,"SFD",40,2,4,453,1931,NULL,NULL
28,1077,"SFD",-1,2,4,453,1933,NULL,NULL
29,1059,"SFD",76,2,4,453,1935,NULL,NULL
30,1068,"SFD",30,2,4,453,1932,NULL,NULL
31,1057,"SFD",-1,2,4,453,1930,NULL,NULL
32,1078,"SFD",78,2,4,453,1938,NULL,NULL
33,1074,"SFD",32,2,4,453,1935,NULL,NULL
34,1061,"SFD",11,2,4,453,1936,NULL,NULL
35,1059,"SFD",33,2,4,453,1939,NULL,NULL
36,1057,"SFD",31,2,4,453,1938,NULL,NULL
37,1074,"SFD",-1,2,3,453,1937,NULL,NULL
38,1079,"SFD",38,2,4,453,1938,NULL,NULL
39,1055,"SFD",28,2,4,453,1934,NULL,NULL
40,1063,"SFD",80,2,4,453,1933,NULL,NULL
25,1072,"SFD",25,2,4,500,1936,NULL,NULL
26,1057,"SFD",-1,2,4,500,1933,NULL,NULL
27,1069,"SFD",40,2,4,500,1931,NULL,NULL
28,1077,"SFD",-1,2,4,500,1933,NULL,NULL
29,1059,"SFD",76,2,4,500,1935,NULL,NULL
30,1068,"SFD",30,2,4,500,1932,NULL,NULL
31,1057,"SFD",-1,2,4,500,1930,NULL,NULL
32,1078,"SFD",78,2,4,500,1938,NULL,NULL
33,1074,"SFD",32,2,4,500,1935,NULL,NULL
34,1061,"SFD",11,2,4,500,1936,NULL,NULL
35,1059,"SFD",33,2,4,500,1939,NULL,NULL
36,1057,"SFD",31,2,4,500,1938,NULL,NULL
37,1074,"SFD",-1,2,3,500,1937,NULL,NULL
38,1079,"SFD",38,2,4,500,1938,NULL,NULL
39,1055,"SFD",28,2,4,500,1934,NULL,NULL
40,1063,"SFD",80,2,4,500,1933,NULL,NULL
41,1095,"SFD",41,3,4,872,1965,NULL,NULL
42,1136,"SFD",42,3,2,872,1969,NULL,NULL
43,1135,"SFD",43,3,1,872,1965,NULL,NULL
Expand Down Expand Up @@ -82,26 +82,26 @@ id,zone,type,hhID,bedrooms,quality,monthlyCost,yearBuilt,coordX,coordY
81,1157,"SFD",81,3,4,659,1997,NULL,NULL
82,1155,"SFD",82,3,4,659,1998,NULL,NULL
83,1162,"SFD",83,3,4,659,1996,NULL,NULL
84,19,"MF5plus",84,1,4,151,1975,NULL,NULL
85,1,"MF5plus",-1,1,4,151,1974,NULL,NULL
86,1,"MF5plus",86,1,4,151,1977,NULL,NULL
87,24,"MF5plus",87,1,4,151,1977,NULL,NULL
88,24,"MF5plus",88,1,4,151,1974,NULL,NULL
89,23,"MF5plus",89,1,4,151,1976,NULL,NULL
90,19,"MF5plus",90,1,4,151,1971,NULL,NULL
91,1,"MF5plus",91,1,4,151,1973,NULL,NULL
92,24,"MF5plus",92,1,4,151,1975,NULL,NULL
93,19,"MF5plus",93,1,4,151,1971,NULL,NULL
94,1,"MF5plus",94,1,4,151,1976,NULL,NULL
95,21,"MF5plus",95,1,4,151,1979,NULL,NULL
96,20,"MF5plus",105,1,4,151,1972,NULL,NULL
97,20,"MF5plus",97,1,4,151,1973,NULL,NULL
98,24,"MF5plus",98,1,4,151,1975,NULL,NULL
99,19,"MF5plus",99,1,4,151,1972,NULL,NULL
100,1,"MF5plus",106,1,4,151,1973,NULL,NULL
84,19,"MF5plus",84,1,4,159,1975,NULL,NULL
85,1,"MF5plus",-1,1,4,159,1974,NULL,NULL
86,1,"MF5plus",86,1,4,159,1977,NULL,NULL
87,24,"MF5plus",87,1,4,159,1977,NULL,NULL
88,24,"MF5plus",88,1,4,159,1974,NULL,NULL
89,23,"MF5plus",89,1,4,159,1976,NULL,NULL
90,19,"MF5plus",90,1,4,159,1971,NULL,NULL
91,1,"MF5plus",91,1,4,159,1973,NULL,NULL
92,24,"MF5plus",92,1,4,159,1975,NULL,NULL
93,19,"MF5plus",93,1,4,159,1971,NULL,NULL
94,1,"MF5plus",94,1,4,159,1976,NULL,NULL
95,21,"MF5plus",95,1,4,159,1979,NULL,NULL
96,20,"MF5plus",105,1,4,159,1972,NULL,NULL
97,20,"MF5plus",97,1,4,159,1973,NULL,NULL
98,24,"MF5plus",98,1,4,159,1975,NULL,NULL
99,19,"MF5plus",99,1,4,159,1972,NULL,NULL
100,1,"MF5plus",106,1,4,159,1973,NULL,NULL
101,581,"SFD",14,4,4,182,2000,349254.178869233,4342224.8451820025
102,952,"SFD",36,2,4,38,2000,312823.33660929714,4379709.753289761
102,952,"SFD",36,2,4,42,2000,312823.33660929714,4379709.753289761
103,1131,"SFD",34,3,4,60,2000,430602.002077716,4333371.6379696755
104,901,"SFA",101,3,4,144,2000,352211.27639046154,4310062.653957178
105,22,"MF5plus",18,1,4,141,2000,354093.31970647647,4352459.27429112
105,22,"MF5plus",18,1,4,149,2000,354093.31970647647,4352459.27429112
106,552,"SFD",104,4,4,165,2001,326288.1295675028,4343054.763120962
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ id,zone,type,hhID,bedrooms,quality,monthlyCost,yearBuilt,coordX,coordY
22,873,"SFA",22,3,4,629,1990,NULL,NULL
23,921,"SFA",23,3,4,629,1992,NULL,NULL
24,861,"SFA",24,3,4,629,1990,NULL,NULL
25,1072,"SFD",25,2,4,476,1936,NULL,NULL
26,1057,"SFD",26,2,4,476,1933,NULL,NULL
27,1069,"SFD",40,2,4,476,1931,NULL,NULL
28,1077,"SFD",-1,2,4,476,1933,NULL,NULL
29,1059,"SFD",-1,2,4,476,1935,NULL,NULL
30,1068,"SFD",30,2,4,476,1932,NULL,NULL
31,1057,"SFD",32,2,4,476,1930,NULL,NULL
32,1078,"SFD",-1,2,4,476,1938,NULL,NULL
33,1074,"SFD",33,2,3,476,1935,NULL,NULL
34,1061,"SFD",34,2,4,476,1936,NULL,NULL
35,1059,"SFD",35,2,4,476,1939,NULL,NULL
36,1057,"SFD",31,2,3,476,1938,NULL,NULL
37,1074,"SFD",37,2,3,476,1937,NULL,NULL
38,1079,"SFD",38,2,4,476,1938,NULL,NULL
39,1055,"SFD",28,2,4,476,1934,NULL,NULL
40,1063,"SFD",-1,2,4,476,1933,NULL,NULL
25,1072,"SFD",25,2,4,500,1936,NULL,NULL
26,1057,"SFD",26,2,4,500,1933,NULL,NULL
27,1069,"SFD",40,2,4,500,1931,NULL,NULL
28,1077,"SFD",-1,2,4,500,1933,NULL,NULL
29,1059,"SFD",-1,2,4,500,1935,NULL,NULL
30,1068,"SFD",30,2,4,500,1932,NULL,NULL
31,1057,"SFD",32,2,4,500,1930,NULL,NULL
32,1078,"SFD",-1,2,4,500,1938,NULL,NULL
33,1074,"SFD",33,2,3,500,1935,NULL,NULL
34,1061,"SFD",34,2,4,500,1936,NULL,NULL
35,1059,"SFD",35,2,4,500,1939,NULL,NULL
36,1057,"SFD",31,2,3,500,1938,NULL,NULL
37,1074,"SFD",37,2,3,500,1937,NULL,NULL
38,1079,"SFD",38,2,4,500,1938,NULL,NULL
39,1055,"SFD",28,2,4,500,1934,NULL,NULL
40,1063,"SFD",-1,2,4,500,1933,NULL,NULL
41,1095,"SFD",41,3,2,886,1965,NULL,NULL
42,1136,"SFD",42,3,2,886,1969,NULL,NULL
43,1135,"SFD",43,3,2,886,1965,NULL,NULL
Expand Down Expand Up @@ -82,25 +82,25 @@ id,zone,type,hhID,bedrooms,quality,monthlyCost,yearBuilt,coordX,coordY
81,1157,"SFD",81,3,4,669,1997,NULL,NULL
82,1155,"SFD",82,3,4,669,1998,NULL,NULL
83,1162,"SFD",83,3,4,669,1996,NULL,NULL
84,19,"MF5plus",84,1,4,152,1975,NULL,NULL
85,1,"MF5plus",85,1,3,152,1974,NULL,NULL
86,1,"MF5plus",86,1,4,152,1977,NULL,NULL
87,24,"MF5plus",87,1,4,152,1977,NULL,NULL
88,24,"MF5plus",88,1,4,152,1974,NULL,NULL
89,23,"MF5plus",89,1,4,152,1976,NULL,NULL
90,19,"MF5plus",90,1,4,152,1971,NULL,NULL
91,1,"MF5plus",91,1,4,152,1973,NULL,NULL
92,24,"MF5plus",92,1,4,152,1975,NULL,NULL
93,19,"MF5plus",93,1,4,152,1971,NULL,NULL
94,1,"MF5plus",94,1,4,152,1976,NULL,NULL
95,21,"MF5plus",95,1,4,152,1979,NULL,NULL
96,20,"MF5plus",-1,1,4,152,1972,NULL,NULL
97,20,"MF5plus",97,1,4,152,1973,NULL,NULL
98,24,"MF5plus",98,1,4,152,1975,NULL,NULL
99,19,"MF5plus",99,1,4,152,1972,NULL,NULL
100,1,"MF5plus",-1,1,4,152,1973,NULL,NULL
84,19,"MF5plus",84,1,4,160,1975,NULL,NULL
85,1,"MF5plus",85,1,3,160,1974,NULL,NULL
86,1,"MF5plus",86,1,4,160,1977,NULL,NULL
87,24,"MF5plus",87,1,4,160,1977,NULL,NULL
88,24,"MF5plus",88,1,4,160,1974,NULL,NULL
89,23,"MF5plus",89,1,4,160,1976,NULL,NULL
90,19,"MF5plus",90,1,4,160,1971,NULL,NULL
91,1,"MF5plus",91,1,4,160,1973,NULL,NULL
92,24,"MF5plus",92,1,4,160,1975,NULL,NULL
93,19,"MF5plus",93,1,4,160,1971,NULL,NULL
94,1,"MF5plus",94,1,4,160,1976,NULL,NULL
95,21,"MF5plus",95,1,4,160,1979,NULL,NULL
96,20,"MF5plus",-1,1,4,160,1972,NULL,NULL
97,20,"MF5plus",97,1,4,160,1973,NULL,NULL
98,24,"MF5plus",98,1,4,160,1975,NULL,NULL
99,19,"MF5plus",99,1,4,160,1972,NULL,NULL
100,1,"MF5plus",-1,1,4,160,1973,NULL,NULL
101,581,"SFD",14,4,4,165,2000,349254.178869233,4342224.8451820025
102,952,"SFD",36,2,4,40,2000,312823.33660929714,4379709.753289761
102,952,"SFD",36,2,4,42,2000,312823.33660929714,4379709.753289761
103,1131,"SFD",-1,3,4,61,2000,430602.002077716,4333371.6379696755
104,901,"SFA",101,3,4,145,2000,352211.27639046154,4310062.653957178
105,22,"MF5plus",18,1,4,142,2000,354093.31970647647,4352459.27429112
105,22,"MF5plus",18,1,4,150,2000,354093.31970647647,4352459.27429112
Loading

0 comments on commit 01afd69

Please sign in to comment.