Files
pricing/cpp/Statistics.cpp
David Doebel 087a2f0d74 Restructure C++ core into cpp module and package bindings.
Move the pricing engine sources out of src/ into cpp/, add the closed-form engine and pybind wiring, and align tests/build targets with the new project layout.

Made-with: Cursor
2026-04-02 16:30:33 +02:00

54 lines
873 B
C++

/**
* @file Statistics.cpp
* @brief Streaming moment and extrema updates.
*/
#include "Statistics.hpp"
void Statistics::dump(double value) {
for (std::size_t i = 0; i < 3; ++i) {
moments_[i] += std::pow(value, i+1);
}
++n;
max_ = std::max(max_, value);
min_ = std::min(min_, value);
}
void Statistics::clear() {
n = 0;
moments_ = {0.,0.,0.};
}
double Statistics::mean() {
return moments_[0]/n;
}
double Statistics::variance() {
return moments_[1]/n - std::pow(mean(), 2);
}
double Statistics::standardDeviation() {
return std::sqrt(variance());
}
double Statistics::skewness() {
return moments_[2]/std::pow(n, 3);
}
double Statistics::max() {
return max_;
}
double Statistics::min() {
return min_;
}
double Statistics::sum() {
return moments_[0];
}
double Statistics::count() {
return n;
}