Module Algostream_backtest.Result

What a backtest produces.

Three views of the same run: an equity curve (what happened to capital), a blotter (what was traded), and per-order TCA (how well it was executed). Algostream_performance consumes the first two; to_perf_fills adapts the blotter into that library's input type so the dependency runs one way only — performance never depends on backtest.

type equity_point = {
  1. ts_ns : int64;
  2. nav : float;
  3. cash : float;
  4. gross_exposure : float;
  5. net_exposure : float;
  6. leverage : float;
  7. drawdown : float;
    (*

    fractional, from the running peak

    *)
  8. n_positions : int;
}
type blotter_row = {
  1. ts_ns : int64;
  2. order_id : string;
  3. client_order_id : string;
  4. symbol : string;
  5. side : Side.t;
  6. quantity : float;
    (*

    positive; direction is in side

    *)
  7. price : float;
  8. notional : float;
  9. commission : float;
  10. slippage_cost : float;
    (*

    currency, versus the decision price; positive = adverse

    *)
  11. liquidity : Trade.execution_type;
  12. strategy_id : string;
  13. tag : string;
  14. nav_after : float;
  15. realized_pnl_after : float;
}
type counters = {
  1. n_events : int;
  2. n_out_of_order_dropped : int;
  3. n_actions : int;
  4. n_submitted : int;
  5. n_rejected_by_risk : int;
  6. n_fills : int;
  7. n_maker_fills : int;
  8. n_taker_fills : int;
  9. n_cancelled : int;
  10. n_expired : int;
  11. n_fok_killed : int;
  12. n_ioc_remainder_cancelled : int;
  13. n_stops_triggered : int;
  14. unfilled_quantity : float;
}
type t = {
  1. strategy_name : string;
  2. params : (string * float) list;
  3. root_seed : int64;
  4. run_index : int;
  5. equity : equity_point array;
  6. blotter : blotter_row array;
  7. tca : (string * Execution_quality.report) array;
  8. final_portfolio : Portfolio.portfolio;
  9. counters : counters;
  10. first_ts_ns : int64;
  11. last_ts_ns : int64;
  12. total_commission : float;
  13. total_financing : float;
  14. strategy_diagnostics : (string * float) list;
}
val empty_counters : counters
val nav_curve : t -> (int64 * float) array

NAV curve in the shape Algostream_performance expects.

val to_perf_fills : t -> Algostream_performance.Attribution.fill array

Adapt the blotter into Performance.Attribution.fill records. Financing is not attributable to an individual fill, so it is spread across fills pro rata by notional — an approximation, and noted as one.

val equity_csv_header : string
val write_equity_csv : t -> Stdlib.out_channel -> unit
val blotter_csv_header : string
val write_blotter_csv : t -> Stdlib.out_channel -> unit
val summary_to_string : t -> string