3#include <pineforge/pineforge.h>
91 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
92 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
93 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
94 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
95 std::numeric_limits<double>::quiet_NaN()}};
162 std::optional<double>
metric(std::string_view path)
const noexcept;
169class TrialResources final {
172 TrialResources(
const StrategyPlugin& plugin, pf_strategy_t strategy)
173 : plugin_(plugin), strategy_(strategy) {}
176 plugin_.free_report(&report);
177 plugin_.free_strategy(strategy_);
180 TrialResources(
const TrialResources&) =
delete;
182 TrialResources& operator=(
const TrialResources&) =
delete;
184 pf_strategy_t strategy()
const noexcept {
return strategy_; }
186 pf_report_t report{};
190 pf_strategy_t strategy_;
194void apply_trial_settings(
const StrategyPlugin& plugin, pf_strategy_t strategy,
196 const BacktestConfiguration& configuration);
198ReportSnapshot copy_report(
const pf_report_t& report,
const BacktestConfiguration& configuration,
244 std::shared_ptr<const Dataset>
dataset,
258 std::size_t bar_count)
const;
270 std::shared_ptr<const StrategyPlugin> plugin_;
Immutable owned or file-mapped OHLCV input shared by independent trial executions.
RAII wrapper around one compiled PineForge strategy plugin.
Deterministic one-shot adapter from serialized parameters to a detached report.
TrialExecutor(std::shared_ptr< const StrategyPlugin > plugin, DatasetView view, BacktestConfiguration configuration={})
Binds a validated plugin, immutable dataset view, and execution configuration.
TrialExecutionResult execute_prefix(const ParameterValues &inputs, const ParameterValues &strategy_overrides, std::size_t bar_count) const
Runs the exact full-backtest engine path on an immutable bar prefix.
const StrategyPlugin & plugin() const noexcept
Returns the loaded strategy plugin.
const DatasetView & view() const noexcept
Returns the immutable execution range.
const BacktestConfiguration & configuration() const noexcept
Returns the immutable per-execution configuration.
TrialExecutionResult execute(const ParameterValues &inputs, const ParameterValues &strategy_overrides={}) const
Runs one fresh strategy instance with overrides applied before ordinary inputs.
const Dataset & dataset() const noexcept
Returns the shared immutable owner; its size may exceed the execution view.
TrialExecutor(std::shared_ptr< const StrategyPlugin > plugin, std::shared_ptr< const Dataset > dataset, BacktestConfiguration configuration={})
Binds the whole dataset as a view, preserving existing callers' pointer and length.
void require_return_stats_identity()
Refuses return statistics in a build whose identity is unbound.
std::map< std::string, std::string > ParameterValues
Serialized Pine input or runtime-override values keyed by strategy parameter name.
TrialExecutionStatus
Terminal status of one native strategy execution.
@ kSucceeded
Backtest completed and a detached snapshot is available.
@ kEngineError
Strategy reported an error; no comparable snapshot is available.
Immutable engine settings applied to every execution owned by a TrialExecutor.
bool return_stats_monthly
Computes the returns.monthly statistics; the chart timezone above selects the calendar (only UTC is d...
bool capture_trades
Whether ReportSnapshot owns the complete C-ABI trade records (off in the HPO hot loop).
bool return_stats_bar
Computes the returns.bar statistics from the report's equity curve (see docs/return-stats....
std::string chart_timezone
Optional chart timezone applied through the strategy plugin.
bool bar_magnifier
Enables PineForge bar-magnifier sampling.
std::optional< SymbolInfo > symbol_info
Optional instrument metadata, applied after inputs and overrides.
std::shared_ptr< const SymbolFeeds > symbol_feeds
Fixed other-symbol bars loaded once, validated before trials, and shared read-only.
std::string script_timeframe
Pine strategy execution timeframe; may differ from the input timeframe.
pf_magnifier_distribution_t magnifier_distribution
Distribution used to place magnifier samples.
std::string input_timeframe
Timeframe represented by the input Dataset bars.
bool capture_equity_curve
Whether ReportSnapshot owns a copy of the report equity curve.
int magnifier_samples
Positive number of magnifier samples per sub-bar.
std::uint32_t pbo_blocks
Number of blocks S of the bar series to reduce per completed trial, and 0, the default,...
Immutable, non-copying range of bars retaining its Dataset owner.
const std::shared_ptr< const Dataset > owner
Keeps owned bars or the mapping and its descriptor alive.
Owning report snapshot detached from strategy and C-ABI report lifetimes.
bool needs_aggregation
Whether the engine aggregated input bars for script execution.
std::int64_t security_complete_total
Number of complete secondary-feed observations.
std::int64_t security_partial_total
Number of partial secondary-feed observations.
std::int64_t security_feeds_total
Number of requested secondary security feeds.
double net_profit
Report-level net profit in account currency.
ReturnStatsFields return_monthly
Monthly-return statistics, computed before the report was released when requested.
std::int32_t input_tf_seconds
Input timeframe duration in seconds.
ReturnStatsFields return_bar
Bar-return statistics, computed before the report was released when requested.
std::int64_t script_bars_processed
Number of script-timeframe bars processed by the strategy.
std::int32_t script_tf_seconds
Script timeframe duration in seconds.
bool bar_magnifier_enabled
Whether bar magnification was active.
std::int32_t total_trades
Number of completed trades.
pf_metrics_t metrics
Complete detached PineForge metrics structure.
std::int64_t input_bars_processed
Number of input-timeframe bars processed by the engine.
std::vector< pf_equity_point_t > equity_curve
Optional owned copy controlled by BacktestConfiguration::capture_equity_curve.
std::vector< pf_trade_t > trades
Optional owned trade records controlled by BacktestConfiguration::capture_trades.
std::int64_t magnifier_sample_ticks_total
Total synthetic magnifier ticks sampled.
std::int64_t magnifier_sub_bars_total
Total magnifier sub-bars processed.
std::int32_t script_tf_ratio
Integer aggregation ratio reported by the engine.
ReturnBlockMoments return_blocks
Per-block moments of the full-window equity curve; status NotRequested when blocks were not requested...
std::optional< double > metric(std::string_view path) const noexcept
Resolves a canonical objective path without allocating a string map.
ReturnBlockLayout return_block_layout
Block layout of the full-window equity curve, computed before the report was released when blocks wer...
Block layout of one bar-return series: how many intervals each block holds and which curve point open...
Moments of every block of one bar-return series, ascending block.
Published fields of one return-statistics series, in wire order: count, skipped, periods_per_year,...
bool computed
True when the series was requested and computed from a report's equity curve.
std::array< double, 9 > values
Field values in wire order; NaN stands for null.
Result envelope returned by TrialExecutor::execute().
bool succeeded() const noexcept
Returns whether status is TrialExecutionStatus::kSucceeded.
std::string error
Strategy error text when status is TrialExecutionStatus::kEngineError.
std::optional< std::string > error_code
Engine-owned failure code; absent for plugins without the optional getter.
std::optional< std::string > error_args
Raw engine argument JSON; consumers must validate it before serialization.
ReportSnapshot report
Detached report populated when execution succeeds.
TrialExecutionStatus status
Machine-readable terminal status.