|
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.Momentum
Indicators including Momentum, highest/lowest, Trend Intensity Index; which measure the Momentum seen in the market. The Momentum describes the degree to which the market trends and is generally applied to the study of price dynamics, and in particular to help identify up or down trends at a specified moment in time.
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 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 | |
Momentum()
Creates a new instance. |
|
| Method Summary | |
double |
highest(double[] prices,
int noOfPeriods)
Returns the highest value of all prices within a given look back period. |
double[] |
highestPeriod(double[] prices,
int noPeriods)
Returns an array of the highest values for all look back sub-periods of a given length. |
int |
highestPosition(double[] prices,
int noOfPeriods)
Returns the position of the highest value of the price over a look back period. |
double |
lowest(double[] prices,
int noOfPeriods)
Returns the lowest value of all prices within a given look back period. |
double[] |
lowestPeriod(double[] prices,
int noOfPeriods)
Returns an array of the lowest values for all look back sub-periods of a given length. |
int |
lowestPosition(double[] prices,
int noOfPeriods)
Returns the position in which lowest value of the prices array for the specified period was recorded. |
double |
momentumIndicator(double close,
double nperiodPrice)
We evaluate the n-period momentum which is simply the difference between todays closing price and the close price n periods ago. |
double |
momentumPct(double close,
double nperiodPrice)
We calculate the momentum percentage which measures the percentage change of the closing price with the price n periods before. |
double[] |
momentumPctPeriod(double[] prices,
int noOfPeriods)
We calculate the momentum percentage over a given period. |
double[] |
momentumPeriod(double[] close,
int noOfPeriods)
We evaluate the n-period momentum which is simply the difference between today's closing price and the close price n periods ago, for all periods for which sufficient historical data is given. |
double |
trendIntensityIndex(double[] prices,
int lengthOfMA)
Trend Intensity Index measures the strength of a trend by comparing the deviation of the price with its corresponding moving average. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Momentum()
| Method Detail |
public double momentumIndicator(double close,
double nperiodPrice)
Extended values and/or turning points of the momentum are good indicators of oversold or over brought conditions (respectively).
close - the last closing price of the asset considered.nperiodPrice - the closing price of the asset considered n periods ago.
IllegalArgumentException - thrown if either parameter is strictly negative.
public double[] momentumPeriod(double[] close,
int noOfPeriods)
Remark: Extended values and/or turning points of the momentum are good indicators of oversold or over brought conditions (respectively).
close - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the closing price in the last trading period, the second term is the closing price in the previous trading period and so on.noOfPeriods - the number of periods before to which the closing price is compared.
IllegalArgumentException - thrown if either parameter is strictly negative.
public double momentumPct(double close,
double nperiodPrice)
The closing (or current) price divided by the price from n periods previous and then
multiplied to 100, to give the percentage where 1 percent = 1, of the change of the present
price with the price n periods beforehand. This indicator will oscillate around the long term trend
rate of the given asset is questions. That is, if the asset is mean reverting then the indicators
will oscillate around 100, over the log term. However, if the market has a long term up trend such
as the SP500, then the indicators will oscillator around a value higher than 100 + X,
where X is the long term trend rate of the market in question.
The application of the indicator to identify a trend is very straight forward. When the values of
the indicator are less then 100, it indicates a down trend and when the values are
above 100, it indicate an up trend.
close - the last closing price of the asset.nperiodPrice - the closing price of the asset n periods ago.
IllegalArgumentException - thrown if either parameter is strictly negative.
public double[] momentumPctPeriod(double[] prices,
int noOfPeriods)
momnetumPct method. Instead of taking into account only
one value of the closing price we calculate the momentum percentage over a entire period.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the closing price in the last trading period, the second term is the closing price in the previous trading period and so on.noOfPeriods - the number of periods before to which the closing price is compared.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.
public double highest(double[] prices,
int noOfPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the value of the highest value is 103, which is the highest value within { 101, 100, 103, 102 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.noOfPeriods - the number of previous periods over which the highest value is found (i.e. the look back period).
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.highestPeriod
public double[] highestPeriod(double[] prices,
int noPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the highest value over the first look back period is 103, which is the lowest value within { 101, 100, 103, 102 }. Now when the look back period is shift back a period to { 102, 101, 100, 103 }, highest value is 103, and hence in this case the returned array would be { 103, 103 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.noPeriods - the number of periods previous within the look back period over which the highest value is found.
noPeriods-periods back from the present period), the second term is
the high for the previous look back period (i.e. noPeriods-periods back from
the previous period), and so on. Note that the length of the returned array is equal to the
length of the prices array minus noPeriods - 1.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.highest
public double lowest(double[] prices,
int noOfPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the value of the lowest value is 100, which is the highest value within { 101, 100, 103, 102 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.noOfPeriods - the number of previous periods over which the lowest value is found (i.e. look back period).
IllegalArgumentException - thrown if prices array has strictly negative elements
or if the noOfPeriods argument is greater then the length of prices array.lowestPeriod
public double[] lowestPeriod(double[] prices,
int noOfPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the lowest value over the first look back period is 100, which is the lowest value within { 101, 100, 103, 102 }. Now when the look back period is shift back a period to { 102, 101, 100, 103 }, lowest value is 100, and hence in this case the returned array would be { 100, 100 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.
noPeriods-periods back from the present period), the second term is
the low for the previous look back period (i.e. noPeriods-periods back from
the previous period), and so on. Note that the length of the returned array is equal to the
length of the prices array minus noPeriods - 1.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.lowest
public int highestPosition(double[] prices,
int noOfPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the position of the highest is 1, corresponding to 103, which is the highest value within { 101, 100, 103, 102 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.noOfPeriods - the number of periods from the present period (i.e. look back period) over which the position of the highest value is sort.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.
public int lowestPosition(double[] prices,
int noOfPeriods)
We illustrate the application of this method with the following example. If the prices over the past five periods are: { 102, 101, 100, 103, 102 }, and the look back period has 3 periods, then the position of the lowest is 2, corresponding to 100, which is the lowest value within { 101, 100, 103, 102 }.
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.noOfPeriods - the number of periods before to which the price is compared.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
noOfPeriods argument is greater then the length of prices array.
public double trendIntensityIndex(double[] prices,
int lengthOfMA)
If the price is greater than the moving average a positive deviation is recorded, and if price is less than the moving average a negative deviation is recorded. Where the size of the deviation in each case is simply the (absolute) difference between the price and the moving average. The indicator is given by the following formula:
TTI = 100 * ( Sum of Positive Deviations ) / ( ( Sum of Positive Deviations ) + ( Sum of Negative Deviations ) )
prices - an array of length equal to the number of periods considered in the indicator evaluation where the first element is the price in the last trading period, the second term is the price in the previous trading period and so on.lengthOfMA - the number of periods considered within the evaluation of the moving average of each of the periods on which it can be evaluated.
IllegalArgumentException - thrown if prices array has strictly negative elements or if the
lengthOfMA argument is greater then the length of prices array.
|
WebCab Technical Analysis v1.1 (J2SE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||