Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
NadarayaWatsonImpl< I1, I2, Kernel > Class Template Reference

Nadaraya Watson impl. More...

#include <qle/math/nadarayawatson.hpp>

+ Inheritance diagram for NadarayaWatsonImpl< I1, I2, Kernel >:
+ Collaboration diagram for NadarayaWatsonImpl< I1, I2, Kernel >:

Public Member Functions

 NadarayaWatsonImpl (const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const Kernel &kernel)
 
void update () override
 
Real value (Real x) const override
 
Real standardDeviation (Real x) const override
 
- Public Member Functions inherited from RegressionImpl
virtual ~RegressionImpl ()
 
virtual void update ()=0
 
virtual Real value (Real x) const =0
 
virtual Real standardDeviation (Real x) const =0
 

Private Attributes

I1 xBegin_
 
I1 xEnd_
 
I2 yBegin_
 
Kernel kernel_
 

Detailed Description

template<class I1, class I2, class Kernel>
class QuantExt::detail::NadarayaWatsonImpl< I1, I2, Kernel >

Nadaraya Watson impl.

Definition at line 50 of file nadarayawatson.hpp.

Constructor & Destructor Documentation

◆ NadarayaWatsonImpl()

NadarayaWatsonImpl ( const I1 &  xBegin,
const I1 &  xEnd,
const I2 &  yBegin,
const Kernel &  kernel 
)
Precondition
the \( x \) values must be sorted.
kernel needs a Real operator()(Real x) implementation

Definition at line 55 of file nadarayawatson.hpp.

Member Function Documentation

◆ update()

void update ( )
overridevirtual

Implements RegressionImpl.

Definition at line 58 of file nadarayawatson.hpp.

58{}

◆ value()

Real value ( Real  x) const
overridevirtual

Implements RegressionImpl.

Definition at line 60 of file nadarayawatson.hpp.

60 {
61
62 Real tmp1 = 0.0, tmp2 = 0.0;
63
64 for (Size i = 0; i < static_cast<Size>(xEnd_ - xBegin_); ++i) {
65 Real tmp = kernel_(x - xBegin_[i]);
66 tmp1 += yBegin_[i] * tmp;
67 tmp2 += tmp;
68 }
69
70 return QuantLib::close_enough(tmp2, 0.0) ? 0.0 : tmp1 / tmp2;
71 }

◆ standardDeviation()

Real standardDeviation ( Real  x) const
overridevirtual

Implements RegressionImpl.

Definition at line 73 of file nadarayawatson.hpp.

73 {
74
75 Real tmp1 = 0.0, tmp1b = 0.0, tmp2 = 0.0;
76
77 for (Size i = 0; i < static_cast<Size>(xEnd_ - xBegin_); ++i) {
78 Real tmp = kernel_(x - xBegin_[i]);
79 tmp1 += yBegin_[i] * tmp;
80 tmp1b += yBegin_[i] * yBegin_[i] * tmp;
81 tmp2 += tmp;
82 }
83
84 return QuantLib::close_enough(tmp2, 0.0) ? 0.0 : std::sqrt(tmp1b / tmp2 - (tmp1 * tmp1) / (tmp2 * tmp2));
85 }

Member Data Documentation

◆ xBegin_

I1 xBegin_
private

Definition at line 88 of file nadarayawatson.hpp.

◆ xEnd_

I1 xEnd_
private

Definition at line 88 of file nadarayawatson.hpp.

◆ yBegin_

I2 yBegin_
private

Definition at line 89 of file nadarayawatson.hpp.

◆ kernel_

Kernel kernel_
private

Definition at line 90 of file nadarayawatson.hpp.