File:UsAverageHouseSalePrice.svg

From Wikiversity
Jump to navigation Jump to search

Original file(SVG file, nominally 768 × 432 pixels, file size: 85 KB)

This is a file from the Wikimedia Commons. The description on its description page there is shown below.

Commons is a freely licensed media file repository. You can help.

Summary

Description
English: Average sales price of houses sold for the United States, plotted using code from Plotting code section.
Date
Source Own work
Author Dan Polansky

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

Plotting code

from matplotlib import pyplot as plt
import datetime
plotPrices = True
plot20YRates = True
# Data source:https://fred.stlouisfed.org/series/ASPUS
#ASPUS Average Sales Price of Houses Sold for the United States
inputData = [
  "1963-01-01:19300",
  "1963-04-01:19400",
  "1963-07-01:19200",
  "1963-10-01:19600",
  "1964-01-01:19600",
  "1964-04-01:20200",
  "1964-07-01:20500",
  "1964-10-01:20900",
  "1965-01-01:21500",
  "1965-04-01:21000",
  "1965-07-01:21600",
  "1965-10-01:21700",
  "1966-01-01:22700",
  "1966-04-01:23200",
  "1966-07-01:23000",
  "1966-10-01:22800",
  "1967-01-01:24000",
  "1967-04-01:24200",
  "1967-07-01:23900",
  "1967-10-01:24400",
  "1968-01-01:25400",
  "1968-04-01:26700",
  "1968-07-01:26600",
  "1968-10-01:27000",
  "1969-01-01:27600",
  "1969-04-01:28100",
  "1969-07-01:28100",
  "1969-10-01:27100",
  "1970-01-01:27000",
  "1970-04-01:27300",
  "1970-07-01:26000",
  "1970-10-01:26300",
  "1971-01-01:27300",
  "1971-04-01:28600",
  "1971-07-01:28300",
  "1971-10-01:28200",
  "1972-01-01:29000",
  "1972-04-01:29400",
  "1972-07-01:30300",
  "1972-10-01:31600",
  "1973-01-01:32800",
  "1973-04-01:35100",
  "1973-07-01:35900",
  "1973-10-01:36600",
  "1974-01-01:38000",
  "1974-04-01:38600",
  "1974-07-01:39000",
  "1974-10-01:39300",
  "1975-01-01:40900",
  "1975-04-01:42600",
  "1975-07-01:42200",
  "1975-10-01:44400",
  "1976-01-01:46000",
  "1976-04-01:47800",
  "1976-07-01:48100",
  "1976-10-01:50300",
  "1977-01-01:51600",
  "1977-04-01:54300",
  "1977-07-01:54000",
  "1977-10-01:57500",
  "1978-01-01:59300",
  "1978-04-01:61600",
  "1978-07-01:63500",
  "1978-10-01:66400",
  "1979-01-01:68300",
  "1979-04-01:72400",
  "1979-07-01:74200",
  "1979-10-01:72700",
  "1980-01-01:73600",
  "1980-04-01:74400",
  "1980-07-01:77500",
  "1980-10-01:80000",
  "1981-01-01:80900",
  "1981-04-01:84300",
  "1981-07-01:83800",
  "1981-10-01:83700",
  "1982-01-01:81200",
  "1982-04-01:85700",
  "1982-07-01:83900",
  "1982-10-01:84600",
  "1983-01-01:86700",
  "1983-04-01:89100",
  "1983-07-01:92500",
  "1983-10-01:90800",
  "1984-01-01:94700",
  "1984-04-01:99200",
  "1984-07-01:98500",
  "1984-10-01:97800",
  "1985-01-01:98500",
  "1985-04-01:100500",
  "1985-07-01:100500",
  "1985-10-01:103800",
  "1986-01-01:106300",
  "1986-04-01:112000",
  "1986-07-01:114400",
  "1986-10-01:115600",
  "1987-01-01:120800",
  "1987-04-01:126100",
  "1987-07-01:129900",
  "1987-10-01:133500",
  "1988-01-01:137900",
  "1988-04-01:134800",
  "1988-07-01:141500",
  "1988-10-01:140400",
  "1989-01-01:144300",
  "1989-04-01:146800",
  "1989-07-01:150200",
  "1989-10-01:151200",
  "1990-01-01:149500",
  "1990-04-01:151200",
  "1990-07-01:145500",
  "1990-10-01:150100",
  "1991-01-01:151100",
  "1991-04-01:148200",
  "1991-07-01:145400",
  "1991-10-01:144400",
  "1992-01-01:144500",
  "1992-04-01:145300",
  "1992-07-01:141700",
  "1992-10-01:147200",
  "1993-01-01:144700",
  "1993-04-01:148900",
  "1993-07-01:148000",
  "1993-10-01:148300",
  "1994-01-01:153600",
  "1994-04-01:154200",
  "1994-07-01:152800",
  "1994-10-01:156100",
  "1995-01-01:153500",
  "1995-04-01:158900",
  "1995-07-01:157700",
  "1995-10-01:160900",
  "1996-01-01:161100",
  "1996-04-01:166000",
  "1996-07-01:164000",
  "1996-10-01:171000",
  "1997-01-01:172200",
  "1997-04-01:177200",
  "1997-07-01:174700",
  "1997-10-01:175400",
  "1998-01-01:180000",
  "1998-04-01:178800",
  "1998-07-01:184300",
  "1998-10-01:181500",
  "1999-01-01:189100",
  "1999-04-01:191800",
  "1999-07-01:193000",
  "1999-10-01:204800",
  "2000-01-01:202900",
  "2000-04-01:202400",
  "2000-07-01:204100",
  "2000-10-01:212100",
  "2001-01-01:211000",
  "2001-04-01:211200",
  "2001-07-01:207800",
  "2001-10-01:214200",
  "2002-01-01:227600",
  "2002-04-01:227600",
  "2002-07-01:219100",
  "2002-10-01:232500",
  "2003-01-01:233100",
  "2003-04-01:241000",
  "2003-07-01:248100",
  "2003-10-01:256000",
  "2004-01-01:262900",
  "2004-04-01:265300",
  "2004-07-01:274000",
  "2004-10-01:286300",
  "2005-01-01:288500",
  "2005-04-01:287800",
  "2005-07-01:294600",
  "2005-10-01:294200",
  "2006-01-01:305300",
  "2006-04-01:302600",
  "2006-07-01:308100",
  "2006-10-01:299600",
  "2007-01-01:322100",
  "2007-04-01:310100",
  "2007-07-01:301200",
  "2007-10-01:305800",
  "2008-01-01:290400",
  "2008-04-01:304200",
  "2008-07-01:285100",
  "2008-10-01:276600",
  "2009-01-01:257000",
  "2009-04-01:273400",
  "2009-07-01:274100",
  "2009-10-01:272900",
  "2010-01-01:275300",
  "2010-04-01:268800",
  "2010-07-01:266000",
  "2010-10-01:278000",
  "2011-01-01:268100",
  "2011-04-01:267600",
  "2011-07-01:263000",
  "2011-10-01:259700",
  "2012-01-01:278000",
  "2012-04-01:282700",
  "2012-07-01:294500",
  "2012-10-01:297700",
  "2013-01-01:307400",
  "2013-04-01:320400",
  "2013-07-01:324400",
  "2013-10-01:334400",
  "2014-01-01:331400",
  "2014-04-01:340600",
  "2014-07-01:340400",
  "2014-10-01:369400",
  "2015-01-01:348000",
  "2015-04-01:339700",
  "2015-07-01:347400",
  "2015-10-01:366700",
  "2016-01-01:357000",
  "2016-04-01:357900",
  "2016-07-01:358800",
  "2016-10-01:364900",
  "2017-01-01:374800",
  "2017-04-01:376900",
  "2017-07-01:373200",
  "2017-10-01:399700",
  "2018-01-01:374600",
  "2018-04-01:378400",
  "2018-07-01:392900",
  "2018-10-01:384000",
  "2019-01-01:375500",
  "2019-04-01:376700",
  "2019-07-01:382700",
  "2019-10-01:384600",
  "2020-01-01:383000",
  "2020-04-01:374500",
  "2020-07-01:397800",
  "2020-10-01:403900",
  "2021-01-01:418600",
  "2021-04-01:440600",
  "2021-07-01:473000",
  "2021-10-01:497300",
  "2022-01-01:514100",
  "2022-04-01:527500",
  "2022-07-01:547800",
  "2022-10-01:552600",
  "2023-01-01:505300",
  "2023-04-01:503000",
  "2023-07-01:521900",
  "2023-10-01:492300"]

dates = []
prices = []
calc20YRates = []
for dataRowStr in inputData:
  dataRow = dataRowStr.split(":")
  date = datetime.datetime.strptime(dataRow[0], "%Y-%m-%d").date()
  price = int(dataRow[1])
  dates.append(date)
  prices.append(price)
  qInY = 4 # Quarter count in year
  if len(prices) > 20 * qInY:
    calc20YRates.append((float(prices[-1]) / prices[-1 - 20 * qInY]) ** (1/20.0))
  else:
    calc20YRates.append(float("nan"))

if plotPrices:
  fig, biax = plt.subplots()
  figSize = fig.get_size_inches()
  fig.set_size_inches(figSize[0] * 4/3, figSize[1])
  biax.set(xlabel="Date (Label on 1 January)", ylabel="House Price (USD)",
           title="Average U.S. house sales prices in USD, quarterly step (per stlouisfed.org)")
  xtickDates, xtickDatesStr = [], []
  for idx, date in enumerate(dates):
    if date.month == 1 and date.day == 1:
      xtickDates.append(date)
      xtickDatesStr.append(str(date.year) if date.year % 2 == 0 else "")
  plt.xticks(xtickDates, xtickDatesStr, rotation=70)
  plt.yticks([x * 50000 for x in range(0, 13)])
  plt.plot(dates, prices, color="#6699CC")
  plt.grid(linewidth=0.25, color="#CCCCCC")
  plt.tight_layout()
  plt.savefig("UsAverageHouseSalePrice.svg")
  
if plot20YRates:
  fig, biax = plt.subplots()
  figSize = fig.get_size_inches()
  fig.set_size_inches(figSize[0] * 4/3, figSize[1])
  biax.set(xlabel="Withdrawal date (label on 1 January)", ylabel="House price (USD) change rate",
           title="20-year change rate of U.S. house price in USD, annualized (base data per stlouisfed.org)\n" +
                 "The date of withdrawal, the date of deposit being 20 years before")
  xtickDates, xtickDatesStr = [], []
  for idx, date in enumerate(dates):
    if date.month == 1 and date.day == 1:
      xtickDates.append(date)
      xtickDatesStr.append(str(date.year) if date.year % 2 == 0 else "")
  plt.xticks(xtickDates, xtickDatesStr, rotation=70)
  plt.axhline(1, color='#BBBBBB', linewidth=0.75)
  plt.plot(dates, calc20YRates, color="#6699CC")
  plt.grid(linewidth=0.25, color="#CCCCCC")
  biax.set_yticklabels(['{:,.1%}'.format(x - 1) for x in biax.get_yticks()])
  plt.tight_layout()
  plt.savefig("UsAverageHouseSalePrice20YYield.svg")

Captions

Average sales price of houses sold for the United States

Items portrayed in this file

depicts

2 April 2024

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current08:59, 2 April 2024Thumbnail for version as of 08:59, 2 April 2024768 × 432 (85 KB)Dan PolanskyUploaded own work with UploadWizard

The following page uses this file:

Metadata