// Reproducible Southern California county home value and rent figures from Zillow Research public data (ZHVI and ZORI). // Sources (public CSVs, no key): // ZHVI https://files.zillowstatic.com/research/public_csvs/zhvi/County_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv (all homes = single-family + condo/co-op, middle tier 33rd-67th percentile, smoothed, seasonally adjusted, dollars) // ZORI https://files.zillowstatic.com/research/public_csvs/zori/County_zori_uc_sfrcondomfr_sm_month.csv (all homes plus multifamily, smoothed, dollars per month) // Usage: node zillow-socal-housing.mjs prints the tables as JSON and writes socal-county-housing-zillow-2021-2026.csv and zillow-socal-housing-output.json next to this script // Method: for each county, the value for the October month-end of each year 2021 to 2026 and the change over 12 months and over the five years from October 2021 to the latest month. The latest month is whatever the file ends with; figures change each month. // Limits: Zillow indexes are modeled estimates of typical values, not sale prices or asking rents of a specific home; they are revised; they say nothing about moving costs or why anyone moves. Data (c) Zillow; please attribute to Zillow Research Data. import fs from 'node:fs'; const ZHVI = 'https://files.zillowstatic.com/research/public_csvs/zhvi/County_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv'; const ZORI = 'https://files.zillowstatic.com/research/public_csvs/zori/County_zori_uc_sfrcondomfr_sm_month.csv'; const load = async (u) => { const l = (await (await fetch(u)).text()).trim().split(/\r?\n/); return { h: l[0].split(','), r: l.slice(1).map((x) => x.split(',')) }; }; const COUNTIES = ['Riverside County', 'San Bernardino County', 'Los Angeles County', 'Orange County', 'San Diego County']; const out = { sources: { zhvi: ZHVI, zori: ZORI }, retrieved: new Date().toISOString().slice(0, 10), counties: {} }; const rows = []; for (const [key, u] of [['homeValue', ZHVI], ['rent', ZORI]]) { const { h, r } = await load(u); const iN = h.indexOf('RegionName'), iS = h.indexOf('StateName'); const L = h.length - 1; out[key + 'Latest'] = h[L]; const at = (x, label) => { const i = h.indexOf(label); return i < 0 ? null : Number(x[i]); }; for (const c of COUNTIES) { const x = r.find((a) => a[iN] === c && a[iS] === 'CA'); if (!x) throw new Error('missing ' + c + ' in ' + key); const latest = Number(x[L]); const m12 = Number(x[L - 12]); const month = h[L].slice(5, 7); const y0 = Number(h[L].slice(0, 4)) - 5; const base = at(x, y0 + '-' + month + h[L].slice(7)); if (!Number.isFinite(latest) || !Number.isFinite(m12) || !Number.isFinite(base)) throw new Error('bad values ' + c + ' ' + key); out.counties[c] = out.counties[c] || {}; out.counties[c][key] = { latest: Math.round(latest), months12Ago: Math.round(m12), fiveYearsAgo: Math.round(base), change12Pct: Math.round((latest / m12 - 1) * 1000) / 10, change5yPct: Math.round((latest / base - 1) * 1000) / 10 }; rows.push([c, key, h[L], Math.round(latest), Math.round(m12), Math.round(base), out.counties[c][key].change12Pct, out.counties[c][key].change5yPct]); } } for (const c of COUNTIES) { const o = out.counties[c]; o.priceToAnnualRent = Math.round((o.homeValue.latest / (o.rent.latest * 12)) * 10) / 10; } const csv = ['county,measure,latest_month,latest_value,value_12_months_earlier,value_5_years_earlier,change_12_months_pct,change_5_years_pct', ...rows.map((r) => `"${r[0]}",${r.slice(1).join(',')}`)].join('\n') + '\n'; fs.writeFileSync(new URL('./socal-county-housing-zillow-2021-2026.csv', import.meta.url), csv); fs.writeFileSync(new URL('./zillow-socal-housing-output.json', import.meta.url), JSON.stringify(out, null, 1)); console.log(JSON.stringify(out, null, 1));