PineForge HPO 0.1.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
strategy_plugin.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pineforge/pineforge.h>
4
5#include <filesystem>
6#include <string>
7
8namespace pineforge {
9namespace hpo {
10
16class StrategyPlugin final {
17public:
21 explicit StrategyPlugin(std::filesystem::path path);
23
26 StrategyPlugin(StrategyPlugin&& other) noexcept;
28
30 const std::filesystem::path& path() const noexcept { return path_; }
32 int abi_version() const noexcept { return abi_version_value_; }
33
36 pf_strategy_t create_strategy() const;
37
39 void free_strategy(pf_strategy_t strategy) const noexcept;
40
43 void set_input(pf_strategy_t strategy, const std::string& key, const std::string& value) const;
44
47 void set_override(pf_strategy_t strategy,
48 const std::string& key,
49 const std::string& value) const;
50
57 void set_chart_timezone(pf_strategy_t strategy, const std::string& timezone) const;
58
63 void run_backtest_full(pf_strategy_t strategy,
64 const pf_bar_t* bars,
65 int bar_count,
66 const std::string& input_timeframe,
67 const std::string& script_timeframe,
68 bool bar_magnifier,
69 int magnifier_samples,
70 pf_magnifier_distribution_t magnifier_distribution,
71 pf_report_t* report) const;
74 std::string last_error(pf_strategy_t strategy) const;
75
77 void free_report(pf_report_t* report) const noexcept;
78
79private:
80 using StrategyCreateFn = pf_strategy_t (*)(const char*);
81 using StrategyFreeFn = void (*)(pf_strategy_t);
82 using StrategySetInputFn = void (*)(pf_strategy_t, const char*, const char*);
83 using StrategySetOverrideFn = void (*)(pf_strategy_t, const char*, const char*);
84 using StrategySetChartTimezoneFn = void (*)(pf_strategy_t, const char*);
85 using RunBacktestFullFn = void (*)(pf_strategy_t,
86 pf_bar_t*,
87 int,
88 const char*,
89 const char*,
90 int,
91 int,
92 pf_magnifier_distribution_t,
93 pf_report_t*);
94 using StrategyGetLastErrorFn = const char* (*)(pf_strategy_t);
95 using ReportFreeFn = void (*)(pf_report_t*);
96 using AbiVersionFn = int (*)();
97
98 void close() noexcept;
99
100 std::filesystem::path path_;
101 void* library_handle_ = nullptr;
102 int abi_version_value_ = 0;
103 StrategyCreateFn strategy_create_ = nullptr;
104 StrategyFreeFn strategy_free_ = nullptr;
105 StrategySetInputFn strategy_set_input_ = nullptr;
106 StrategySetOverrideFn strategy_set_override_ = nullptr;
107 StrategySetChartTimezoneFn strategy_set_chart_timezone_ = nullptr;
108 RunBacktestFullFn run_backtest_full_ = nullptr;
109 StrategyGetLastErrorFn strategy_get_last_error_ = nullptr;
110 ReportFreeFn report_free_ = nullptr;
111 AbiVersionFn pf_abi_version_ = nullptr;
112};
113
114} // namespace hpo
115} // namespace pineforge
RAII wrapper around one compiled PineForge strategy plugin.
StrategyPlugin & operator=(StrategyPlugin &&other) noexcept
void set_chart_timezone(pf_strategy_t strategy, const std::string &timezone) const
Sets the chart timezone when non-empty and supported by the plugin.
pf_strategy_t create_strategy() const
Creates a fresh strategy handle owned by the caller.
const std::filesystem::path & path() const noexcept
Returns the dynamic-library path supplied at construction.
std::string last_error(pf_strategy_t strategy) const
Returns the plugin's last error for strategy, or an empty string when none exists.
void free_report(pf_report_t *report) const noexcept
Releases report-owned allocations populated by run_backtest_full().
void run_backtest_full(pf_strategy_t strategy, const pf_bar_t *bars, int bar_count, const std::string &input_timeframe, const std::string &script_timeframe, bool bar_magnifier, int magnifier_samples, pf_magnifier_distribution_t magnifier_distribution, pf_report_t *report) const
Invokes the plugin's full backtest entry point using immutable OHLCV input.
void free_strategy(pf_strategy_t strategy) const noexcept
Releases a handle returned by create_strategy(); safe to call during cleanup.
int abi_version() const noexcept
Returns the ABI version reported by the validated plugin.
void set_input(pf_strategy_t strategy, const std::string &key, const std::string &value) const
Applies one serialized Pine input before the backtest starts.
StrategyPlugin(std::filesystem::path path)
Loads path and resolves the required PineForge strategy symbols.
StrategyPlugin(StrategyPlugin &&other) noexcept
void set_override(pf_strategy_t strategy, const std::string &key, const std::string &value) const
Applies one serialized runtime strategy override before the backtest starts.
StrategyPlugin & operator=(const StrategyPlugin &)=delete
StrategyPlugin(const StrategyPlugin &)=delete