EWM#

class numpy::EWM#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use EWM
EWM obj;
// ... operations ...

Constructors#

Signature

Location

Example

EWM(const Series<T>& series, double alpha, bool adjust, bool ignore_na, size_t min_periods)

df_ewm.h:50

Construction#

Signature

Return Type

Location

Example

static EWM from_alpha(const Series<T>& series, double alpha, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)

static EWM

df_ewm.h:120

static EWM from_com(const Series<T>& series, double com, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)

static EWM

df_ewm.h:86

static EWM from_halflife(const Series<T>& series, double halflife, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)

static EWM

df_ewm.h:103

static EWM from_span(const Series<T>& series, double span, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)

static EWM

df_ewm.h:69

Indexing / Selection#

Signature

Return Type

Location

Example

double get_value(size_t i) const

double

df_ewm.h:292

Statistics#

Signature

Return Type

Location

Example

Series<double> mean() const

Series<double>

df_ewm.h:133

View

Series<double> std\_(int ddof = 1) const

Series<double>

df_ewm.h:268

Series<double> var(int ddof = 1) const

Series<double>

df_ewm.h:206

View

Other Methods#

Signature

Return Type

Location

Example

bool adjust() const

bool

df_ewm.h:285

double alpha() const

double

df_ewm.h:284

bool ignore_na() const

bool

df_ewm.h:286

Code Examples#

The following examples are extracted from the test suite.

mean (np_test_1_all.cpp:11714)
11704    // Create test array
11705    auto array = createInt32Array({ 2, 3 }, 0);
11706    array.setElementAt({ 0, 0 }, 1);
11707    array.setElementAt({ 0, 1 }, 2);
11708    array.setElementAt({ 0, 2 }, 3);
11709    array.setElementAt({ 1, 0 }, 4);
11710    array.setElementAt({ 1, 1 }, 5);
11711    array.setElementAt({ 1, 2 }, 6);
11712
11713    // Test mean without axis
11714    auto mean_all = mean(array);
11715    if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716        std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717        std::cout << std::string("[FAIL] ") + description << std::endl;
11718        throw std::runtime_error(description);
11719    }
11720    // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722    // Test mean along axis 0
11723    auto mean_axis0 = mean(array, 0);
11724    if (!(mean_axis0.getShape()[0] == 3)) {
var (np_test_1_all.cpp:11816)
11806    std::cout << "========= testVarianceAndStandardDeviation =======================";
11807
11808    // Create test array with known variance
11809    auto array = createFloat64Array({ 4 }, 0);
11810    array.setElementAt({ 0 }, 1.0);
11811    array.setElementAt({ 1 }, 2.0);
11812    array.setElementAt({ 2 }, 3.0);
11813    array.setElementAt({ 3 }, 4.0);
11814
11815    // Test variance (population)
11816    auto var_result = var(array, std::nullopt, 0);  // ddof=0 for population variance
11817    double expected_var = 1.25;  // Known variance for [1,2,3,4]
11818    if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) {
11819        std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))";
11820        std::cout << std::string("[FAIL] ") + description << std::endl;
11821        throw std::runtime_error(description);
11822    }
11823    // std::cout << "[OK] Population variance works correctly\n";
11824
11825    // Test variance (sample)
11826    auto var_sample = var(array, std::nullopt, 1);  // ddof=1 for sample variance