PineForge HPO 0.1.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
trial_executor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pineforge/pineforge.h>
4
5#include <cstdint>
6#include <map>
7#include <memory>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <vector>
12
15
16namespace pineforge {
17namespace hpo {
18
20using ParameterValues = std::map<std::string, std::string>;
21
25 std::string input_timeframe;
27 std::string script_timeframe;
29 std::string chart_timezone;
31 bool bar_magnifier = false;
35 pf_magnifier_distribution_t magnifier_distribution = PF_MAGNIFIER_ENDPOINTS;
36
42};
43
51 std::int32_t total_trades = 0;
53 double net_profit = 0.0;
54
56 std::int64_t input_bars_processed = 0;
58 std::int64_t script_bars_processed = 0;
60 std::int64_t security_feeds_total = 0;
62 std::int64_t security_complete_total = 0;
64 std::int64_t security_partial_total = 0;
66 std::int64_t magnifier_sub_bars_total = 0;
69
71 std::int32_t input_tf_seconds = 0;
73 std::int32_t script_tf_seconds = 0;
75 std::int32_t script_tf_ratio = 0;
77 bool needs_aggregation = false;
80
82 pf_metrics_t metrics{};
84 std::vector<pf_equity_point_t> equity_curve;
85
92 std::optional<double> metric(std::string_view path) const noexcept;
93};
94
96enum class TrialExecutionStatus : std::uint8_t {
97 kSucceeded = 0,
98 kEngineError = 1,
99};
100
113
119class TrialExecutor final {
120public:
125 TrialExecutor(std::shared_ptr<const StrategyPlugin> plugin,
126 std::shared_ptr<const Dataset> dataset,
128
134 const ParameterValues& strategy_overrides = {}) const;
135
137 const BacktestConfiguration& configuration() const noexcept { return configuration_; }
139 const Dataset& dataset() const noexcept { return *dataset_; }
141 const StrategyPlugin& plugin() const noexcept { return *plugin_; }
142
143private:
144 std::shared_ptr<const StrategyPlugin> plugin_;
145 std::shared_ptr<const Dataset> dataset_;
146 BacktestConfiguration configuration_;
147};
148
149} // namespace hpo
150} // namespace pineforge
Immutable in-memory OHLCV input shared by independent trial executions.
Definition dataset.hpp:17
RAII wrapper around one compiled PineForge strategy plugin.
Deterministic one-shot adapter from serialized parameters to a detached report.
const StrategyPlugin & plugin() const noexcept
Returns the loaded strategy plugin.
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 dataset.
TrialExecutor(std::shared_ptr< const StrategyPlugin > plugin, std::shared_ptr< const Dataset > dataset, BacktestConfiguration configuration={})
Binds a validated plugin, immutable dataset, and execution configuration.
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.
std::string chart_timezone
Optional chart timezone applied through the strategy plugin.
bool bar_magnifier
Enables PineForge bar-magnifier sampling.
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.
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.
std::int32_t input_tf_seconds
Input timeframe duration in seconds.
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::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.
std::optional< double > metric(std::string_view path) const noexcept
Resolves a canonical objective path without allocating a string map.
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.
ReportSnapshot report
Detached report populated when execution succeeds.
TrialExecutionStatus status
Machine-readable terminal status.