Your first FLOX backtest¶
This tutorial gets you from a clean Python environment to a backtest running on real BTC 1m data. Three commands.
Prerequisites¶
- Python 3.10+
piponPATH
1. Install¶
The wheel includes the compiled C++ engine and a flox console script.
2. Scaffold a project¶
flox new writes main.py, requirements.txt, a README, and a
data/btcusdt_sample.csv with 500 real BTC/USDT 1-minute bars
(timestamp,open,high,low,close,volume). The default template is
research: a single-file SMA(10/30) crossover.
3. Run¶
Output:
backtest on btcusdt_sample.csv
return : -1.2103%
trades : 187 win=66.3%
sharpe : -4.5746
max DD : 1.5030%
net PnL: -121.0296
That is the actual result of an SMA(10/30) crossover on 500 minutes of BTC. 66% of trades closed in the green, but small wins do not pay for fees and the few losers — net result is a 1.2% drawdown. Useful as a sanity check and a baseline; also useful as a reminder that "SMA crossover" is not a strategy.
The strategy class¶
main.py is one file. The class you edit:
class my_strategy_strategy(flox.Strategy):
def on_trade(self, ctx, trade):
fv = self.fast.update(trade.price)
sv = self.slow.update(trade.price)
if fv is None or sv is None or not self.slow.ready:
return
if fv > sv and ctx.is_flat():
self.market_buy(0.01)
elif fv < sv and ctx.is_flat():
self.market_sell(0.01)
Use your own data¶
Set MY_STRATEGY_DATA (the env-var prefix is the upper-cased project
slug + _DATA) to a CSV with the same columns:
Next steps¶
- Replace the SMA crossover with your own indicators (Indicator Graph).
- Parameter sweep via Grid Search.
- Run the same class against a live exchange: Connect FLOX to a CCXT exchange.
- Longer hand-built version (without the scaffolder): Python quickstart.