Skip to content

Instantly share code, notes, and snippets.

@oesmith
Created July 4, 2015 10:32
Show Gist options
  • Save oesmith/b58663c123c7d74d2658 to your computer and use it in GitHub Desktop.
Save oesmith/b58663c123c7d74d2658 to your computer and use it in GitHub Desktop.
import datetime
# Monthly house price index, starting in January 1991. Extracted from the
# Nationwide monthly house price index. Licensing and more info available at:
# http://www.nationwide.co.uk/about/house-price-index/headlines
RAW_INDEX = [
105.83, 106.72, 105.52, 107.08, 108.49, 109.93, 108.80, 107.81, 106.25,
106.66, 105.77, 105.94, 103.64, 103.44, 103.69, 103.69, 105.16, 105.54,
105.18, 104.36, 101.93, 101.14, 98.95, 99.24, 99.90, 100.49, 100.12,
103.09, 101.54, 105.30, 104.22, 103.13, 102.09, 102.16, 100.97, 102.58,
102.98, 102.77, 103.94, 102.75, 103.27, 102.76, 103.98, 103.11, 102.91,
105.43, 103.90, 103.92, 101.54, 101.32, 102.99, 103.86, 104.09, 102.43,
102.98, 102.21, 101.61, 101.36, 101.61, 101.34, 100.78, 102.25, 102.78,
105.13, 105.55, 106.38, 106.90, 107.77, 108.39, 109.37, 110.59, 109.90,
109.03, 110.96, 112.74, 114.52, 116.09, 118.07, 119.96, 120.85, 122.36,
122.66, 123.44, 123.76, 123.32, 125.22, 126.66, 128.27, 129.93, 131.40,
132.97, 132.00, 131.56, 131.91, 131.96, 132.41, 132.43, 133.70, 136.27,
137.36, 139.51, 141.22, 142.10, 144.90, 146.09, 147.16, 149.53, 150.05,
149.74, 153.75, 158.38, 161.37, 161.60, 162.49, 161.85, 161.06, 160.93,
161.66, 163.12, 163.96, 166.47, 166.20, 169.72, 172.05, 174.09, 177.68,
179.46, 180.26, 184.39, 182.84, 184.05, 186.61, 185.99, 189.44, 193.09,
200.43, 205.25, 212.84, 217.08, 221.21, 225.26, 226.75, 230.93, 233.81,
235.2, 236.4, 243.7, 244.9, 248.9, 253.8, 255.8, 257.9, 260.3, 263.2,
266.1, 270.2, 268.9, 276.8, 284.4, 291.1, 297.3, 302.3, 307.8, 306.7,
306.7, 303.5, 306.1, 304.5, 302.7, 305.0, 307.0, 311.5, 313.7, 314.8,
315.9, 313.8, 312.2, 313.4, 313.5, 313.7, 316.1, 316.3, 323.3, 326.3,
328.4, 330.6, 334.6, 334.6, 338.0, 338.4, 343.5, 346.6, 345.6, 348.5,
353.3, 359.7, 362.2, 367.2, 367.6, 366.9, 368.5, 371.1, 367.3, 363.2,
360.0, 357.8, 357.3, 356.2, 346.3, 343.9, 337.8, 328.5, 322.8, 316.9,
316.1, 305.3, 300.2, 294.7, 301.1, 302.9, 307.2, 312.1, 316.9, 319.6,
322.8, 323.2, 324.7, 323.4, 326.1, 321.8, 328.2, 334.7, 337.5, 339.4,
337.8, 332.2, 332.7, 327.7, 325.4, 323.7, 321.6, 321.5, 328.7, 330.4,
333.6, 335.6, 336.6, 331.0, 331.7, 330.5, 330.7, 326.8, 323.6, 324.6,
325.8, 327.4, 331.2, 330.6, 327.9, 328.6, 327.1, 327.5, 326.9, 323.7,
323.7, 324.4, 328.4, 330.3, 335.0, 337.0, 340.8, 340.2, 343.4, 346.5,
348.2, 350.8, 352.1, 354.8, 359.6, 366.2, 372.1, 376.8, 376.9, 377.6,
375.8, 377.7, 377.8, 376.2, 375.9, 375.0, 377.9, 385.1, 389.3, 389.1,
]
JUNE2015 = datetime.date(2015, 6, 1)
def _idx(date):
"""Calculate an index in the RAW_PRICES lookup table."""
return (date.year - 1991) * 12 + (date.month - 1)
def adjust(price, sale_date, adjusted_date = JUNE2015):
"""
Project an estimated value for a property based on a sale price and date
using the Nationwide property price index. The 'day' fields of the date
parameters are ignored.
"""
a = RAW_INDEX[_idx(sale_date)]
b = RAW_INDEX[_idx(adjusted_date)]
return price * (b / a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment