PranavSharma's picture
initial commit
5d5de4c verified
raw
history blame contribute delete
962 Bytes
import numpy as np
import pandas as pd
def generate_synthetic_sku(
n_periods: int = 52,
base_price: float = 10.0,
base_demand: float = 120.0,
elasticity: float = -1.5,
noise_std: float = 0.1,
seed: int = 42,
) -> pd.DataFrame:
"""
Generate a single-SKU synthetic price–demand time series.
Elasticity is constant and known (ground truth).
"""
rng = np.random.default_rng(seed)
# price variation around base price
prices = base_price * (1 + rng.normal(0, 0.15, size=n_periods))
prices = np.clip(prices, base_price * 0.6, base_price * 1.4)
# demand model: q = A * p^elasticity * noise
noise = np.exp(rng.normal(0, noise_std, size=n_periods))
demand = base_demand * (prices ** elasticity) * noise
df = pd.DataFrame(
{
"t": np.arange(n_periods),
"price": prices,
"qty": demand,
}
)
return df