Skip to content

Repository files navigation

varsity-algo

CI License: MIT Python 3.11+

A trading-signal scanner for the Indian market that you can actually run. Describe a strategy in plain English, scan the Nifty universe, and review every order before it is placed.

This is the system from Zerodha Varsity's Build a Trading Algo with AI — No Coding Required, built end to end and built safely.

It follows the video's flow — log in with your API key, API secret and request token, see your account, then generate signals with Short SMA, Long SMA, Lookback and Max — and adds the parts the video leaves out.

Connect Zerodha and prices come from Kite, exactly as in the video. Without it the scanner still runs on free end-of-day data, so you can try everything before paying for anything.


Watch the setup tutorial

Tutorial

Download the tutorial (5 min, narrated) — or docs/varsity-algo-tutorial.mp4 in the repo.

Install, first scan, building a strategy from English, and the order guardrails. Narrated end to end. Every frame is the real application — the strategy you see being built from "golden cross on the nifty 500 but only if RSI is under 70" was produced live by a 7B model running locally with no API key.


Install

Windows — download the repo, then double-click start.bat.

macOS / Linux

git clone https://github.com/sachincse/varsity-algo
cd varsity-algo
chmod +x start.sh && ./start.sh

That is the whole thing. The script checks for Python and Node, creates a virtual environment, installs everything, builds the dashboard, and opens http://localhost:8000. Re-running it is fast.

You need Python 3.11+ (tick "Add python.exe to PATH" on the first installer screen) and Node 20.19+ or 22.12+. If Node is missing the app still runs — you just get the API instead of the dashboard.

Full walkthrough, including every error message and its fix: docs/SETUP.md.


What it does

Connect Connect — the video's login page: API key, API secret, request token. Credentials typed here stay in memory; put them in .env and only the token is needed each morning.
Account Account — the video's user tab: user ID, name, products and exchanges from the Kite profile API, plus holdings and funds. Settings lists every model option and which price source is live.
Strategy Strategy — type the rule the way you would say it. The model fills a fixed schema; it never writes or runs code.
Signals Signals — Short SMA, Long SMA, Lookback and Max, then a table ranked by crossover recency showing the close beside both moving averages, so you can check a signal by eye.
Orders Orders — signals become a sized order sheet. Placement is off by default and every order needs its own confirmation.

The language model is optional, and free

Only used to turn English into a strategy. Pick one, put it in .env, restart.

Free, no credit card

Provider .env Get a key
Groq LLM_PROVIDER=groq
GROQ_API_KEY=…
console.groq.com/keys
Google Gemini LLM_PROVIDER=gemini
GEMINI_API_KEY=…
aistudio.google.com/apikey
OpenRouter LLM_PROVIDER=openrouter
OPENROUTER_API_KEY=…
openrouter.ai/keys

Free and fully offline — no key, no account, nothing leaves your machine

# install from https://ollama.com/download
ollama pull qwen3:8b
LLM_PROVIDER=ollama
LLM_MODEL=qwen3:8b

The tutorial video was recorded this way. A 7B model handled "golden cross on the nifty 500 but only if RSI is under 70" correctly, on a laptop, for nothing.

Twelve providers are supported in total — Anthropic, Groq, OpenRouter, Gemini, Together, DeepSeek, Fireworks, Cerebras, Mistral, xAI, Ollama, LM Studio, plus any OpenAI-compatible endpoint. Claude uses its official SDK; the rest share one adapter.

Model IDs rot fast. Groq retired every Llama chat model in August 2026. If you see "provider does not know this model", set LLM_MODEL to a current one — no code change needed.


What is different from the video

The AI writes code and then runs it. A model that can emit arbitrary Python into a process holding your broker access token is a remote-code-execution path with a natural-language prompt as its input. Here the model fills a closed schema (core/nl.py) which compiles into a validated strategy (core/spec.py). Asking it to add a shell_command field returns Extra inputs are not permitted.

₹500/month before you can look at anything. Kite is used the moment you connect — same data, same broker, same chart. But you are not blocked until then: without a session the scanner falls back to free end-of-day data, so you can decide whether it is worth paying for.

Nothing checks the signals are honest. 44 tests, and the important ones try to prove the engine cannot see the future: truncate the input and signals must be unchanged; replace every bar after date T with noise and everything up to T must be bit-identical.

Bullish and bearish are presented symmetrically. A retail account cannot hold a short equity position overnight in India, so a bearish crossover is an exit for something you already own, never a trade.


Does the strategy make money?

No, and you should know that before building on it. SMA(6)/SMA(30) on the Nifty 100, 2011–2026, next-open fills, full Zerodha charges, 25 bps slippage, and a point-in-time universe:

CAGR
SMA 6/30, honestly tested 1.92%
Nifty 100 total-return index, net of fees 10.70%
Same universe, no timing rule at all 11.90%

It also sits at the 28th percentile of a random-entry null with the same trade count and holding periods. 95% of gross trading gains went to charges, and 67% of the remaining profit was dividends the strategy did nothing to earn.

The scanner is a useful lens on what is moving. It is not a reason to trade.


Safety model for orders

Placing an order is the only irreversible thing this program does, so it sits behind four locks:

  1. ENABLE_TRADING=true in .env — a deliberate act in a text editor
  2. a preview that mints a one-time token bound to the exact symbol, side, quantity and product
  3. that token expiring after three minutes, because the prices behind it go stale
  4. a browser confirmation naming the order

Orders go one at a time. There is no "place all".


Layout

core/     spec.py (the DSL) · nl.py (English → spec) · engine.py (causal
          indicators) · data.py (yfinance or Kite)
server/   FastAPI; serves /api and the built SPA from one process
          kite_client.py · jobs.py · llm/ (12 providers) · routes/
web/      React + Vite dashboard
tests/    44 tests, mostly attempts to break the causality guarantee
tools/    record_app.py · narration.py · build_video.py — the tutorial
          video is generated from source, not hand-edited
docs/     SETUP.md · API_SPEC.md · the tutorial video

Development

python -m pytest tests/ -q          # 44 passed
cd web && npm run dev               # hot-reload frontend on :5173
python -m uvicorn server.main:app --reload --port 8000

Rebuild the tutorial video (needs ffmpeg):

python tools/record_app.py --out build/clips   # drive the real app
python tools/build_video.py --revoice          # narrate, edit, encode

The narration script lives in tools/narration.py and is spoken by a free neural voice via edge-tts — no API key. Narration drives the edit: each segment is stretched to fit its line rather than the line being squeezed into a duration chosen in advance. Change VOICE for a different accent.

Licence

MIT — see LICENSE. Not financial advice. You are responsible for every order you approve.

About

The Zerodha Varsity 'build a trading algo with AI' video, built end to end and built safely. FastAPI + React + Kite Connect. The LLM fills a validated schema instead of writing code. Works with 12 providers including a local model with no API key.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages