Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-ollama-crontab/llms.txt

Use this file to discover all available pages before exploring further.

backtest-ollama-crontab is a TypeScript monorepo demonstrating how to wire a local Ollama LLM (gpt-oss quantized) into an algorithmic trading pipeline as an outline-based risk filter. It ingests signals from a public Telegram channel, asks the LLM whether each signal is safe to trade, and measures the impact on P&L via a full backtest harness. In a January 2026 backtest on the same signal set, the LLM gate improved total P&L from +52.22% → +68.90%, raised winrate from 68% → 82%, and improved Sharpe from 0.309 → 0.512 by vetoing 6 signals — 4 of which were losers.

Quickstart

Build the workspace, authenticate Telegram, and run your first backtest in minutes.

Architecture

Understand the five-stage pipeline: Crawl → Parse → Risk Outline → Strategy → Cron.

Risk Outline

The LLM prompt, two empirical rules, and the Zod-validated response contract.

Backtest Results

Full trade logs and statistics: with and without the Ollama gate.

How It Works

The pipeline has five stages, each in a dedicated service:
1

Crawl

A Telegram MTProto client (CrawlerService) pulls raw messages from the configured public channel and upserts them into the parser-items MongoDB collection.
2

Parse

CryptoYodaScreenService runs regex extraction over each message to pull out direction, entry, targets, and stoploss, storing structured rows in parser-items.
3

Risk Filter

SignalJobService feeds every unvisited parser-items row through SignalLogicService, which calls the RiskOutline — an Ollama-backed agent-swarm-kit outline that applies two empirical rules and returns a riskAction: "skip" | "follow" verdict stored in screen-items.
4

Strategy

jan_2026.strategy.ts reads screen-items and only opens a position when riskAction === "follow" and the current price is inside the signal’s entry zone. TP = targets[2], SL = signal.stoploss.
5

Crontab

Two Cron.register calls handle scheduling: a 15-minute live poller re-ingests the channel every quarter-hour in live mode; a one-shot backtest preparer crawls the full frame at startup in backtest mode.

Key Features

Local LLM Risk Filter

gpt-oss quantized via Ollama evaluates every signal using pre-computed avgRangePct and momentum24hPct metrics — no cloud API required.

15-Minute Live Crontab

Cron.register with interval: "15m" polls the Telegram channel continuously, keeping parser-items fresh without manual intervention.

Two Empirical Rules

Sleeping-coin SHORT veto and knife-catching LONG veto are embedded in the LLM system prompt and tunable without recompiling any packages.

Full Backtest Harness

Replay a full month of signals against Binance OHLCV data using backtest-kit, with per-trade PnL, drawdown, Sharpe, and profit factor.

Zod-Validated Responses

The LLM response is validated against a Zod schema with five fields and five custom validators before being persisted to screen-items.

DI Service Architecture

di-factory wires CrawlerService, ParserService, SignalJobService, and more — each independently testable and replaceable.

Quick Navigation

Environment Variables

All CC_* env vars with defaults and purpose.

Infrastructure

Docker Compose for MongoDB and Redis.

Telegram Auth

QR-code MTProto session setup.

Crawler

How messages are fetched from Telegram.

Parser

Regex-based signal extraction format.

Crontab

Live and backtest scheduling with Cron.register.

Build docs developers (and LLMs) love