Skip to main content

pyatl

Python strategies on algotradelib’s C++ backtest

WarningAI-generated documentation

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.git

If 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

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.