Heat of the Market

Arpit Bhayani

curious, tinkerer, and explorer


Question

In a rapidly developing city, house prices change over time based on their neighborhood’s influence. The city can be represented as an N×N grid, where each cell represents a property with a certain price.

The price evolution of each house is influenced by:

  1. Its neighboring house prices (spatial component)
  2. A constant appreciation rate α (temporal component)
  3. A development factor β that represents local infrastructure improvements

The price P(x, y, t) at position (x, y) at time t follows standard diffusion.

Given the following inputs,

  • N: grid size
  • Initial price configuration P₀(x, y)
  • Number of years T to simulate
  • α (price diffusion coefficient)
  • β (development factor)

Simulates the price evolution over 10 years and output

  • the average price across the city
  • the maximum and minimum prices
  • [extension] a heatmap showing the price distribution

Input

N = 50  # 50x50 grid
T = 5   # Simulate for 5 years
alpha = 0.2  # Diffusion coefficient
beta = 0.05  # Development factor

# Initial condition: central high-price district
P0 = np.zeros((N, N))
P0[20:30, 20:30] = 1000000  # Million-dollar properties in center
P0[0:10, 0:10] = 500000     # Another wealthy area

Solution

Here’s the code for reference and some notes on the solution below.

This simulation models how house prices spread and evolve across a city using principles similar to heat diffusion in physics. The key ideas are:

  • Prices tend to influence nearby areas (diffusion effect)
  • There’s natural price growth over time (development factor)
  • Different initial conditions represent different city features

The code uses what’s called a reaction-diffusion equation:

dP/dt = α∇²P + βP

where:

  • P is the price at each location
  • α (alpha) is the diffusion coefficient - how quickly prices influence nearby areas
  • β (beta) is the development factor - natural price growth rate
  • ∇²P (Laplacian) measures how different a price is from its neighbors

initial city layout:

P0[20:30, 20:30] = 1000000  # A central expensive district
P0[0:10, 0:10] = 500000     # A secondary wealthy area
P0 += 200000 * X            # Prices increase from left to right

This creates:

  • A high-price downtown area ($1M)
  • A secondary wealthy district ($500K)
  • A general price gradient where east is more expensive than west

So, to see how the prices evolve over time, we divide time into small steps (dt = 0.01 years) and for each step:

  • Calculates how different each location’s price is from its neighbors (Laplacian)
  • Updates prices based on both diffusion (spreading) and development (growth)
  • Stores the state at the end of each year

Post computing everything we output the required stats and visualize the price distribution.

Arpit Bhayani

Creator of DiceDB, Staff Engg at Google Ads and Dataproc, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses


Arpit's Newsletter read by 125,000 engineers

Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.