get_property_price_index
Retrieve Swiss Residential Property Price Index data from BFS to track quarterly property price trends since 2009. Filter by property type and date range for analysis.
Instructions
Get the Swiss Residential Property Price Index (SWRPI) — official BFS data. Baseline Q4 2019 = 100. Returns quarterly index values tracking Swiss property prices since 2009. Covers all properties, single-family houses, and apartments separately.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | Property type to filter by: "all" (combined index), "houses" (single-family), "apartments" (condominiums/flats). Defaults to "all". | |
| from | No | Start period (inclusive). Format: "2020Q1", "2020-Q1", or just "2020". Defaults to earliest available (2009-Q4). | |
| to | No | End period (inclusive). Format: "2024Q4", "2024-Q4", or just "2024". Defaults to latest available. |
Implementation Reference
- src/modules/realestate.ts:155-244 (handler)Handler function for the get_property_price_index tool.
async function handleGetPropertyPriceIndex( args: Record<string, unknown> ): Promise<string> { const rawType = typeof args.type === "string" ? args.type.trim().toLowerCase() : "all"; const rawFrom = typeof args.from === "string" ? args.from.trim() : undefined; const rawTo = typeof args.to === "string" ? args.to.trim() : undefined; const validTypes = ["all", "houses", "apartments"]; if (!validTypes.includes(rawType)) { throw new Error(`Invalid type "${rawType}". Must be one of: all, houses, apartments`); } // Filter by from/to let data = [...SWRPI_ALL_DATA]; if (rawFrom) { const parsed = parseQuarter(rawFrom); if (!parsed) throw new Error(`Invalid from value: "${rawFrom}". Use format like "2020Q1" or "2020"`); data = data.filter( (d) => d.year > parsed.year || (d.year === parsed.year && d.quarter >= parsed.quarter) ); } if (rawTo) { const parsed = parseQuarter(rawTo); if (!parsed) throw new Error(`Invalid to value: "${rawTo}". Use format like "2024Q4" or "2024"`); data = data.filter( (d) => d.year < parsed.year || (d.year === parsed.year && d.quarter <= parsed.quarter) ); } if (data.length === 0) { throw new Error("No data available for the specified period range"); } // Build series based on type const series = data.map((d) => { const entry: Record<string, unknown> = { period: d.period }; if (rawType === "all") entry.index = d.index_all; else if (rawType === "houses") entry.index = d.index_houses; else entry.index = d.index_apartments; return entry; }); // Trend: compare latest to previous year same quarter const latest = data[data.length - 1]; const prevYear = data.find( (d) => d.year === latest.year - 1 && d.quarter === latest.quarter ); let latestIndex: number; let prevIndex: number | undefined; if (rawType === "all") { latestIndex = latest.index_all; prevIndex = prevYear?.index_all; } else if (rawType === "houses") { latestIndex = latest.index_houses; prevIndex = prevYear?.index_houses; } else { latestIndex = latest.index_apartments; prevIndex = prevYear?.index_apartments; } const trend = prevIndex !== undefined ? { change_yoy: parseFloat((((latestIndex - prevIndex) / prevIndex) * 100).toFixed(2)), change_yoy_label: `${latest.period} vs ${quarterToLabel(latest.year - 1, latest.quarter)}`, } : null; // Reference: fetch dataset metadata from CKAN for the source URL const datasetUrl = `https://opendata.swiss/en/dataset/${SWRPI_DATASET_ID}`; return JSON.stringify({ type: rawType, baseline: "Q4 2019 = 100", from: data[0].period, to: data[data.length - 1].period, latest_index: latestIndex, latest_period: latest.period, data_points: series.length, series, trend, note: "Swiss Residential Property Price Index (SWRPI). Baseline Q4 2019 = 100.", source: "Federal Statistical Office (BFS) — Swiss Residential Property Price Index (SWRPI)", source_url: datasetUrl, dataset_id: SWRPI_DATASET_ID, }); } - src/modules/realestate.ts:399-428 (schema)Schema definition for the get_property_price_index tool.
{ name: "get_property_price_index", description: "Get the Swiss Residential Property Price Index (SWRPI) — official BFS data. " + "Baseline Q4 2019 = 100. Returns quarterly index values tracking Swiss property prices " + "since 2009. Covers all properties, single-family houses, and apartments separately.", inputSchema: { type: "object", properties: { type: { type: "string", description: 'Property type to filter by: "all" (combined index), "houses" (single-family), ' + '"apartments" (condominiums/flats). Defaults to "all".', }, from: { type: "string", description: 'Start period (inclusive). Format: "2020Q1", "2020-Q1", or just "2020". ' + "Defaults to earliest available (2009-Q4).", }, to: { type: "string", description: 'End period (inclusive). Format: "2024Q4", "2024-Q4", or just "2024". ' + "Defaults to latest available.", }, }, }, }, - src/modules/realestate.ts:478-484 (registration)Dispatcher for the real estate tools, including registration of get_property_price_index.
export async function handleRealEstate( name: string, args: Record<string, unknown> ): Promise<string> { switch (name) { case "get_property_price_index": return handleGetPropertyPriceIndex(args);