19#ifndef quantext_nadaraya_watson_regression_hpp
20#define quantext_nadaraya_watson_regression_hpp
22#include <ql/math/comparison.hpp>
24#include <boost/make_shared.hpp>
43 virtual Real
value(Real x)
const = 0;
60 Real
value(Real x)
const override {
62 Real tmp1 = 0.0, tmp2 = 0.0;
64 for (Size i = 0; i < static_cast<Size>(
xEnd_ -
xBegin_); ++i) {
70 return QuantLib::close_enough(tmp2, 0.0) ? 0.0 : tmp1 / tmp2;
75 Real tmp1 = 0.0, tmp1b = 0.0, tmp2 = 0.0;
77 for (Size i = 0; i < static_cast<Size>(
xEnd_ -
xBegin_); ++i) {
84 return QuantLib::close_enough(tmp2, 0.0) ? 0.0 : std::sqrt(tmp1b / tmp2 - (tmp1 * tmp1) / (tmp2 * tmp2));
108 template <
class I1,
class I2,
class Kernel>
109 NadarayaWatson(
const I1& xBegin,
const I1& xEnd,
const I2& yBegin,
const Kernel& kernel) {
110 impl_ = QuantLib::ext::make_shared<detail::NadarayaWatsonImpl<I1, I2, Kernel> >(xBegin, xEnd, yBegin, kernel);
118 QuantLib::ext::shared_ptr<detail::RegressionImpl>
impl_;
Nadaraya Watson regression.
NadarayaWatson(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const Kernel &kernel)
Real operator()(Real x) const
Real standardDeviation(Real x) const
QuantLib::ext::shared_ptr< detail::RegressionImpl > impl_
Real value(Real x) const override
Real standardDeviation(Real x) const override
NadarayaWatsonImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const Kernel &kernel)
virtual ~RegressionImpl()
virtual Real standardDeviation(Real x) const =0
virtual Real value(Real x) const =0