File size: 962 Bytes
5d5de4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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
|