Examples
Runnable examples, from simplest backtest to full production setups
Every example is a full working Python file you can copy, paste, and run. Ordered from simplest to most advanced.
Start here
Simplest backtest The minimal 20-line backtest. Shows the core pattern. Equity mean reversion Bollinger mean reversion with Kelly sizing + moderate risk.
Code along
Step-by-step tutorials that walk through every line. Start here if you want to understand how the pieces fit together.
MA Crossover Build a classic fast/slow moving average strategy from scratch. Manual Orders Place orders by hand with hz.connect(). No pipeline needed. Portfolio Control Compare sizers, set constraints, control how signals become positions. Multi-Asset Basket Trade equities and prediction markets in the same backtest. Custom Risk Setup Configure stops, drawdown guards, and circuit breakers step by step. Mixed-Asset Portfolio Equities + prediction markets + perps in one portfolio. Adaptive Portfolio A sizer that reads its own drawdown and adjusts sizing dynamically. Multi-Asset Fund 12 markets, 4 strategies, 3 asset classes, custom sizer, and validation. Full System Custom strategy + real sizing + layered risk + validation.
Strategy recipes
Focused examples for specific patterns.
Trend following MovingAverageCross + TSMomentum ensemble. Multi-strategy Four strategies simultaneously with unified portfolio optimization. Regime stress test Strategy behavior across trend/chop/crash regimes. Strict risk Tight stops + stacked drawdown guards.
Live broker
End-to-end research + paper trading + real-network verification against an actual broker.
Extending Horizon
Imperative API Direct order placement without the pipeline. Custom feature Write your own indicator. Custom strategy Subclass Strategy with custom signal logic. Behavioral audit The invariants the test suite verifies.
Running the examples
All examples assume the Horizon package is on your PYTHONPATH:
bash
cd /path/to/profit/new
PYTHONPATH=. python3 my_example.py
Most examples use synthetic data with fixed seeds, so output is deterministic and no API keys are needed.