Moving average data source can be used to calculate a trend from input data. Simple and exponential moving averages are supported. Input columns are introduced by configuring an importing data source.
Simple moving average (SMA) is an arithmetic mean calculated over past period of values. The length of a period determines how quickly trend adjusts to the input data.
Exponential moving average (EMA) is calculated by adjusting the previous EMA value by using a fraction of the change introduced by the new input value.
To be more precise: EMA for given time t from input Data is calculated as follows:
EMA[t] = ( (Data[t] - EMA[t-1] ) x Multiplier) + EMA[t-1]
where Multiplier is defined as:
Multiplier = 2 / (1 + period)
Thus the longer the period is, the slower EMA is to adjust.
The first (period-1) EMAs are not defined and are set to null. The initial value EMA[period] is calculated using SMA[period].
In order to calculate average, input data is needed. This is done by adding importing data source configuration inside the <movingAverage> element. Roughly:
<movingAverage avgType="simple" period="3">
<movAvgColumn column="inputid"/>
<xpath source="..." select="...">
<xpathColumn column="..." id="inputid"/>
</xpath>
<movingAverage/>
Main point in the above is that the columns produced by the importing data source are identified with ids.
As a default a simple average is calculated. By setting avgType to the value of "exponential", EMA is calculated.
One can also configure none or multiple <movAvgColumn> tags. For each <movAvgColumn>, a new output column is added, in addition to the input data columns. Each new output column is given an unique identifier. One can also override input columns by defining an overriding id. If no <movAvgColumn> is defined, then the first input column containing values (column of type="value"), is selected as the input column.
In this example simple moving average is calculated from input data. Output data contains two columns, the input column and calculated moving average result.
<data>
<movingAverage period="4" avgtype="simple" >
<movAvgColumn column="input" id="output" name="SMA" type="value"/>
<xpath source="http://localhost:8080/chart/usersguide/datasources/movavg/movavgData.xml"
select="//simpledata/datavalue">
<xpathColumn column="series1" id="input" name="input data" type="value"/>
</xpath>
</movingAverage>
</data>
|
| Single series with a simple 4 point moving average. |
|
| Moving average with a column id that shadows original data column id. |
|
| Two series with exponential moving averages (EMA). |
|
| Single series with simple (SMA) and exponential (EMA) moving averages. |