WebCab Technical Analysis
(J2EE Edition)

com.webcab.ejb.finance.trading.indicators
Interface MovingAverageLocal

All Superinterfaces:
EJBLocalObject

public interface MovingAverageLocal
extends EJBLocalObject

Local interface of MovingAverage. This interface provides the same functionality as the MovingAverage remote interface.

See Also:
MovingAverage

Method Summary
 double exponentiallyWeightedMovingAverage(double[] timeSeries, double smoothingFactor)
          Method exponentiallyWeightedMovingAverage(double[], double) as defined in the MovingAverage remote interface.
 double geometricMovingAverage(double[] historicalValue)
          Method geometricMovingAverage(double[]) as defined in the MovingAverage remote interface.
 double kairi(double movingAverage, double price)
          Method kairi(double, double) as defined in the MovingAverage remote interface.
 double linearlyWeightedMovingAverage(double[] priceSeries)
          Method linearlyWeightedMovingAverage(double[]) as defined in the MovingAverage remote interface.
 double medianMovingAverage(double[] historicalHigh, double[] historicalLow)
          Method medianMovingAverage(double[], double[]) as defined in the MovingAverage remote interface.
 int simpleCrossingSignal(double lastShortMA, double previousShortMA, double lastLongMA, double previousLongMA)
          Method simpleCrossingSignal(double, double, double, double) as defined in the MovingAverage remote interface.
 double simpleMovingAverage(double[] historicalPrice)
          Method simpleMovingAverage(double[]) as defined in the MovingAverage remote interface.
 double weightedxDayMovingAverage(double[] historicalPrices, double[] weights)
          Method weightedxDayMovingAverage(double[], double[]) as defined in the MovingAverage remote interface.
 
Methods inherited from interface javax.ejb.EJBLocalObject
getEJBLocalHome, getPrimaryKey, isIdentical, remove
 

Method Detail

simpleMovingAverage

public double simpleMovingAverage(double[] historicalPrice)
Method simpleMovingAverage(double[]) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Calculates the x-day arithmetic moving average of the market price of a traded asset over the past x-days. Care should be taken when evaluating the moving average that the price on each of these days is sampled in a consistent manor. For example, the moving average could take the average closing prices on the last x-days in order to evaluate the average.

Parameters:
historicalPrice - an array of length x, where the first element historicalPrice[0], corresponds to the market price on the first of the x-day period. The term historicalPrice[1], corresponds to the market price of the second of the x-day period, and so on...
Throws:
IllegalArgumentException - thrown if the historicalPrices array is empty.
See Also:
MovingAverage.simpleMovingAverage(double[])

medianMovingAverage

public double medianMovingAverage(double[] historicalHigh,
                                  double[] historicalLow)
Method medianMovingAverage(double[], double[]) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Returns the x-day Median Moving Average of the market price of a traded asset over the past x-days.

Parameters:
historicalHigh - an array where the first element historicalHigh[0], corresponds to the highest market price during the last trading period, the historicalHigh[1], corresponds to the highest market price in the previous period, and so on..
historicalLow - an array where the first element historicalLow[0], corresponds to the lowest market price during the last trading period, the historicalLow[1], corresponds to the lowest market price in the previous period, and so on...
Throws:
IllegalArgumentException - thrown if the arrays historicalHigh and historicalLow are of different lengths or if one of these arrays is empty.
See Also:
MovingAverage.medianMovingAverage(double[], double[])

geometricMovingAverage

public double geometricMovingAverage(double[] historicalValue)
Method geometricMovingAverage(double[]) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Calculates the x-day Geometric Moving Average (GMA) which is the geometric average of the values given over the past x days. This indicator is particularly appropriate in the study of time series of values which obey the logarithm addition law. One such example is a series of the returns of an asset over a number of periods.

Parameters:
historicalValue - an array of length x, where the first element historicalPrice[0], corresponds to the market on the first of the x-day period. The term historicalPrice[1], corresponds to the market price of the second of the x-day period, and so on...
Throws:
IllegalArgumentException - thrown if the historicalValue array is empty.
See Also:
MovingAverage.geometricMovingAverage(double[])

weightedxDayMovingAverage

public double weightedxDayMovingAverage(double[] historicalPrices,
                                        double[] weights)
Method weightedxDayMovingAverage(double[], double[]) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Here we evaluate the Weighted Moving Average (WMA) which allows you to assign more significance to resent price dynamics.

Parameters:
weights - this is an array of length x, which assigns to each of the historicalPrices a weighting. The ith element weights[i], assigns to the element historicalPrice[i], a weighting.
historicalPrices - an array of length x, where the first element historicalPrice[0], corresponds to the market on the first of the x-day period. The term historicalPrice[1], corresponds to the market price of the second of the x-day period, and so on.
Throws:
IllegalArgumentException - thrown if the length of the weights and historicalPrices arrays differ or if either array is empty.
See Also:
xDayMovingAverage, MovingAverage.weightedxDayMovingAverage(double[], double[])

linearlyWeightedMovingAverage

public double linearlyWeightedMovingAverage(double[] priceSeries)
Method linearlyWeightedMovingAverage(double[]) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Returns the value of the Linearly Weighted Moving Average (LWMA) of a (finite) price series. The Linearly Weighted Moving Average (LWMA) weights the time series by assigning a weight of 1, to the oldest price and a weight of 2 to the second oldest price on so on... Until the weight of the most recent value is assigned to be the number of days in the time series. Then the LWMA is given by the sum of the weighted prices divided by the sum of the weights.

Parameters:
priceSeries - an array where the first element is the price on the earliest day, the second element is the price on the next earliest day and on so.
Throws:
IllegalArgumentException - thrown if the array priceSeries is empty.
See Also:
MovingAverage.linearlyWeightedMovingAverage(double[])

exponentiallyWeightedMovingAverage

public double exponentiallyWeightedMovingAverage(double[] timeSeries,
                                                 double smoothingFactor)
Method exponentiallyWeightedMovingAverage(double[], double) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Evaluates the (x-day) Exponentially Weighted Moving Average (EWMA) of a time series from the 0-th period until the (x-1)-th period.

Parameters:
timeSeries - an array where the first value corresponds to the value of the asset in the $t$th period, and the second value corresponds to the value of the asset in the $t-1$th period and so on
smoothingFactor - the number between 0 and 1 which is known as a smoothing factor. The closer the value is to zero the more influence more resent measurements will have on the EWMA.
Throws:
IllegalArgumentException - thrown if the timeSeries is empty or if the value given for the smoothing factor lies outside the closed range [0,1].
See Also:
MovingAverage.exponentiallyWeightedMovingAverage(double[], double)

kairi

public double kairi(double movingAverage,
                    double price)
Method kairi(double, double) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Calculates the Kairi Indicator measures as a percentage of the price the divergence between the a moving average (generally the simple moving average) of the price and the price itself. The Kairi Indicator is often used with conjunction with other moving averages within trading systems.

The formulae for the Kairi Indicator is as follows:


Kairi Indicator = (MA - price)/ price

where MA is the moving average being considered and price is the present price of the underlying asset.

Application

The Kairi Indicator can be used in order to take advantage of an over extended trending market. For example, in an upwardly trending market when the price gets say more than 10% above the simple moving average, the asset could be sold and repurchased when the next hits the simple moving average again.

The Kairi Indicator could also be used in order to detect market tops and bottom. The idea being that market tops and bottoms often occur when the price is at an extreme value in relation to its moving average. That is, the Kairi Indicator should take an extreme value at market tops and bottoms.

Parameters:
movingAverage - the value of the moving average (generally the simple moving average) of the underlying asset
price - the present price of the underlying asset
Returns:
The percentage expressed as decimal format (i.e. 0.01 = 1%) between the present price and a moving average of the price.
See Also:
MovingAverage.kairi(double, double)

simpleCrossingSignal

public int simpleCrossingSignal(double lastShortMA,
                                double previousShortMA,
                                double lastLongMA,
                                double previousLongMA)
Method simpleCrossingSignal(double, double, double, double) as defined in the MovingAverage remote interface.

Description copied from the MovingAverage interface:

Generates of trading signal in accordance with the Simple crossing two moving average trading system. This system uses the classical approach of using the crossing of moving averages to generate trading signals.

Selecting the Moving Averages

You will need to select the type of moving average used and the different periods over which these moving averages are evaluated. In most, instances the simple moving average is used but in principle any type of moving average could be used. The periods of moving averages must be different. Typical choices of period used correspond roughly to convenient time periods, such as: 5 (1 week), 20 (1 month), 50 (2 months) (i.e. 50), 200 (1 year).

We will refer to the moving average with the shorter period as the Short MA, and the moving average with the longer period as the Long MA. Corresponding to the fact that they measure the trending behavior on shorter and long time spans.

Generation of Trading Signals

Trading signals are generated when:

Parameters:
lastShortMA - the last value of the Short moving average (i.e. the moving average with the shorter period)
previousShortMA - the previous value of the short moving average (i.e. the moving average with the shorter period)
lastLongMA - the last value of the Long moving average (i.e. the moving average with the longer period)
previousLongMA - the previous value of the long moving average (i.e. the moving average with the long period)
Returns:
this method returns a -1, 0, 1; depending on whether a sell, no signal or buy signal was generate by the system.
See Also:
MovingAverage.simpleCrossingSignal(double, double, double, double)

WebCab Technical Analysis
(J2EE Edition)