Believable price data for trading UIs
Charting components need data that moves like a real market. This fake stock price generator builds a fictional ticker and a daily open-high-low-close series using a geometric random walk, so candlesticks rise and fall in realistic percentage steps instead of obvious straight lines.
How it works
The generator starts from your chosen price and walks it forward one trading day at a time. Each new close is the previous close scaled by a daily return drawn from your drift and volatility:
shock = random in [-1, 1]
dailyReturn = drift + volatility * shock
close[t] = close[t-1] * (1 + dailyReturn)
Open is set near the previous close, while high and low are spread around the open and close so each candle has a believable body and wicks. Volume is randomized within a plausible range. Export the full OHLC series as CSV or JSON.
Why geometric random walk?
A simple arithmetic random walk adds a fixed dollar amount each day, which means price can go negative — obviously wrong. A geometric random walk multiplies by a percentage, so moves are proportional to the current price. A 2% move on a $10 stock is $0.20; the same 2% on a $100 stock is $2.00. That proportionality is how real markets behave and why a geometric model produces much more convincing charts.
Worked example
Suppose you set a starting price of $100, volatility of 2%, and drift of 0.05% (a slight upward bias). For example:
- Day 1: shock = 0.8, daily return = 0.05% + 2% × 0.8 = 1.65%. Close = $100 × 1.0165 = $101.65.
- Day 2: shock = -0.4, daily return = 0.05% - 0.8% = -0.75%. Close = $101.65 × 0.9925 = $100.89.
- The open for Day 2 is set close to Day 1’s close; high and low bracket the open-to-close move.
Over 60 days with these settings the series will trend gently upward with realistic day-to-day variation, no impossible straight lines, and occasional down days that keep it looking authentic.
OHLC output fields
| Field | Description |
|---|---|
date | Trading day in YYYY-MM-DD format |
open | Opening price (near prior close) |
high | Intraday maximum |
low | Intraday minimum |
close | Closing price from the random walk |
volume | Randomised trading volume |
This shape maps directly to the input required by most candlestick charting libraries including Lightweight Charts, Recharts, and Apache ECharts.
Tips and examples
- Keep volatility low (around 1 to 2 percent) for a calm large-cap feel, or raise it to 4 to 6 percent for a volatile small-cap look.
- Add a small positive drift to show an uptrend or a small negative drift for a declining chart.
- Use the JSON export to feed candlestick libraries directly; use CSV for spreadsheets and to verify your OHLC import pipeline.
- Generate two or three fictional tickers with different starting prices and volatilities to test a comparison chart with multiple series on one axis.