Singapore Public Housing (HDB) Valuation Engine using geospatial accessibility scoring.
Project description
HDB Valuation Engine 🇸🇬
A quantitative tool for identifying undervalued Singapore public housing assets using spatial data analysis.
The Real-World Problems
- The LRT Deception: Commercial portals treat LRT (Light Rail) and MRT (Heavy Rail) as equal. This is false. LRT loops add significant commute latency. Buyers need a metric that rewards True Connectivity.
- The Lease Illusion: Buyers often fixate on raw price, ignoring lease decay. A 'cheap' flat with 50 years remaining is often a worse asset than a pricier unit with 95 years.
- Data Overload: With thousands of transactions, manual comparisons are impossible. Buyers need statistical anomaly detection, not just a search bar.
The Engineering Solution
This engine ingests historical transaction data to calculate a 'True Value Score' for every flat.
- LRT-Exclusion Algorithm: Uses Regex filtering and KDTree spatial indexing to calculate walking distance strictly to MRT nodes.
- Depreciation Logic: Normalizes price against remaining lease life to find the true cost of ownership.
- Z-Score Ranking: Identifies properties trading 2 deviations below their cluster average.
Key Features
- Strict OOP pipeline with type hints and logging
- Robust lease parsing and inference (handles text and infers from
lease_commence_date+month) - Lease-adjusted price efficiency metric and group-wise Z-Score valuation
- Extended filters (exact/partial) and numeric ranges
- TransportScorer with KDTree and strict LRT exclusion (regex
^(BP|S[WE]|P[WE])) - Export to CSV/JSON/Parquet; optional full export
- Configurable peer grouping via
--group-by - Caching for fast repeated transport queries; cache management subcommand
Algorithm Overview
- Lease parsing/inference
- Parse
remaining_leasestrings to float years (e.g.,61 years 04 months→61.33). - If absent, infer years:
remaining_years = 99 - ((YYYY + (MM-1)/12) - lease_commence_year).
- Parse
- Price efficiency
price_efficiency = resale_price / (floor_area_sqm * remaining_lease_years)
- Group-wise Z-Score
- Group by
--group-by(default:town,flat_type) and computez = (x - μ) / σ.
- Group by
- Valuation score
valuation_score = - z_price_efficiency(higher → more undervalued).
- Transport accessibility (optional)
- Compute nearest MRT exit distance (LRT excluded) and
Accessibility_Score = max(0, 10 - 2 * dist_km). - By default adjusts price_efficiency; use
--no-accessibility-adjustfor analysis-only.
- Compute nearest MRT exit distance (LRT excluded) and
Installation
From PyPI:
pip install hdb-valuation-engine
From source (recommended in a virtual environment):
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\\Scripts\\Activate.ps1
pip install -r requirements.txt
Quick Start
Platform-agnostic data fetching (no Make needed):
- Fetch all supported datasets (HDB resale CSV + MRT exits GeoJSON):
hdb-valuation-engine fetch
- Fetch entire HDB resale dataset (no row limit) plus MRT exits:
hdb-valuation-engine fetch --limit 0
- Only MRT exits to a custom path:
hdb-valuation-engine fetch --datasets mrt --mrt-out .data/LTAMRTStationExitGEOJSON.geojson
- Only HDB resale CSV with 10k rows to default location:
hdb-valuation-engine fetch --datasets resale --limit 10000
Programmatic usage:
from hdb_valuation_engine import HDBValuationEngine
import argparse
app = HDBValuationEngine()
args = argparse.Namespace(
input="ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv",
town="PUNGGOL",
budget=600000,
top=5,
verbose=1,
mrt_catalog=None,
group_by=None,
output=None,
export_full=False,
output_format="csv",
no_accessibility_adjust=False,
town_like=None,
flat_type=None,
flat_type_like=None,
flat_model=None,
flat_model_like=None,
storey_min=None,
storey_max=None,
area_min=None,
area_max=None,
lease_min=None,
lease_max=None,
transport_cache_dir=None,
clear_transport_cache=False,
command=None,
)
exit_code = app.run(args)
print("Exit:", exit_code)
CLI usage (after install):
hdb-valuation-engine --input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" --top 5 -v
Usage
hdb-valuation-engine --input <path/to/file.csv> [OPTIONS]
Core options
--inputPath to HDB resale CSV data--topNumber of results to display (default: 10)- Logging:
-v(INFO) or-vv(DEBUG)
Filters
- Town:
--town PUNGGOL(exact),--town-like unggol(partial) - Flat Type:
--flat-type "5 ROOM"(exact),--flat-type-like room(partial) - Flat Model:
--flat-model "Improved"(exact),--flat-model-like improv(partial) - Storey:
--storey-min 7 --storey-max 12 - Area (sqm):
--area-min 60 --area-max 120 - Remaining Lease (years):
--lease-min 60 --lease-max 95 - Budget (max
resale_price):--budget 600000
Grouping (peer comparison)
--group-by town flat_type [flat_model]
Transport Accessibility (MRT via GeoJSON)
- Fast, cached KDTree for nearest MRT exit queries (10k+ rows). Cache saved under
.cache_transport/. - Provide LTA MRT Station Exit GeoJSON to enable accessibility scoring:
# You can fetch a current GeoJSON via the built-in fetcher
hdb-valuation-engine fetch --datasets mrt --mrt-out .data/LTAMRTStationExitGEOJSON.geojson
# Then reference it when running valuations
--mrt-catalog .data/LTAMRTStationExitGEOJSON.geojson
- Excludes LRT strictly via regex
^(BP|S[WE]|P[WE])and filters names containingLRTas a fallback. - Adds:
Nearest_MRTDist_mAccessibility_Score = max(0, 10 - 2 * dist_km)
- Analysis-only mode (no adjustment):
--no-accessibility-adjust
Exporting
--output top10.csv --output-format csv # CSV (default)
--output top10.json --output-format json # JSON
--output top10.parquet --output-format parquet # Parquet (falls back to CSV if engine missing)
--export-full # Export all filtered rows instead of Top-N
Quick Usage Examples
- Cache management subcommand
# Show cache directory
hdb-valuation-engine cache -v
# Clear cache in default location
hdb-valuation-engine cache --clear -v
# Use a custom cache dir
hdb-valuation-engine cache --transport-cache-dir .transport_cache --clear -v
- Build and cache KDTree from LTA GeoJSON; show Top-10 with adjustment:
hdb-valuation-engine \
--input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" \
--mrt-catalog ".data/LTAMRTStationExitGEOJSON.geojson" \
--top 10 -v
- Use cached KDTree on subsequent runs (faster); analysis-only mode (no price adjustment):
hdb-valuation-engine \
--input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" \
--mrt-catalog ".data/LTAMRTStationExitGEOJSON.geojson" \
--no-accessibility-adjust --top 10 -v
- Custom cache directory and force clear before building:
hdb-valuation-engine \
--input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" \
--mrt-catalog ".data/LTAMRTStationExitGEOJSON.geojson" \
--transport-cache-dir ".transport_cache" --clear-transport-cache --top 5 -v
- CSV catalog path (still supported; auto-excludes LRT lines):
hdb-valuation-engine \
--input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" \
--mrt-catalog "/path/to/mrt_catalog.csv" --top 5 -v
- Combine with group-by and export options:
hdb-valuation-engine \
--input "ResaleFlatPrices/Resale flat prices based on registration date from Jan-2017 onwards.csv" \
--mrt-catalog ".data/LTAMRTStationExitGEOJSON.geojson" \
--group-by town flat_type flat_model \
--export-full --output top.json --output-format json --top 10 -v
Smoke Test Summary
- 2017 onwards: Parsed
remaining_leasestrings successfully; produced Top-10 Punggol table under budget 600k. Export worked. - 2012–2014: Inferred remaining lease from
lease_commence_dateandmonth; produced Top-10 Punggol table. - 2000–Feb 2012: Inference path also worked; produced Top-5 for Ang Mo Kio under budget 200k.
- Extended filters and partial matching verified;
--output,--export-full, and--output-formatworked as expected.
Design & Implementation Notes
- Columns normalized to lowercase with underscores
- Robust z-score handling for zero-variance groups
- Logging across load, feature engineering, scoring, filtering, and export
Release and Tagging
To create a 0.1.0 release and push the tag:
git add -A
git commit -m "chore(release): cut 0.1.0"
git tag -a v0.1.0 -m "Initial PyPI packaging for hdb-valuation-engine"
git push origin main
git push origin v0.1.0
Running Tests
Note: You can fetch data without Make on any platform using the built-in fetch command:
# Fetch all datasets with defaults
hdb-valuation-engine fetch
# Fetch entire resale CSV and MRT exits
hdb-valuation-engine fetch --limit 0
- Recommended: use a virtual environment
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\\Scripts\\Activate.ps1
pip install -r requirements.txt
pytest -q
Optional dataset for an extra smoke test
One test is skipped by default unless a local dataset is available. To enable it:
- Create a folder named
ResaleFlatPricesat the repository root (same level astests/andREADME.md). - Place one or more HDB resale CSV files inside that folder, for example:
Resale flat prices based on registration date from Jan-2017 onwards.csv
You can fetch a small sample automatically with:
make setup-venv # one-time environment setup
make fetch-sample-data # downloads a subset into ./ResaleFlatPrices/
When this folder exists and contains at least one .csv file, the optional smoke test in tests/test_cli_export.py::TestOptionalRealDataset will run. If the folder is missing or empty, the test is skipped with reason:
ResaleFlatPrices folder not present; skipping optional smoke test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hdb_valuation_engine-0.1.2.tar.gz.
File metadata
- Download URL: hdb_valuation_engine-0.1.2.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9c5b815eec6acac6ddbf862fd15c9167e9d5baa2fddb77120f86a8762965dd7
|
|
| MD5 |
e4ba9b36d020ffc828aab73bb4468ba6
|
|
| BLAKE2b-256 |
70295ad39ee2de202a41702208a03daf5d6f1221de7b084e758312a719af6f39
|
File details
Details for the file hdb_valuation_engine-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hdb_valuation_engine-0.1.2-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbd4cfd360cf6cdfc4ee8ba11a593306e37d35131e9a4ef6d76921308017a24
|
|
| MD5 |
72073e139161d66eb7671ded52e8c354
|
|
| BLAKE2b-256 |
d72538dc0846ab16a8be8289dc02eb60080e6a45dd65e9a293d65812aa6bc377
|