pyatl
Python strategies on algotradelib’s C++ backtest
This documentation was generated with the assistance of AI and may contain inaccuracies.
You write the strategy in Python; the replay, the fills and the costs run in algotradelib’s C++ engine.
import pandas as pd
import pyatl
class Hold:
def on_bar(self, ctx, bar):
ctx.target(bar.symbol, 10) # hold 10 shares, bought at the next bar's open
frame = pd.read_csv("bars.csv", parse_dates=["time"])
result = pyatl.backtest(Hold(), {"005930": frame}, commission=0.00015, sell_tax=0.002)
print(result.closing_equity, result.total_return, result.max_drawdown)Install
pyatl needs Python 3.12 or newer and an installed algotradelib; see its install guide. Then:
pip install git+https://github.com/algotradelib/pyatl.gitIf algotradelib is installed under a prefix CMake does not search, set CMAKE_PREFIX_PATH to that prefix. pyatl.algotradelib_version tells which library version a build was made against. NumPy is its only Python dependency; the examples read data with pandas, installed separately (pip install pandas).
Where to go next
- Get started: a first backtest, its result, and a replay you feed yourself.
- Reference: the functions and classes.
- Defining the replay sequence: rolling windows and resampled paths.
- Measures of your own: computing what the result does not report.
- algotradelib’s documentation: the C++ library underneath.
Status
Early. pyatl backtests Korean (KRX) stocks with target positions in whole shares. A position below zero needs shorts=True; no borrow is modelled. Other markets, limit orders and live trading are not supported yet.