PineForge HPO 1.11.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
dataset.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pineforge/pineforge.h>
4
5#include <cstddef>
6#include <filesystem>
7#include <memory>
8#include <vector>
9
10namespace pineforge {
11namespace hpo {
12
15
44class Dataset final {
45public:
48 explicit Dataset(std::vector<pf_bar_t> bars);
49
56 static Dataset load_csv(const std::filesystem::path& path);
57
71 static Dataset load_bin(const std::filesystem::path& path,
73
75 const pf_bar_t* data() const noexcept {
76 return mapped_bars_ ? mapped_bars_.get() : bars_.data();
77 }
79 std::size_t size() const noexcept { return mapped_bars_ ? mapped_count_ : bars_.size(); }
81 bool empty() const noexcept { return size() == 0; }
84 const std::vector<pf_bar_t>& bars() const;
85
106 void verify_unchanged() const;
107
108private:
109 struct MappedFile;
110
111 Dataset(std::shared_ptr<const MappedFile> mapped_file,
112 std::shared_ptr<const pf_bar_t> mapped_bars, std::size_t count);
113
114 std::vector<pf_bar_t> bars_;
115 std::shared_ptr<const MappedFile> mapped_file_;
116 std::shared_ptr<const pf_bar_t> mapped_bars_;
117 std::size_t mapped_count_ = 0;
118};
119
127struct DatasetView final {
130 explicit DatasetView(std::shared_ptr<const Dataset> dataset);
131
135 DatasetView(std::shared_ptr<const Dataset> dataset, std::size_t first, std::size_t count);
136
138 const std::shared_ptr<const Dataset> owner;
140 const std::size_t begin;
142 const std::size_t length;
143
145 const pf_bar_t* data() const noexcept;
147 std::size_t size() const noexcept { return length; }
149 bool empty() const noexcept { return length == 0; }
150};
151
152} // namespace hpo
153} // namespace pineforge
Immutable owned or file-mapped OHLCV input shared by independent trial executions.
Definition dataset.hpp:44
const pf_bar_t * data() const noexcept
Returns a const pointer suitable for PineForge backtest calls.
Definition dataset.hpp:75
void verify_unchanged() const
Compares the mapped file's open descriptor's st_dev, st_ino, st_size, st_mtim and st_ctim to their lo...
std::size_t size() const noexcept
Returns the number of bars.
Definition dataset.hpp:79
const std::vector< pf_bar_t > & bars() const
Returns the owning vector for CSV or vector-backed input.
bool empty() const noexcept
Returns whether the dataset contains no bars.
Definition dataset.hpp:81
static Dataset load_bin(const std::filesystem::path &path, BinaryVerification verification=BinaryVerification::Full)
Maps a headerless little-endian pf_bar_t/v1 file read-only, without copying its bars.
static Dataset load_csv(const std::filesystem::path &path)
Loads timestamp,open,high,low,close,volume columns from a CSV file.
Dataset(std::vector< pf_bar_t > bars)
Takes ownership of validated bars.
BinaryVerification
Verification of a binary chart's sidecar and mapped bytes.
Definition dataset.hpp:14
Immutable, non-copying range of bars retaining its Dataset owner.
Definition dataset.hpp:127
DatasetView(std::shared_ptr< const Dataset > dataset, std::size_t first, std::size_t count)
Constructs the range [first, first + count).
const std::size_t begin
First bar's index in owner.
Definition dataset.hpp:140
DatasetView(std::shared_ptr< const Dataset > dataset)
Constructs a view of the entire owner.
const std::size_t length
Number of bars in this view.
Definition dataset.hpp:142
const std::shared_ptr< const Dataset > owner
Keeps owned bars or the mapping and its descriptor alive.
Definition dataset.hpp:138
std::size_t size() const noexcept
Returns the number of bars in this view.
Definition dataset.hpp:147
const pf_bar_t * data() const noexcept
Returns owner->data() + begin, preserving the pointer even for an empty owner.
bool empty() const noexcept
Returns whether this view contains no bars.
Definition dataset.hpp:149