"""Fake-but-controlled markets with a known 'personality', returned as daily Open/High/Low/Close.
The day is simulated forward in small steps, so the Close is simply where the day's path ENDS.
(An earlier version drew the close first and fitted a path to it; that leaked information
into High/Low and made an open-breakout rule look profitable on pure noise.)"""
import numpy as np, pandas as pd

def make_market(kind, seed, days=1500, strength=1.0, sigma=0.01, steps=600):
    rng = np.random.default_rng(seed)
    noise = rng.normal(0, sigma / np.sqrt(steps), (days, steps))      # intraday shocks
    shocks = rng.normal(size=days)
    o = np.empty(days); h = np.empty(days); l = np.empty(days); c = np.empty(days)
    x, m = 0.0, 0.0                                   # x = log price, m = slowly-changing 'mood' (trend markets)
    kappa, phi, sd_m = 0.05 * strength, 0.98, 0.0008 * strength
    for t in range(days):
        if kind == "trend":
            m = phi * m + sd_m * np.sqrt(1 - phi**2) * shocks[t]
            drift = m                                  # today's expected move
        elif kind == "revert":
            drift = -kappa * x                         # pulled back toward fair value (log price 0)
        else:
            drift = 0.0
        path = x + np.cumsum(drift / steps + noise[t])
        o[t], c[t] = np.exp(x), np.exp(path[-1])
        h[t], l[t] = np.exp(max(x, path.max())), np.exp(min(x, path.min()))
        x = path[-1]
    idx = pd.bdate_range("2015-01-01", periods=days)
    return 100 * pd.DataFrame({"Open": o, "High": h, "Low": l, "Close": c}, index=idx)
