Module Algostream_reporting.Export

Tabular export: CSV and JSON from one column description.

Why quoting matters here

The CSV writers that already existed (Backtest.Result.write_blotter_csv) emit strategy_id and tag with a bare %s. Both are strategy-supplied free text — tag exists precisely so a fill can be traced back to the reason it was placed — so a comma or a newline in either silently corrupts the file, shifting every later column by one. This module quotes properly, per RFC 4180: a field containing a comma, a double quote, CR or LF is wrapped in quotes with internal quotes doubled.

Not xlsx

Excel export is not implemented. A real .xlsx is a ZIP container of OOXML parts, which is a meaningful amount of machinery for a format Excel opens from CSV anyway. It is listed as a deferral rather than quietly dropped.

type value =
  1. | S of string
  2. | F of float
    (*

    non-finite values render as an empty CSV cell and JSON null

    *)
  3. | I of int
  4. | I64 of int64
  5. | B of bool
type column = {
  1. header : string;
  2. extract : unit -> value;
    (*

    re-evaluated per row by rows_of

    *)
}
val csv_escape : string -> string

Quote one field for CSV. Exposed because Backtest.Result needs the same rule without taking a dependency on this library.

val value_to_csv : value -> string
val to_csv : headers:string list -> rows:value list list -> string

to_csv ~headers ~rowsrows are already-extracted values, one list per row.

val to_json : headers:string list -> rows:value list list -> string

Same data as a JSON array of objects. Keys come from headers; non-finite floats become null, so the output is always parseable.

type format =
  1. | Csv
  2. | Json
val format_of_string : string -> (format, string) Stdlib.result
val format_to_string : format -> string
val content_type : format -> string
val render : format -> headers:string list -> rows:value list list -> string
val to_file : string -> format -> headers:string list -> rows:value list list -> unit

Write to a path, creating or truncating.