hpipy.price_index.HedonicIndex#
- class hpipy.price_index.HedonicIndex(**kwargs)[source]
- Bases: - BaseHousePriceIndex- Hedonic house price index. - Implements the hedonic methodology for constructing house price indices. It uses property characteristics to control for quality differences between properties and estimates the pure price change over time. - Parameters:
- data – TransactionData. The transaction data used to construct the index. 
- model – BaseHousePriceModel. The underlying price model used to estimate the index. 
- kwargs (Any) 
 
 - name
- The names of the time periods in the index. - Type:
- pd.Series 
 
 - periods
- The time periods covered by the index. - Type:
- pd.Series 
 
 - value
- The index values. - Type:
- pd.Series 
 
 - index
- The index values in an alternate format. - Type:
- Any 
 
 - imputed
- Boolean array indicating which periods were imputed. - Type:
- np.ndarray 
 
 - smooth
- Smoothed version of the index values. - Type:
- Any 
 
 - volatility
- Volatility measures for the index. - Type:
- pd.DataFrame 
 
 - volatility_smooth
- Smoothed volatility measures. - Type:
- pd.DataFrame 
 
 - revision
- Revision measures for the index. - Type:
- pd.DataFrame 
 
 - revision_smooth
- Smoothed revision measures. - Type:
- pd.DataFrame 
 
 - Example - >>> import pandas as pd >>> from hpipy.price_index import HedonicIndex >>> # Create sample transaction data. >>> data = pd.DataFrame({ ... "property_id": [1, 2, 3], ... "transaction_id": [1, 2, 3], ... "price": [200000, 250000, 300000], ... "date": pd.to_datetime(["2020-01", "2021-01", "2020-02"]), ... "sqft": [1500, 1800, 2000], ... "bedrooms": [3, 3, 4], ... }) >>> # Create index. >>> index = HedonicIndex.create_index( ... data, ... prop_id="property_id", ... trans_id="transaction_id", ... price="price", ... date="date", ... periodicity="A", ... min_date="2020-01", ... max_date="2021-01", ... dep_var="price", ... ind_var=["sqft", "bedrooms"], ... ) - Methods - Initialize base house price index. - Convert coefficients to an index. - Create the index. - Create a series from the index. - Create an index from a house price model. - Get hedonic transaction data. - Get hedonic model. - Smooth the index. - Apply smoothing to all indices. - Attributes - __init__(**kwargs)
- Initialize base house price index. - Parameters:
- kwargs (Any) 
- Return type:
- None 
 
 - static coef_to_index(coef_df, log_dep, base_price=1)
- Convert coefficients to an index. 
 - classmethod create_index(trans_data, prop_id=None, trans_id=None, price=None, seq_only=True, max_period=None, smooth=False, periodicity=None, min_date=None, max_date=None, adj_type=None, **kwargs)
- Create the index. - Parameters:
- trans_data (TransactionData | PeriodTable | pd.DataFrame) – Input transaction data. 
- prop_id (str | None, optional) – Property identifier. Defaults to None. 
- trans_id (str | None, optional) – Transaction identifier. Defaults to None. 
- price (str | None, optional) – Price column name. Defaults to None. 
- seq_only (bool, optional) – Sequential only. Defaults to True. 
- max_period (int | None, optional) – Maximum index period. Defaults to None. 
- smooth (bool, optional) – Smooth the index. Defaults to False. 
- periodicity (str | None, optional) – Periodicity of the index. Defaults to None. 
- min_date (str | None, optional) – Minimum date for the index. Defaults to None. 
- max_date (str | None, optional) – Maximum date for the index. Defaults to None. 
- adj_type (str | None, optional) – Adjustment type. Defaults to None. 
- **kwargs – Additional keyword arguments. 
 
- Returns:
- Index object. 
- Return type:
- Self 
 
 - create_series(train_period=12, max_period=None, **kwargs)
- Create a series from the index. 
 - classmethod from_model(model, trans_data=None, max_period=None, smooth=False, **kwargs)
- Create an index from a house price model. - Parameters:
- model (BaseHousePriceModel) – House price model object. 
- trans_data (TransactionData | None, optional) – Transaction data object. Defaults to None. 
- max_period (int | None, optional) – Maximum period for the index. Defaults to None. 
- smooth (bool, optional) – Smooth the index. Defaults to False. 
- **kwargs – Additional keyword arguments. 
 
- Returns:
- Index object. 
- Return type:
- Self 
 
 - smooth_index(order=3, in_place=False)
- Smooth the index. 
 - smooth_series(order=3)
- Apply smoothing to all indices. - Parameters:
- order (int) – Defaults to 3. 
- Returns:
- Index object. 
- Return type:
- Self 
 
 - data: TransactionData
 - model: BaseHousePriceModel
 - name: Series
 - periods: Series
 - value: Series
 - index: Any
 - imputed: ndarray
 - smooth: Any
 - accuracy: DataFrame
 - accuracy_smooth: DataFrame
 - volatility: DataFrame
 - volatility_smooth: DataFrame
 - revision: DataFrame
 - revision_smooth: DataFrame