Core Functions
calculate_time_adjustment
Sales DataFrame with required fields:
sale_date: Transaction datesale_year,sale_month,sale_quarter: Date componentssale_price: Transaction pricebldg_area_finished_{unit}: Finished building arealand_area_{unit}: Land area
Settings dictionary containing configuration for area units and modeling parameters
Initial period type to attempt:
"M" (monthly), "Q" (quarterly), or "Y" (yearly). Automatically adjusted if insufficient data.Enable detailed progress output
DataFrame with daily time adjustment values containing:
period: Date (daily)value: Time adjustment multiplier
- Determines whether land or improvement drives value
- Calculates sale price per area unit
- Determines appropriate time resolution based on data density
- Computes median values by period (month/quarter/year)
- Interpolates missing periods linearly
- Flattens to daily resolution
- Normalizes to first period = 1.0
apply_time_adjustment
Input sales DataFrame
Settings dictionary
Period type for adjustment calculation
If True, write time adjustment schedule to CSV file
Print verbose output during computation
Sales DataFrame with added columns:
sale_price_time_adj: Time-adjusted sale pricesale_price_time_adj_per_impr_{unit}: Adjusted price per improvement areasale_price_time_adj_per_land_{unit}: Adjusted price per land area
write=True):
out/time_adjustment/{model_group}/time_adjustment_schedule.csv
apply_time_adjustment_per_model_group
apply_time_adjustment to process each model group separately, ensuring time trends are calculated independently for different property types.
Sales data for a single model group
Settings dictionary
Model group identifier
Period type for adjustment
Write adjustment schedule to file
Verbose output
Sales DataFrame with time-adjusted price columns
enrich_time_adjustment
Input sales DataFrame
Settings dictionary with optional
data.process.time_adjustment.period configurationWrite time adjustment schedule to file
Verbose output
Sales DataFrame with
sale_price_time_adj column addedPrivate Helper Functions
_determine_value_driver
Analyzes sales data to determine whether land or improvements primarily drive value in the dataset. Returns:"land" or "impr"
Logic:
- Compares median sale price per area for land vs. improvements
- If values are within 15% and ≥30% of sales are land, uses land
- Otherwise uses improvements
_determine_time_resolution
Automatically selects appropriate time period (Month, Quarter, Year) based on data density. Requirements:- At least 5 sales per period
- Monthly: tolerates up to 2 missing months per year
- Quarterly: tolerates up to 1 missing quarter per year
- Falls back to coarser resolution if insufficient data
_crunch_time_adjustment
Computes median sale price per area by time period, filters sparse periods, and interpolates missing values. Process:- Groups sales by period
- Calculates median price per area
- Filters periods with < 5 sales
- Interpolates missing periods
- Normalizes to first period
- Applies 3-period moving average for monthly data
_flatten_periods_to_days
Converts period-level adjustments to daily resolution through interpolation. Method: Maps period medians to period midpoints, then linearly interpolates between midpoints to fill all days.Usage Example
Time Adjustment Methodology
Calculation Steps
- Value Driver Detection: Determines if land or improvements drive value
- Period Selection: Chooses time resolution (M/Q/Y) based on data density
- Median Calculation: Computes median $/area by period
- Sparse Period Filtering: Removes periods with < 5 sales
- Interpolation: Fills gaps with linear interpolation
- Normalization: Sets earliest period to 1.0
- Smoothing: Applies moving average for monthly data
- Daily Mapping: Converts to daily factors via period midpoints
Correction Factor Formula
The correction factor brings historical sales forward to present value:- Jan 2020 indexed value: 1.00
- Jun 2023 indexed value: 1.15
- A sale from Jan 2020 at 500k × (1.15/1.00) = $575k
Data Requirements
Minimum Requirements:- At least 5 sales per time period
- Valid
sale_dateandsale_pricefields - Either
bldg_area_finished_{unit}orland_area_{unit}> 0
- 10+ sales per month for monthly resolution
- 30+ sales per quarter for quarterly resolution
- Continuous time coverage (interpolation handles small gaps)