Skip to content

Commit

Permalink
Complete refurbishment of the old Record classes, now named HousingMa…
Browse files Browse the repository at this point in the history
…rketRecord, HouseBidderRecord, and HouseOfferRecord, including the removal of BTLBuyerRecord
  • Loading branch information
adrian-carro committed Sep 25, 2018
1 parent 5eb8193 commit 4dc9e8f
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 242 deletions.
28 changes: 14 additions & 14 deletions src/main/java/collectors/MicroDataRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void openNewFile() {
}
}

public void recordSale(HouseBuyerRecord purchase, HouseSaleRecord sale, MortgageAgreement mortgage, HousingMarket market) {
public void recordSale(HouseBidderRecord purchase, HouseOfferRecord sale, MortgageAgreement mortgage, HousingMarket market) {
if(!active) return;
outfile.print(
Model.getTime()+", "
Expand All @@ -42,18 +42,18 @@ public void recordSale(HouseBuyerRecord purchase, HouseSaleRecord sale, Mortgage
outfile.print("rental, ");
}
outfile.print(
sale.house.id+", "+
sale.house.getQuality()+", "+
sale.initialListedPrice+", "+
sale.tInitialListing+", "+
sale.getHouse().id+", "+
sale.getHouse().getQuality()+", "+
sale.getInitialListedPrice()+", "+
sale.gettInitialListing()+", "+
sale.getPrice()+", "+
purchase.buyer.id+", "+
purchase.buyer.getAge()+", "+
purchase.buyer.behaviour.isPropertyInvestor()+", "+
purchase.buyer.getMonthlyGrossTotalIncome()+", "+
purchase.buyer.getMonthlyGrossEmploymentIncome() +", "+
purchase.buyer.getBankBalance()+", "+
purchase.buyer.behaviour.getBTLCapGainCoefficient() +", "
purchase.getBidder().id+", "+
purchase.getBidder().getAge()+", "+
purchase.getBidder().behaviour.isPropertyInvestor()+", "+
purchase.getBidder().getMonthlyGrossTotalIncome()+", "+
purchase.getBidder().getMonthlyGrossEmploymentIncome() +", "+
purchase.getBidder().getBankBalance()+", "+
purchase.getBidder().behaviour.getBTLCapGainCoefficient() +", "
);
if(mortgage != null) {
outfile.print(
Expand All @@ -64,8 +64,8 @@ public void recordSale(HouseBuyerRecord purchase, HouseSaleRecord sale, Mortgage
} else {
outfile.print("-1, false, false, ");
}
if(sale.house.owner instanceof Household) {
Household seller = (Household)sale.house.owner;
if(sale.getHouse().owner instanceof Household) {
Household seller = (Household) sale.getHouse().owner;
outfile.println(
seller.id+", "+
seller.getAge()+", "+
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/collectors/RegionalHousingMarketStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ public void preClearingRecord() {
// Re-initialise to zero variables computed before market clearing
nBuyers = market.getBids().size();
nBTLBuyers = 0;
for (HouseBuyerRecord bid: market.getBids()) {
if (bid.buyer.behaviour.isPropertyInvestor() && bid.buyer.getHome() != null) {
for (HouseBidderRecord bid: market.getBids()) {
if (bid.getBidder().behaviour.isPropertyInvestor() && bid.getBidder().getHome() != null) {
nBTLBuyers++;
}
}
nSellers = market.getOffersPQ().size();
nNewSellers = 0;
nBTLSellers = 0;
for (HousingMarketRecord element: market.getOffersPQ()) {
HouseSaleRecord offer = (HouseSaleRecord)element;
if (offer.tInitialListing == Model.getTime()) {
HouseOfferRecord offer = (HouseOfferRecord)element;
if (offer.gettInitialListing() == Model.getTime()) {
nNewSellers++;
}
if (offer.house.owner != Model.construction) {
Household h = (Household)offer.house.owner;
if (offer.getHouse().owner != Model.construction) {
Household h = (Household) offer.getHouse().owner;
if (h.behaviour.isPropertyInvestor()) {
nBTLSellers++;
}
Expand All @@ -173,15 +173,15 @@ public void preClearingRecord() {

// Record bid prices and their average
int i = 0;
for(HouseBuyerRecord bid : market.getBids()) {
for (HouseBidderRecord bid : market.getBids()) {
sumBidPrices += bid.getPrice();
bidPrices[i] = bid.getPrice();
++i;
}

// Record offer prices, their average, and the number of empty and new houses
i = 0;
for(HousingMarketRecord sale : market.getOffersPQ()) {
for (HousingMarketRecord sale : market.getOffersPQ()) {
sumOfferPrices += sale.getPrice();
offerPrices[i] = sale.getPrice();
++i;
Expand All @@ -194,17 +194,17 @@ public void preClearingRecord() {
* This method updates the values of several counters every time a buyer and a seller are matched and the
* transaction is completed. Note that only counter variables can be modified within this method
*
* @param purchase The HouseBuyerRecord of the buyer
* @param sale The HouseSaleRecord of the house being sold
* @param purchase The HouseBidderRecord of the buyer
* @param sale The HouseOfferRecord of the house being sold
*/
// TODO: Need to think if this method and recordTransaction can be joined in a single method!
public void recordSale(HouseBuyerRecord purchase, HouseSaleRecord sale) {
public void recordSale(HouseBidderRecord purchase, HouseOfferRecord sale) {
salesCount += 1;
MortgageAgreement mortgage = purchase.buyer.mortgageFor(sale.house);
if(mortgage != null) {
if(mortgage.isFirstTimeBuyer) {
MortgageAgreement mortgage = purchase.getBidder().mortgageFor(sale.getHouse());
if (mortgage != null) {
if (mortgage.isFirstTimeBuyer) {
ftbSalesCount += 1;
} else if(mortgage.isBuyToLet) {
} else if (mortgage.isBuyToLet) {
btlSalesCount += 1;
}
}
Expand All @@ -216,10 +216,10 @@ public void recordSale(HouseBuyerRecord purchase, HouseSaleRecord sale) {
* This method updates the values of several counters every time a buyer and a seller are matched and the
* transaction is completed. Note that only counter variables can be modified within this method
*
* @param sale The HouseSaleRecord of the house being sold
* @param sale The HouseOfferRecord of the house being sold
*/
public void recordTransaction(HouseSaleRecord sale) {
sumDaysOnMarketCount += config.constants.DAYS_IN_MONTH*(Model.getTime() - sale.tInitialListing);
public void recordTransaction(HouseOfferRecord sale) {
sumDaysOnMarketCount += config.constants.DAYS_IN_MONTH*(Model.getTime() - sale.gettInitialListing());
sumSalePricePerQualityCount[sale.getQuality()] += sale.getPrice();
nSalesPerQualityCount[sale.getQuality()]++;
sumSoldReferencePriceCount += referencePricePerQuality[sale.getQuality()];
Expand Down Expand Up @@ -256,7 +256,7 @@ public void postClearingRecord() {
}
}
// ... current house price index (only if there have been sales)
if(nSales > 0) {
if (nSales > 0) {
housePriceIndex = sumSoldPrice/sumSoldReferencePrice;
}
// ... HPIRecord with the new house price index value
Expand All @@ -265,14 +265,14 @@ public void postClearingRecord() {
annualHousePriceAppreciation = housePriceAppreciation(1);
longTermHousePriceAppreciation = housePriceAppreciation(config.HPA_YEARS_TO_CHECK);
// ... relaxation of the price distribution towards the reference price distribution (described in appendix A3)
for(int q = 0; q < config.N_QUALITY; q++) {
for (int q = 0; q < config.N_QUALITY; q++) {
expAvSalePricePerQuality[q] = config.MARKET_AVERAGE_PRICE_DECAY*expAvSalePricePerQuality[q]
+ (1.0 - config.MARKET_AVERAGE_PRICE_DECAY)*(housePriceIndex*referencePricePerQuality[q]);
}
// ...record number of unsold new build houses
nUnsoldNewBuild = 0;
for(HousingMarketRecord sale : market.getOffersPQ()) {
if(((HouseSaleRecord)sale).house.owner == Model.construction) nUnsoldNewBuild++;
for (HousingMarketRecord sale : market.getOffersPQ()) {
if (((HouseOfferRecord) sale).getHouse().owner == Model.construction) nUnsoldNewBuild++;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/collectors/RegionalRentalMarketStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public void preClearingRecord() {
* variables. Updates the values of several counters every time a buyer and a seller are matched and the transaction
* is completed. Note that only counter variables can be modified within this method
*
* @param sale The HouseSaleRecord of the house being sold
* @param sale The HouseOfferRecord of the house being sold
*/
@Override
public void recordTransaction(HouseSaleRecord sale) {
public void recordTransaction(HouseOfferRecord sale) {
super.recordTransaction(sale);
sumMonthsOnMarketPerQualityCount[sale.getQuality()] += (Model.getTime() - sale.tInitialListing);
sumMonthsOnMarketPerQualityCount[sale.getQuality()] += (Model.getTime() - sale.gettInitialListing());
}

//----- Post-market-clearing methods -----//
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/housing/BTLBuyerRecord.java

This file was deleted.

10 changes: 6 additions & 4 deletions src/main/java/housing/Construction.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ private void smartStep() {
newHouse.owner = this;
// ...put the house for sale in the regional house sale market at the reference price for that quality
region.houseSaleMarket.offer(newHouse,
region.regionalHousingMarketStats.getExpAvSalePriceForQuality(newHouse.getQuality()));
region.regionalHousingMarketStats.getExpAvSalePriceForQuality(newHouse.getQuality()),
false);
// region.regionalHousingMarketStats.getReferencePriceForQuality(newHouse.getQuality()));
// ...add the house to the portfolio of construction sector properties
onMarket.add(newHouse);
Expand Down Expand Up @@ -185,7 +186,8 @@ private void normalStep() {
newHouse.owner = this;
// ...put the house for sale in the regional house sale market at the reference price for that quality
region.houseSaleMarket.offer(newHouse,
region.regionalHousingMarketStats.getReferencePriceForQuality(newHouse.getQuality()));
region.regionalHousingMarketStats.getReferencePriceForQuality(newHouse.getQuality()),
false);
// ...add the house to the portfolio of construction sector properties
onMarket.add(newHouse);
// ...and finally increase both regional and general housing stocks, and decrease shortfall
Expand All @@ -197,15 +199,15 @@ private void normalStep() {
}

@Override
public void completeHouseSale(HouseSaleRecord sale) { onMarket.remove(sale.house); }
public void completeHouseSale(HouseOfferRecord sale) { onMarket.remove(sale.getHouse()); }

@Override
public void endOfLettingAgreement(House h, PaymentAgreement p) {
System.out.println("Strange: a tenant is moving out of a house owned by the construction sector!");
}

@Override
public void completeHouseLet(HouseSaleRecord sale) {
public void completeHouseLet(HouseOfferRecord sale) {
System.out.println("Strange: the construction sector is trying to let a house!");
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/housing/House.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class House implements Comparable<House>, Serializable {
public Region region;
public int id;

HouseSaleRecord saleRecord;
HouseSaleRecord rentalRecord;
HouseOfferRecord saleRecord;
HouseOfferRecord rentalRecord;

private int quality;

Expand Down Expand Up @@ -50,15 +50,15 @@ public House(Region region, int quality) {

boolean isOnMarket() { return saleRecord != null; }

HouseSaleRecord getSaleRecord() { return saleRecord; }
HouseOfferRecord getSaleRecord() { return saleRecord; }

HouseSaleRecord getRentalRecord() { return rentalRecord; }
HouseOfferRecord getRentalRecord() { return rentalRecord; }

boolean isOnRentalMarket() { return rentalRecord != null; }
void putForSale(HouseSaleRecord saleRecord) { this.saleRecord = saleRecord; }
void putForSale(HouseOfferRecord saleRecord) { this.saleRecord = saleRecord; }

void resetSaleRecord() { saleRecord = null; }
void putForRent(HouseSaleRecord rentalRecord) { this.rentalRecord = rentalRecord; }
void putForRent(HouseOfferRecord rentalRecord) { this.rentalRecord = rentalRecord; }

void resetRentalRecord() { rentalRecord = null; }

Expand Down
63 changes: 63 additions & 0 deletions src/main/java/housing/HouseBidderRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package housing;

import java.util.Comparator;

/**************************************************************************************************
* This class encapsulates information on a household that has placed a bid for a house on the
* rental or the ownership housing market. One can think of it as the file an estate agent would
* have on a customer who wants to buy or rent a house.
*
* @author daniel, Adrian Carro
*
*************************************************************************************************/
public class HouseBidderRecord extends HousingMarketRecord {

//------------------//
//----- Fields -----//
//------------------//

private Household bidder; // Household who is bidding to buy or rent a house
private boolean BTLBid; // True if the bid is for a buy-to-let property, false for a home bid (Note that rental bids are all set to false)

//------------------------//
//----- Constructors -----//
//------------------------//

HouseBidderRecord(Household h, double price, boolean BTLBid) {
super(price);
this.bidder = h;
this.BTLBid = BTLBid;
}

//----------------------//
//----- Subclasses -----//
//----------------------//

/**
* Class that implements a price comparator which solves the case of equal price by using the arguments' IDs.
*/
public static class PComparator implements Comparator<HouseBidderRecord> {
@Override
public int compare(HouseBidderRecord arg0, HouseBidderRecord arg1) {
double diff = arg0.getPrice() - arg1.getPrice();
if (diff == 0.0) {
diff = arg0.getId() - arg1.getId();
}
return (int) Math.signum(diff);
}
}

//-------------------//
//----- Methods -----//
//-------------------//

//----- Getter/setter methods -----//

public Household getBidder() { return bidder; }

boolean isBTLBid() { return BTLBid; }

// TODO: Check if the abstract method in HousingMarketRecord class is actually needed, otherwise this could be removed
@Override
public int getQuality() { return 0; }
}
42 changes: 0 additions & 42 deletions src/main/java/housing/HouseBuyerRecord.java

This file was deleted.

Loading

0 comments on commit 4dc9e8f

Please sign in to comment.