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).
7
#include <
pineforge/pineforge.h
>
8
#include <
pineforge/engine.hpp
>
// TradeC
9
#include <string>
10
11
namespace
pineforge
{
12
namespace
metrics
{
13
14
enum class
TradeFilter
{
ALL
,
LONG
,
SHORT
};
15
16
pf_trade_stats_t
compute_trade_stats
(
const
TradeC
* trades,
int
n,
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.
22
pf_equity_stats_t
compute_equity_stats
(
const
pf_equity_point_t
* curve, int64_t n,
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.
37
pf_equity_stats_t
compute_equity_stats
(
const
pf_equity_point_t
* curve, int64_t n,
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
engine.hpp
pineforge::metrics
Definition
engine.hpp:64
pineforge::metrics::TradeFilter
TradeFilter
Definition
metrics.hpp:14
pineforge::metrics::TradeFilter::ALL
@ ALL
Definition
metrics.hpp:14
pineforge::metrics::TradeFilter::SHORT
@ SHORT
Definition
metrics.hpp:14
pineforge::metrics::TradeFilter::LONG
@ LONG
Definition
metrics.hpp:14
pineforge::metrics::compute_equity_stats
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)
pineforge::metrics::compute_trade_stats
pf_trade_stats_t compute_trade_stats(const TradeC *trades, int n, TradeFilter filter, double initial_capital)
pineforge
Definition
array.hpp:42
pineforge.h
pf_equity_point_t
Single per-script-bar equity point.
Definition
pineforge.h:326
pf_equity_stats_t
Equity-curve-derived statistics (all-trades only, like TV).
Definition
pineforge.h:272
pf_trade_stats_t
Trade-level statistics block — computed once each for all / long / short.
Definition
pineforge.h:209
pineforge::TradeC
Definition
engine.hpp:235
include
pineforge
metrics.hpp
PineForge unreleased — Apache-2.0 —
github.com/pineforge-4pass/pineforge-engine
—
pineforge.dev