1D CNN (Sequence)
Reads the last 60 raw OHLCV candles like an image.
A small AI model that looks at the last 60 days of prices like a picture and learns to spot familiar shapes — breakouts, coils, head-and-shoulders. It doesn't know the names of these patterns, it just notices the ones that tend to come before big moves.
A 1D convolutional neural network that reads the last 60 days of OHLCV like an image and outputs an expected return. CNNs are translation-invariant by design — meaning the same pattern at the start, middle, or end of the window gets recognised. It learns recurring chart shapes (breakouts, coils, head-and-shoulders) without anyone telling it what they are.
Conv1d → GAP → linear · trained on shape, not features
Real 1D CNN (Sequence) bot, running on real Yahoo data when the symbol is available. Drag the params — the bot re-runs instantly.
This is the actual code the bot runs — not a re-explanation, not a simplified version. Whatever ships here is what executes when you press Run All in the workbench. Read it, copy it, fork it, build a better one.
const sequenceCnn: BotDef = aiBot<DirReq, SeqRes>(
{
id: "ai-sequence",
name: "1D CNN (Sequence)",
category: "ai",
glyph: "▰",
tagline: "Reads the last 60 raw OHLCV candles like an image.",
formula: "Conv1d → GAP → linear · trained on shape, not features",
endpoint: "/api/sequence",
module: "ai quants/models/sequence/train.py",
params: [
{ key: "lookback", label: "Lookback (bars)", kind: "number", default: 60, min: 30, max: 120, step: 1 },
],
},
{
request: dirRequest,
build: (data) => {
const pred = data.expected_return;
return {
signals: [],
metrics: [
{ key: "pred", label: "20d return", value: `${(pred * 100).toFixed(2)}%`, tone: pred > 0 ? "bull" : "bear" },
{ key: "dir", label: "Direction", value: data.direction.toUpperCase(), tone: data.direction === "up" ? "bull" : "bear" },
{ key: "lookback", label: "Window", value: "60d OHLCV" },
{ key: "model", label: "Architecture", value: "Conv1d → GAP → Linear", tone: "info" },
],
summary: `1D CNN reads the last 60 bars and outputs ${(pred * 100).toFixed(2)}% expected 20d return.`,
beginner:
"We treat the last 60 days of price data like an image and run a small convolutional network across it.",
verdict: {
side: pred > 0.015 ? "buy" : pred < -0.015 ? "sell" : "hold",
text: `CNN sees a ${(pred * 100).toFixed(2)}% setup over the next 20 days.`,
confidence: Math.min(1, Math.abs(pred) * 15),
},
};
},
mock: (ctx, p) => {
const lookback = num(p, "lookback", 60);
const px = closes(ctx.candles);
const trend = trendStrength(px);
const seed = hashStr(ctx.symbol + "cnn" + lookback);
const rand = seedRand(seed);
const pred = trend * 0.5 + (rand() - 0.5) * 0.04;
return {
signals: [],
metrics: [
{ key: "pred", label: "20d return", value: `${(pred * 100).toFixed(2)}%`, tone: pred > 0 ? "bull" : "bear" },
{ key: "dir", label: "Direction", value: pred > 0 ? "UP" : "DOWN", tone: pred > 0 ? "bull" : "bear" },
{ key: "lookback", label: "Window", value: `${lookback}d OHLCV` },
{ key: "shape", label: "Detected pattern", value: trend > 0.05 ? "uptrend" : trend < -0.05 ? "downtrend" : "chop", tone: "info" },
],
summary: `1D CNN (TS mock) suggests ${(pred * 100).toFixed(2)}% over 20d.`,
beginner: "We treat the last 60 days of price data like an image and run a CNN.",
verdict: {
side: pred > 0.015 ? "buy" : pred < -0.015 ? "sell" : "hold",
text: `CNN sees a ${(pred * 100).toFixed(2)}% setup over the next 20 days.`,
confidence: Math.min(1, Math.abs(pred) * 15),
},
};
},
},
);id— unique key the workbench uses to find the bot.params— the sliders + inputs you see on the cell.run(ctx, p)— the function that gets called with candles + your params and returns the verdict.verdict— the BUY / SELL / HOLD pill at the top of the cell.metrics— the small stat boxes shown in the cell body.
- Copy the whole block above.
- On /quant, click + Import your bot in the bot library.
- Paste, hit save. It hot-loads into your workspace.
- Edit any param defaults or logic to your taste — it's now yours.
- ·Pattern-driven traders. The CNN is essentially an automated chartist. It picks up on shapes that human eyes also notice but can't formalise.
- ·Short-to-medium horizon (~20 days). The 60-bar window naturally caps how far back it can look.
- ·Pairs nicely with classical indicators — the CNN catches what RSI/MACD don't.
- ·Slow-moving fundamentals. The network can't see beyond 60 bars; it's blind to anything older.
- ·Noisy intraday data. Designed for daily bars; minute data is too noisy for 60-step convolutions.
- ·Names with little visual structure (treasuries, low-vol utilities). Not enough shape variation.
BUY when expected return > +1.5%, SELL when < -1.5%, HOLD in between. The 'detected pattern' chip (uptrend / downtrend / chop) is a sanity-check label, not a formal classifier output — it's derived from recent trend strength.
This bot tries to call the FastAPI service first. When it's up, you get real model output. When it's down, the bot transparently falls back to a deterministic TS surrogate.
cd "ai quants" && uvicorn serve:app --reload --port 8000Why CNN instead of LSTM?+
What does the model see, exactly?+
Attention over a full year of OHLCV. Spots seasonality + regime.
Will the stock be up or down 20 days from now? GBM ensemble vote.
Predicts the size of the next 20-day move, not just the sign.
All AI quants vote. Tier emerges from agreement, not opinion.
Honest confidence interval — not just a point prediction.