net.simplace.sim.components.util.SimpleMovingAverage

Calculates simple moving average of a variable (non centered)

Averaging

Calculates the simple moving average by taking the sum of the last cDays values of the variable iValue and dividing by the number of days with available data during the averaging window.

Missing values are null - notice: null is not 0.0! \(idx_j\) indicates if a value on simulation day \(j\) is available (i.e. non-null).

\[ idx_j = \begin{cases} 1 & \text{if } iValue_j \neq \text{null} \\ 0 & \text{else} \end{cases} \]

If \(k\) is the actual simulation day, then \(DaysInBuffer_k\) counts how many values where available the last cDays.

\[ DaysInBuffer_k = \sum_{j=k- cDays + 1}^k idx_j \]

The values are summed up, where null values are treated as 0.0.

\[ Sum_k = \sum_{j=k- cDays + 1}^k idx_j \cdot iValue_j \]

\[ Average_k = \frac{Sum_k}{DaysInBuffer_k} \]

Missing data at begin or in between

At simulation start the values from pre-startdate are missing. There could also occur missing values in between. Missing values contribute as 0 to the Sum and are ignored for the Average, by summing only available values and dividing by available days. If there is no data at all in the actual window, the average is set to 0.

The variable StrictAverage gives only the average, if there is data for all days in the window. Otherwise the value is null. (Notice: null is not 0.0! Depending where the output is used, this can cause NullPointerExceptions).

\[ StrictAverage_k = \begin{cases} Average_k & \text{if } DaysInBuffer_k = cDays \\ \text{null} & \text{else} \end{cases} \]

Notice: non centered

As the values from following days are not available, the moving average can be calculated only from the past and today's values.

Component Variables

Content TypeNameDescriptionData TypeUnitMin ValueMax ValueDefault Value
constantcDayswindow size in days (average taken over last cDays days, including today)INT--1
inputiValuedaily values to be averagedDOUBLE---
outActualValueBufferbuffered values of last cDays - first in / first outDOUBLEARRAY---
outAverageaverage of the non-missing (non-null) values, i.e. Sum/DaysInBufferDOUBLE--0.0
outDaysInBuffernumber of values that are used for averaging, possibly smaller than cDays when null values occur or at beginINT--0
outStrictAverageaverage, if no data missing. null otherwiseDOUBLE---
outSumsum of the past values (use 0.0 for missing/null values)DOUBLE--0.0
outTotalDayscount of total simulated daysINT--0



public class SimpleMovingAverage extends net.simplace.sim.model.FWSimComponent {
// Public Constructors
public SimpleMovingAverage();


// Public Instance Methods
public HashMap createVariables(); // Defines
net.simplace.sim.model.FWSimComponent


Create the FWSimVariables as interface for this SimComponent

// Protected Instance Methods
protected void init(); // Defines net.simplace.sim.model.FWSimComponent

Initializes the fields by getting input and output FWSimVariables from VarMap
protected void process(); // Defines net.simplace.sim.model.FWSimComponent

Process the algorithm and write the results back to VarMap
protected FWSimComponent clone(FWSimVarMap aVarMap);
// Defines net.simplace.sim.model.FWSimComponent


creates a clone from this SimComponent for use in other threads


}



Hierarchy: java.lang.Object - net.simplace.sim.model.FWSimComponent (net.simplace.sim.util.FWSimFieldContainer) - SimpleMovingAverage