PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
metrics.hpp
Go to the documentation of this file.
1#pragma once
2// Pure metric computations over closed-trade arrays and equity curves.
3// No BacktestEngine dependency: unit-testable standalone, called by
4// fill_report. Conventions (NaN rules, positive-magnitude losses, even-
5// trade handling) are documented per-field in <pineforge/pineforge.h>.
6// pineforge.h MUST precede engine.hpp (PINEFORGE_NO_STRATEGY_DECLS; see engine.hpp).
8#include <pineforge/engine.hpp> // TradeC
9#include <string>
10
11namespace pineforge {
12namespace metrics {
13
14enum class TradeFilter { ALL, LONG, SHORT };
15
17 TradeFilter filter, double initial_capital);
18
19// Acquires the global timezone lock (tz_util::ScopedTimezone) when chart_tz
20// is non-UTC; MUST NOT be called while already holding a ScopedTimezone
21// (non-recursive mutex -- deadlock). See src/timezone.hpp.
23 double initial_capital,
24 const std::string& chart_tz,
25 double first_open, double last_close,
26 int64_t bars_in_market, double net_profit);
27
28// The same computation with the observation count stated, not read from the
29// curve length. observation_count is the denominator of time_in_market_pct
30// (bars_in_market / observation_count; NaN when it is not positive) and
31// nothing else: every walk, guard and formula runs over the n curve points as
32// above. The ordinary overload is this one with observation_count = n. A
33// selected-window curve is its window anchor followed by M script-bar
34// observations, so its caller passes n = M + 1 and observation_count = M: the
35// anchor is a curve point and the base of the first return, not a bar. Same
36// timezone-lock rule as above.
38 double initial_capital,
39 const std::string& chart_tz,
40 double first_open, double last_close,
41 int64_t bars_in_market, double net_profit,
42 int64_t observation_count);
43
44} // namespace metrics
45} // namespace pineforge
pf_equity_stats_t compute_equity_stats(const pf_equity_point_t *curve, int64_t n, double initial_capital, const std::string &chart_tz, double first_open, double last_close, int64_t bars_in_market, double net_profit)
pf_trade_stats_t compute_trade_stats(const TradeC *trades, int n, TradeFilter filter, double initial_capital)
Single per-script-bar equity point.
Definition pineforge.h:326
Equity-curve-derived statistics (all-trades only, like TV).
Definition pineforge.h:272
Trade-level statistics block — computed once each for all / long / short.
Definition pineforge.h:209