|
WebCab Technical Analysis v1.1 (J2SE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--webcab.lib.finance.trading.indicators.Stochastics
Oscillator's of Stochastic type such as fast %K Stochastic, %D Stochastic and associated trading signals such as Extremum Value, Crossing, Crossing Extreme. These stochastic indicators compare the most recent observed market variables (price, high, low etc) with the same market variables over a given historical period. Here we provide the (fast) %K Stochastic and its moving average known as the (slow) %D Stochastic.
Within this class we have implemented the fast %K Stochastic and a general
implementation of the %D Stochastic. The generality of the %D Stochastic
lies in the fact that the method by which the moving average is evaluated can be selected.
Stochastic Oscillator's produce two time series, %K, and its moving average (MA) usually denoted by %D. These two lines are usual plotted on the same graph since it is generally the interaction of these two indicators which is used in order to generate trading signals.
Below we describe three popular ways in which the Stochastic indicator in interpreted in order to produce trading signals:
For many of the indicators we provide essentially two versions of the same method. The first version evaluates the indicator over the entire period given and the second version evaluates the indicator over all the sub-periods of a given length. Moreover, the version which evaluates over all sub-periods of a given length will return the results as an array where the 1st term of the array will be the value associated with the most recent sub-period, and the previous element corresponding to the previous sub-period and so on.
The naming of these two versions will follow the convention that if the indicator which
evaluates over the entire period and returns a single element is named ABCIndicator,
then the corresponding indicator over all sub-periods (of a given length) which returns
an array will be denoted by ABCIndicatorOverPeriod.
For example, if our source data has N elements then the two versions
of a given indicator, where the number of periods used within the sub-periods is
n would correspond to:
ABCIndicator - Evaluation of the indicator over the whole period of length N.ABCIndicatorOverPeriod - Will return an array where the
first term is the value of the indicator ABCIndicator on the most recent n
periods, and the next term is the value of the indicator ABCIndicator on the
previous n+1 periods minus the most recent period and so on. That is,
for each iterative evaluation 'the window of evaluation' is shifted one place back.
| Constructor Summary | |
Stochastics()
Creates a new instance. |
|
| Method Summary | |
int |
crossingExtremeSignal(double extremeLow,
double extremeHigh,
double firstStochasticLast,
double firstStochasticPrevious,
double secondStochasticLast,
double secondStochasticPrevious)
This trading system combines the features of the crossing and extremum value trading systems by requiring that a signal will only be generated if the fast %K Stochastic crosses the slow %D Stochastic either above or below the extremal values. |
int[] |
crossingExtremeSignalPeriod(double extremeLow,
double extrememHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Crossing Extreme Trading system applied over a period. |
int[] |
crossingSignal(double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Implements a general framework for producing trading signals based on the crossing of two Stochastics. |
int |
crossingSignal(double firstStochasticLast,
double firstStochasticPrevious,
double secondStochasticLast,
double secondStochasticPrevious)
Implements a general framework for producing trading signals based on the crossing of two Stochastics. |
int[] |
crossingSignalPeriod(double[] firstStochastic,
double[] secondStochastic)
Implements a general framework for producing trading signals based on the crossing of two Stochastics. |
double[] |
dStochastic(double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Evaluate the (general) %D Stochastic over all periods using only price data. |
double |
dStochastic(double[] stochastic,
int method)
Evaluate the (general) %D Stochastic. |
double[] |
dStochastic(double[] stochastic,
int method,
int lengthOfMA)
Evaluate the (general) %D Stochastic over all periods using known values of the stochastic. |
int[] |
extremeValueDSignalPeriod(double extremeLow,
double extremeHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. |
int[] |
extremeValueKSignalPeriod(double extremeLow,
double extremeHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. |
int |
extremeValueSignal(double extremeLow,
double extremeHigh,
double lastStochastic,
double previousStochastic)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. |
double |
kFastStochastic(double[] high,
double[] low,
double close)
Evaluation of the Fast %K Stochastic. |
double[] |
kFastStochasticPeriod(double[] highs,
double[] lows,
double[] close,
int noOfPeriods)
Evaluation of the Fast %K Stochastic over all possible sub-periods. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Stochastics()
| Method Detail |
public double kFastStochastic(double[] high,
double[] low,
double close)
The Stochastic %K depends on the following variable:
Within this method these parameters are set indirectly by the length of the array's which are passed to the method. That is, if the array's have length 5, then the fast Stochastic is evaluated over the last 5 trading period, referred to as the 5-day %K Stochastic.
Now the formulae for the Fast %K Stochastic is:
Fast %K Stochastic = 100 * (Last Close - Lowest low) / (Highest high - Lowest low),
where the 'lowest low' (respec. 'highest high') is the highest (respec. lowest) close of the asset over the period under consideration. Since the 'Last close', will lie between the highest high and lowest low this indicator will lie between 0 and 100.
high - an array where the k-th term is the high during the k-th previous trading session. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.low - an array where the k-th term is the low during the k-th previous trading session. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.close - the previous closing price of the asset being considered.
kFastStochasticPeriod
public double[] kFastStochasticPeriod(double[] highs,
double[] lows,
double[] close,
int noOfPeriods)
The Stochastic %K depends on the following variable:
Now the formulae for a particular look back periods for the %K Stochastic is:
%K Stochastic = 100 * (Last Close - Lowest low) / (Highest high - Lowest low),
where the 'lowest low' (respec. 'highest high') is the highest (respec. lowest) close of the asset over the period under consideration. Since the 'Last close', will lie between the highest high and lowest low this indicator will lie between 0 and 100.
Here we evaluate the %K Stochastic over all possible periods. Which means that we
first evaluate over the last noOfPeriods-periods using the above formula,
we then evaluate from the previous periods until noOfPeriods + 1-periods
previous, and so on.
highs - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.lows - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic.
kFastStochastic
public double dStochastic(double[] stochastic,
int method)
throws ReferencedServiceException
kFastStochastic,
where the length of the moving average used is the length of the stochastic
parameter.
Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.
As one would expect the Moving Average %D of the %K Stochastic depends on:
stochastic - the value of the stochastic over the period considered.method - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
ReferencedServiceException
public double[] dStochastic(double[] stochastic,
int method,
int lengthOfMA)
kFastStochastic, where
the length of the moving average is specified as a parameter.
Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.
As one would expect the Moving Average %D of the %K Stochastic depends on:
stochastic - the value of the stochastic over the period consideredmethod - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
lengthOfMA - the number of periods over which the moving average is considered
public double[] dStochastic(double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
kFastStochastic, where
the length of the moving average is specified as a parameter.
Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.
As one would expect the Moving Average %D of the %K Stochastic depends on:
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic as provided by DStochastic.method - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
lengthOfMA - the number of periods over which the moving average is considered.
public int extremeValueSignal(double extremeLow,
double extremeHigh,
double lastStochastic,
double previousStochastic)
Buy when the Oscillator (either the Stochastic %K or its moving average %D) falls below a specific level (e.g. 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g. 80) and then falls below that level. This approach is the preferred method of the Stochastics original creator George Lane.
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.extremeHigh - this is the level at which the Stochastic is believed to indicate an over brought level. The Stochastic always lies between 0 and 100, and a suggested extreme high value is 80.lastStochastic - this is the last value of the Stochastic (either %K or %D).previousStochastic - this is the previous value of the Stochastic (either %K or %D)
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated.
public int[] extremeValueKSignalPeriod(double extremeLow,
double extremeHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods)
Buy when the the Stochastic %K falls below a specific level (e.g. 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g. 80) and then falls below that level. This approach is the preferred method of the Stochastics original creator George Lane.
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.extremeHigh - this is the level at which the Stochastic is believed to indicate an over brought level. The Stochastic always lies between 0 and 100, and a suggested extreme high value is 80.high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic as provided by (double[], double[], double[], int) kFastStochasticPeriod.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated for each of the periods considered. Where
the first term is the trading signal for the earliest period and the second term is
the trading signal for the precious period and so on.extremeValueSignal - his indicator is a special case of extremeValueKSignalPeriod
and calculates the extremeValueSignal indicator for a single period.
public int[] extremeValueDSignalPeriod(double extremeLow,
double extremeHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Buy when the Oscillator the Stochastic %D falls below a specific level (e.g. 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g. 80) and then falls below that level. This approach is the preferred method of the Stochastics original creator George Lane.
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.extremeHigh - this is the level at which the Stochastic is believed to indicate an over brought level. The Stochastic always lies between 0 and 100, and a suggested extreme high value is 80.high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.method - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
lengthOfMA - the number of periods over which the moving average is evaluated.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated for each of the periods considered. Where
the first term is the trading signal for the earliest period and the second term is
the trading signal for the precious period and so on.extremeValueSignal - this indicator is a special case of extremeValueKSignalPeriod
and calculates the extremeValueSignal indicator for a single period.
public int crossingSignal(double firstStochasticLast,
double firstStochasticPrevious,
double secondStochasticLast,
double secondStochasticPrevious)
Methodology
Buy when the Stochastic %K, crosses above the MA %D and sell when the Stochastic %K falls below the MA of Stochastic %D. Since this approach is prone to being whip-sawed we use two (general) Stochastics so that a MA of the %K Stochastic of the first Stochastic and an even more smoothed second Stochastic. In this case a sell signal is generated if the first (more sensitive) Stochastic cross below the second (smoothed) Stochastic, and a buy signal is generated if the first Stochastic crosses above the second Stochastic.
firstStochasticLast - the last value of the first Stochastic. Where the first Stochastic is either the (fast) %K Stochastic or a smoothed moving average of this indicator.firstStochasticPrevious - the previous value of the first Stochastic.secondStochasticLast - the last value of the second Stochastic.secondStochasticPrevious - the previous value of the second Stochastic is a moving average of the first stochastic.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal respectively was generated.
public int[] crossingSignalPeriod(double[] firstStochastic,
double[] secondStochastic)
Methodology
Buy when the Stochastic %K, crosses above the MA %D and sell when the Stochastic %K falls below the MA of Stochastic %D. Since this approach is prone to being whip-sawed we use two (general) Stochastics so that a MA of the %K Stochastic of the first Stochastic and an even more smoothed second Stochastic. In this case a sell signal is generated if the first (more sensitive) Stochastic cross below the second (smoothed) Stochastic, and a buy signal is generated if the first Stochastic crosses above the second Stochastic.
firstStochastic - a double array of either the (fast) %K Stochastic or a smoothed moving average of the %K Stochastic. Where the 1st term of the array is the %K Stochastic for the most recent periods, and the 2nd term is the %K Stochastic for the next most recent periods and so on.secondStochastic - a double array of the %D Stochastic where the 1st term of the array is the %D Stochastic for the most recent periods, and the 2nd term is the %D Stochastic for the next most recent periods and so on.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal respectively was generated for each of the periods considered.
Where the first term is the trading signal for the earliest period and the second term is
the trading signal for the precious period and so on.crossingSignal - this indicator is a special case of crossingSignalPeriod
and calculates the crossingSignal for a single period.
public int[] crossingSignal(double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
Methodology
Buy when the Stochastic %K, crosses above the MA %D and sell when the Stochastic %K falls below the MA of Stochastic %D. Since this approach is prone to being whip-sawed we use two (general) Stochastics so that a MA of the %K Stochastic of the first Stochastic and an even more smoothed second Stochastic. In this case a sell signal is generated if the first (more sensitive) Stochastic cross below the second (smoothed) Stochastic, and a buy signal is generated if the first Stochastic crosses above the second Stochastic.
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.method - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
lengthOfMA - the number of periods over which the moving average is considered
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated for each of the periods considered. Where
the first term is the trading signal for the earliest period and the second term is
the trading signal for the precious period and so on.crossingSignal - this indicator is a special case of crossingSignalPeriod,
calculates the crossingSignal for a single period.
public int crossingExtremeSignal(double extremeLow,
double extremeHigh,
double firstStochasticLast,
double firstStochasticPrevious,
double secondStochasticLast,
double secondStochasticPrevious)
This system generates buy and sell signals respectively when one of the following is triggered:
extremumLow, then a buy signal is generated.
extremumHigh, then a sell signal in generated.
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.extremeHigh - this is the level at which the Stochastic is believed to indicate an over brought level. The Stochastic always lies between 0 and 100, and a suggested extreme high value is 80.firstStochasticLast - the last value of the first Stochastic. Where the first Stochastic is either the (fast) %K Stochastic or a smoothed moving average of this indicator.firstStochasticPrevious - the previous value of the first Stochastic.secondStochasticLast - the last value of the second Stochastic.secondStochasticPrevious - the previous value of the second Stochastic is a moving average of the first stochastic.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated.crossingExtremeSignalPeriod - this indicator is a
general case of crossingExtremeSignal and calculates the crossingSignal for more periods.
public int[] crossingExtremeSignalPeriod(double extremeLow,
double extrememHigh,
double[] high,
double[] low,
double[] close,
int noOfPeriods,
int method,
int lengthOfMA)
This system generates buy and sell signals respectively when one of the following is triggered:
extremumLow, then a buy signal is generated.
extremumHigh, then a sell signal in generated.
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.method - determines the methods used for the evaluation of the moving average in accordance with the following key: For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.
lengthOfMA - the number of periods over which the moving average is considered.
-1, 0, 1, respectively; to indicate that either a
sell, no action or buy signal was generated for each of the periods considered. Where
the first term is the trading signal for the earliest period and the second term is
the trading signal for the precious period and so on.crossingExtremeSignal - this indicator is a special case
of crossingExtremeSignalPeriod and calculates the crossingSignal for a single period.
|
WebCab Technical Analysis v1.1 (J2SE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||