Skip to main content

BacktestResult

BacktestResult(
    bars,
    fills,
    equity,
    opening_equity,
    closing_equity,
    halted,
    total_return,
    sharpe,
    annualized_sharpe,
    max_drawdown,
    sortino,
    turnover,
    commission_paid,
    tax_paid,
    slippage_paid,
    rejected,
    refused,
    unfilled,
    gaps,
    unvalued_bars,
    lowest_cash,
    aborted,
    overdrawn_bars,
    unchecked_fill_causality,
    market_price_rule,
    market_fills_by_rule,
    expired_day_orders=None,
    multiple_instruments=None,
    cost_totals_incomplete=None,
    volume_ignored=True,
    bar_tape_unverified=True,
    sellable_is_whole_holding=True,
    buying_power_is_ledger_cash=True,
    periods_per_year=math.nan,
)

What one replay produced.

fills, equity, rejected and refused are dicts of columns (pandas.DataFrame(result.fills) makes a table). Times are ns since the epoch (UTC). halted says why the replay stopped early, if it did; the figures then cover only what ran. Figures are NaN where the library has none. A result saved before a field existed loads with that field’s default: None for a count or flag it did not report, True for the four constant cautions (they held for every replay), NaN for periods_per_year; it keeps the annualized_sharpe it saved.

Attributes

Name Type Description
bars int Bars replayed.
fills dict of str to array One row per fill: time, symbol, side (“buy” or “sell”), order_id (the id the replay gave the order that filled; each replay numbers its own), tag (the order’s tag: “pyatl” for an order from Context.target), quantity, price (slippage included), commission, tax (sale tax, KRW) and slippage (the price per share given up to slippage, already in price).
equity dict of str to array The equity curve: time, equity, and period_return, the library’s return since the previous point (rounded to eight places), the series its Sharpe and Sortino are computed from. A return is NaN on the first point, after an unvalued bar, after a point with equity at or below zero, and where the exact arithmetic fails; if equity was at or below zero before the last point, the library reports no Sharpe or Sortino at all.
opening_equity, closing_equity str Equity at the first and last point, as exact decimal text; empty when the curve has no point.
halted str or None Why the replay stopped early, or None.
total_return, max_drawdown float The return over the run and the largest fall from a peak, as fractions (0.05 is 5 %).
sharpe, sortino float Per period of the equity curve (one bar’s interval), not annualized.
annualized_sharpe float sharpe times the square root of periods_per_year, a rule that assumes serially uncorrelated returns; NaN when there is no count. sharpe, per period, is reported either way.
turnover float Everything traded (buys and sells, quantity x price) divided by the opening equity, over the whole run.
commission_paid, tax_paid, slippage_paid float Costs over the run, KRW; NaN where the library cannot state a total.
rejected dict of str to list Targets the runner could not turn into an order: symbol and reason (the library’s name).
refused dict of str to list or array Orders the risk guard refused: symbol and reason (lists; the reason is the library’s name), and, as arrays, the limit exceeded and the value attempted, in the reason’s own unit (shares for quantity_not_sellable), NaN where the reason has none.
unfilled int Orders still waiting when the replay ended.
gaps int Bars that did not follow the bar before them; nothing is interpolated across a gap.
unvalued_bars int Bars at which the equity could not be valued exactly (a total too large for an exact decimal); such a bar has no point in equity. The library’s own figures leave the next period’s return out; a return computed between two exported points would span the missing bar. Check it is 0 before computing measures from equity per period.
lowest_cash float The lowest cash (KRW) an execution left, if an execution took cash below zero; NaN otherwise, which includes a run that started below zero and executed nothing. Short sale proceeds count as cash, so leverage through shorts does not show here (see shorts).
aborted int Orders cleared when the replay halted, apart from unfilled.
overdrawn_bars int Input bars that ended with cash below zero (with several symbols, one per symbol’s bar); short sale proceeds count as cash, as for lowest_cash.
unchecked_fill_causality int Decisions to fill an order against a bar that the engine could not check were made before that bar (for example with weekly, monthly or yearly bars stamped at their close). Counted when the order is matched to the bar, before it is priced, so it is not a count of fills.
market_price_rule str The configured market-price rule: “decision-close” or “next-close” when the replay was made with that fill, empty under the default (the next bar’s open).
market_fills_by_rule int Fills that rule priced; 0 under the default.
expired_day_orders int or None Orders withdrawn unfilled when their trading session ended, as a day order expires live: for example a “decision-close” order whose symbol had no price yet and whose next daily bar has no open.
multiple_instruments bool or None Whether more than one symbol executed: the library’s caution about survivorship bias. A universe chosen from today’s listings leaves out names delisted during the period, which flatters the result; the library cannot see how the symbols were chosen, so a hand-picked list sets it too.
cost_totals_incomplete bool or None Whether some cost could not be summed exactly (amounts far beyond any real account, such as a huge min_commission); commission_paid, tax_paid and slippage_paid are then NaN.
volume_ignored bool Always True: fills are never capped by traded volume, and queue position, market impact and borrowing are not modelled, so a result says nothing about how much capital the strategy can take.
bar_tape_unverified bool Always True: bars carry no venue, so the replay cannot know which tape (KRX, NXT or consolidated) they came from, and a live run’s bars can differ.
sellable_is_whole_holding bool Always True: every share held counts as sellable; live, a broker can report fewer (unsettled, pledged or locked shares) and refuse a sale the replay allowed.
buying_power_is_ledger_cash bool Always True: the replay’s buying power is its own cash, with no settlement modelled, while a broker computes buying power on its own terms. pyatl does not cap buys at that cash either: a buy may take cash below zero, which overdrawn_bars and lowest_cash report.
periods_per_year float The periods in a year that annualized_sharpe uses: the periods_per_year argument if given, otherwise counted from this replay’s own equity curve, as its points less one over the years between its first and last point (365.25 days each). A given count is reported as given, even on an empty replay; a counted one is NaN with fewer than two points at distinct times. Annualizing needs this number known: a replay shorter than a year extrapolates its own rate, with no full cycle of nights, weekends and holidays, so its annualized figure can be inflated (against 245 KRX sessions a year of 390 1m bars each, about 1.22 times for a week of daily bars and about 2.35 times for one day of 1m bars); give periods_per_year to set it. A counted rate is that of intervals between points, not of the returns that enter sharpe: the point after an unvalued bar carries no return, and a stretch of unvalued bars lowers the count.