Evolve trading strategies with AI while you sleep, then make them pass an exam they cannot cheat.
pip install alphafinch==0.1.0 Copy PIP instructions
Works with Claude Code, Anthropic, OpenAI, Ollama, any OpenAI-compatible server, or no AI at all.
AlphaFinch is an AlphaEvolve-style lab for markets. An AI writes trading strategies as short Python functions, backtests them, and breeds the fittest: mutating them, crossing them and letting populations evolve on separate islands.
The catch with every AI trading demo: evolution is the best overfitting machine ever built. Run it long enough and it will "discover" a brilliant strategy in pure noise. AlphaFinch is built around that problem. The most recent years are locked in a sealed exam that neither evolution nor the AI ever sees, and the bar to pass accounts for every attempt.
Most runs end with nothing passing. That's the honest answer, and the point.
We pre-registered every test before running it (docs/) and report every result.
Quiet Sector Tether buys, within each sector, the stocks that move least with the market and shorts those that move most. It is essentially "betting against correlation", an anomaly published by AQR researchers in 2020: the AI rediscovered it from pre-2017 US data, and it held up in the UK, the Eurozone, Japan, Hong Kong, Australia, Canada and Korea. It survives higher trading costs (t 2.94 at 15 bps), a causal beta hedge (t 3.22) and the six standard Fama–French factors (alpha +2.5%/yr, t 2.64).
The caveats are in the full write-up: it is weaker in 2020–26 alone (t 2.17), short-borrowing fees aren't modelled, and Korea banned short selling for parts of the period. It's frozen in forward/ to be judged again on data that doesn't exist yet.
Needs Python 3.10+. No API keys or data subscriptions: market data is free and downloaded on first use.
pip install "alphafinch[all] @ git+https://github.com/shloksobti/alphafinch" alphafinch demo # offline: synthetic market, no AI, no network (~1 min) alphafinch evolve india # NIFTY 200 stocks; AI provider auto-detected alphafinch evolve india --long-only # same, but no shorting (cash market) alphafinch evolve india-futures # NSE futures: NIFTY, BANKNIFTY, every F&O stock alphafinch evolve futures # 39 global futures: indices, bonds, FX, commodities alphafinch holdings runs/ /champion.py india # what the champion wants to hold today alphafinch world-exam runs/ /champion.py # test it on 7 markets it has never seen alphafinch replay runs/ # re-watch a finished run as a short story Two choices shape every run: the market (a plain word, e.g. india) and the rules (flags, e.g. --long-only). Type alphafinch alone for an overview, alphafinch evolve -h for every option, or read the guide.
What a run takes. The default run (20 generations × 4 islands) makes a few hundred AI calls and takes roughly 20–40 minutes. The first run on a market also downloads its data (a few minutes, then cached). With claude-code it uses your existing subscription; with an API key you pay your provider's usual rates.
alphafinch replay runs/ re-tells any finished run as a short story:
breed ─▶ choose ─▶ 🔒 sealed exam ─▶ 🌍 world exam ─▶ ⏳ forward test Breeding. Four islands, each with a population of strategies. Every generation the AI mutates a parent using its report card, crosses two parents into one idea, or invents an immigrant from a fresh hypothesis. No-AI operators tweak a constant or blend two portfolios. Champions migrate between islands, and each island keeps the best strategy in every niche (fast or slow, market-neutral or market-hugging), so the population can't collapse onto one idea.
Fitness rewards a real edge, not a lucky one:
The AI works like a researcher. Every strategy starts with a written hypothesis. A lab notebook of every idea tried, and how it fared, goes into each prompt. A toolkit (tk) makes sector-neutral long/short books, residual returns and volatility targeting one-liners. Use --strong-model to give crossovers and new ideas to a bigger model.
Choosing the champion. The last three training years are held back from breeding. The top ten finalists and a diversified team are scored once on those years, and the best becomes the champion. The AI never sees those scores.
The sealed exam. The most recent three years. Each attempt reveals only PASS or FAIL, and the bar is t⁻¹(α / attempts), valid however adaptively the search ran (the theory). Results are graded PASS, PROMISING (t > 1, with the years of data a pass would need) or FAIL.
The world exam. Three years of one market can rarely prove a realistic edge. So a frozen strategy runs unchanged on seven other markets, and the evidence is pooled. The verdict uses the lower of two pooled t-statistics (Newey–West and Stouffer), so a strategy has to convince both. Calibrated with placebos: 0 of 200 random strategies passed.
The forward test. alphafinch forward freeze runs/ today, alphafinch forward score in six months. No model has seen tomorrow's data.
Two choices shape every run: the market (what can be traded) and the rules (how). Rules are enforced by the engine on every strategy's positions, so a strategy can't break them and still look good, and the AI is told them up front.
Futures markets get futures rules automatically: shorting is as easy as buying, up to 3× exposure.
Free continuous futures prices fake big gains or losses at every contract roll: on Yahoo's natural-gas series a rolled position "earned" +20% a year when it really lost 12%. So AlphaFinch builds futures from funds that hold and roll the real contracts (and Indian stock futures from each stock's total return), converted to excess returns over the short-term interest rate, which is what a futures position earns.
--provider auto (the default) uses the first one it finds. A Claude Code skill is included in integrations/claude-code.
Or use your own list: --tickers RELIANCE.NS,TCS.NS,INFY.NS (any Yahoo symbols).
Strategies see prices plus data.open/high/low/volume, data.sector, data.macro (VIX, index, oil, gold, rates and more) and, for the US, data.fund (market cap, earnings yield, book-to-market, ROE, sales growth).
US fundamentals need a contact email, because the SEC asks every client for one: export ALPHAFINCH_SEC_CONTACT="Your Name you@example.com".
def strategy(prices, data): """Sector Spread: sector-neutral 6-month momentum. Hypothesis: news diffuses slowly within industries.""" score = tk.neutralize(tk.zscore(prices.pct_change(126)), data.sector) return tk.rebalance(tk.long_short(score, q=0.2), every="M") A strategy returns, for every day, the fraction of capital to hold in each asset (negative means short). It may use numpy, pandas, math and the built-in toolkit tk, must never use future data, and may not name tickers. The guide lists every field and toolkit function.
alphafinch backtest my_strategy.py us # training years only; the sealed years stay sealed alphafinch holdings my_strategy.py us # what it wants to hold after the latest close alphafinch world-exam my_strategy.py # 7 stock markets it has never seen FAQ Will this make me money? Probably not, and AlphaFinch is built to tell you so. A PASS is a lead worth researching, not a trading signal.
Why not just backtest on all the data? With enough tries, something always worked by luck. Only data the search never touched can tell luck from skill.
Can I re-run until something passes? You can, but then the exam means nothing. Count your earlier looks (--alpha, --prior-looks) or test on new markets and new data.
Does it tell me what to buy? alphafinch holdings shows the positions a strategy wants today. That's the output of a research tool, not a recommendation: check the exam verdict and the caveats first.
Can I use my own data? Any Yahoo symbols with --tickers. Other sources can be added in alphafinch/data.py, which returns a simple Panel of aligned tables.
git clone https://github.com/shloksobti/alphafinch && cd alphafinch pip install -e ".[all,dev]" pytest -q # about 40 tests, offline, under a minute Issues and pull requests are welcome: new markets, data sources, toolkit functions and exams especially.
Shlok Sobti, Deflate by Bits, Not Trials, SSRN 7557458 (2026). papers.ssrn.com/abstract=7557458
Built by Shlok Sobti at Invsify, a SEBI-registered investment advisory in India. AlphaFinch is an independent open-source research project: nothing in this repository is investment advice or a recommendation from Invsify.
Research and educational software. Backtests ignore taxes, capacity limits and slippage beyond the modelled costs; borrow fees are charged only under --market-neutral.
agents alphaevolve backtesting evolution llm quant trading
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.




