# Moving Average (EWM)

The **Exponential Weighted Function** (EWM) calculator is a tool within the Verteego platform that allows users to apply exponential smoothing to a dataset for various statistical operations. The calculator supports multiple methods including **mean**, **variance (var)**, **standard deviation (std)**, **correlation (corr)**, and **covariance (cov)**.

**Input Columns**

These are the columns used in the calculation for the exponential weighted function.

* **Names of Columns**: Specify the columns that will be used to apply the calculation.

**Output Columns**

These are the columns that will be added to the dataset as a result of the calculation.

* **Names of Columns**: The output columns generated by applying the exponential weighted function to the input columns.

**Parameters**

This section defines the parameters required for the exponential weighted function calculation.

1. **method**:
   * This specifies the method used for smoothing the values in the input columns. The supported methods are:
     * `mean`: Computes the exponential weighted mean.
     * `var`: Computes the exponential weighted variance.
     * `std`: Computes the exponential weighted standard deviation.
     * `corr`: Computes the exponential weighted correlation.
     * `cov`: Computes the exponential weighted covariance.
2. **span**:
   * Defines the span of the smoothing window, typically in terms of the number of rows considered for the exponential weighting. A larger span results in smoother values, while a smaller span gives more weight to recent values.
3. **values**:
   * A list of columns that need to be smoothed. These columns will undergo the exponential weighted smoothing calculation.
4. **sort\_by**:
   * A list of column names by which the dataset should be sorted before the calculation. Sorting ensures the correct chronological or logical order of the data before applying the smoothing.
5. **group\_by**:
   * A list of columns used for grouping the data. The smoothing function will be applied to each group individually.

***

**Example in YAML Format**

This example demonstrates how to configure the exponential weighted function in YAML format for a typical use case:

```yaml
yamlCopyEditcalculated_cols:
  qty_sold_ewm:
    method: ewm
    input_columns:
      - qty_sold
      - itemid
      - locid
      - date
    output_columns:
      - qty_sold_ewm
    params:
      span: 4
      method: mean
      values:
        - qty_sold
      sort_by:
        - itemid
        - locid
        - date
      group_by:
        - itemid
        - locid
```

In this YAML configuration:

* The exponential weighted function (`ewm`) is applied to the `qty_sold` column.
* The smoothing method used is **mean** (`method: mean`).
* The smoothing window spans over 4 rows (`span: 4`).
* The dataset will be sorted by `itemid`, `locid`, and `date` before applying the smoothing (`sort_by: [itemid, locid, date]`).
* The smoothing will be applied to the `qty_sold` column and grouped by `itemid` and `locid` (`group_by: [itemid, locid]`).
* The output will be stored in the `qty_sold_ewm` column.

***

#### **Use Cases**

This calculator can be useful in various analytical scenarios where smoothing is needed to make time series data more interpretable or to detect trends. Some use cases include:

* **Sales forecasting**: Apply exponential weighted mean or variance to sales data to reduce noise and better capture trends.
* **Demand forecasting**: Smooth the demand data to predict future stock levels or adjust replenishment schedules.
* **Financial analysis**: Use correlation or covariance for financial data to understand the relationships between different assets or business factors over time.

***

#### **Benefits**

* **Real-time Data Smoothing**: Automatically smooth your data to reveal clearer patterns.
* **Enhanced Accuracy**: By choosing the right method (mean, var, std, etc.), you can improve decision-making based on the smoothed values.
* **Customizable for Different Data Types**: Supports a variety of use cases by adjusting parameters like span, sorting, and grouping.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.verteego.com/verteego-doc/pipelines/forecasting-pipelines/calculators/mathematic/moving-average-ewm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
