WebCab Technical Analysis
v1.1
(J2SE Edition)

webcab.lib.finance.trading.indicators
Class Volatility

java.lang.Object
  |
  +--webcab.lib.finance.trading.indicators.Volatility
All Implemented Interfaces:
Serializable

public class Volatility
extends Object
implements Serializable

Allows the Volatility (Historical Estimate with(out) dividends, Standard Error) and the effect of Volatility (Chaikin's Volatility indicator) to be measured.

One Period and Multi Period Versions

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:

  1. ABCIndicator - Evaluation the indicator over the whole period of length N.
  2. 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.

See Also:
Serialized Form

Constructor Summary
Volatility()
          Creates a new instance.
 
Method Summary
 double[] chaikinVolatility(double[] highs, double[] lows, int lengthOfMA, int noOfPeriods)
          Evaluates Chaikin's Volatility indicator over a period which compares the spread between a security's high and low prices.
 double historicalEstimate(double[] assetPrices)
          Evaluates the historical estimate of the present volatility.
 double historicalEstimateStandardError(double numberOfPeriods, double volatilityEstimate)
          Returns the estimate of the standard error of the standard historical estimation given by the functions historicalEstimate(double[]) and historicalEstimateWithDividends(double[], double[]).
 double historicalEstimateWithDividends(double[] assetPrices, double[] dividendsPaid)
          Calculates the historical estimate of the present volatility taking into account the dividends or interest payments of the underlying asset.
 double returnDuringithPeriod(double ithPeriodAssetPrice, double i_1thPeriodAssetPrice)
          Evaluates the continuously compounded return of an asset over one period (for example a period).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Volatility

public Volatility()
Creates a new instance.

Method Detail

chaikinVolatility

public double[] chaikinVolatility(double[] highs,
                                  double[] lows,
                                  int lengthOfMA,
                                  int noOfPeriods)
Evaluates Chaikin's Volatility indicator over a period which compares the spread between a security's high and low prices. It quantifies volatility as a widening of the range between the high and the low price.

Indicator Formula

The formula for this indicator is:

chaikinVolatility = 100.( (HLAverage - HLAverage_n_periods_ago) / HLAverage_n_periods_ago ),

where HLAverage is the Exponential Moving Average of the difference between high and low of the current trading period, and HLAverage_n_periods_ago is the Exponential Moving Average of the difference between high and low of the trading period from n periods ago.

Parameters:
highs - an array of the trading highs over the last n-periods where the k-th terms of the array if the high on the k-th previous period.
lows - an array of the trading lows over the last n-periods where the k-th terms of the array if the trading lows on the k-th previous period.
lengthOfMA - the number of periods considered within the evaluation of the moving average for each of the periods on which it can be evaluated.
noOfPeriods - an integer which represents the number of previous time periods used over which the moving averages are compared.
Returns:
An array of length is equal to the length of the highs array minus the length of the moving average (lengthOfMA) where the 1st term of this array is the value of the indicator of the most resent period and the 2nd term of this array is the value of the indicator on the previous period and so on.
Throws:
IllegalArgumentException - thrown if either parameter is strictly negative or arrays closes or volumes are empty.
IllegalArgumentException - if the length of the highs and lows parameters provided are not equal.

historicalEstimate

public double historicalEstimate(double[] assetPrices)
Evaluates the historical estimate of the present volatility. This procedure uses the price data at the end of equal time intervals of an investment asset which does not pay dividends or interest payments in order to estimate its present volatility per interval. The number returned is the estimated (present) volatility per interval expressed in decimal format (i.e. 1 percent = 0.01). Hence if daily values of the assets price where used then this method will return the historical estimate of the daily volatility.

Choosing the number of historical points used

The historical estimate is evaluated using a given number of historical values of the assets market price. Care should be taken when deciding on the number of historical values to use within the historical estimate of the present volatility. A balance needs to be made between using a large sample (resulting in the small standard error) and a smaller sample which does not take too distant historical values which may not fully reflect the present market dynamics. As a rule of thumb the number of periods used in order to historical estimate the present daily volatility should (in generally) be between 90 and 180 periods.

Parameters:
assetPrices - an array of the assets price at the end of each interval where the 1st term is the most recent asset price and the 2nd term is the previous periods asset price and so on. Note that if we use daily values of the asset price then this methods will return an estimate of the daily volatility.
Returns:
A double which is an estimate of the present volatility based on historical values.
See Also:
historicalEstimateWithDividends

historicalEstimateStandardError

public double historicalEstimateStandardError(double numberOfPeriods,
                                              double volatilityEstimate)
Returns the estimate of the standard error of the standard historical estimation given by the functions historicalEstimate(double[]) and historicalEstimateWithDividends(double[], double[]).

Recall that the standard error is the standard deviation of the sampling distribution of that statistic. Standard errors are important because they reflect how much sampling fluctuations effect the reliability of the statistic, in this case the estimate of the volatility. The standard error of a statistic will depend on the sample size where generally the larger the sample size the smaller the standard error will be.

Parameters:
numberOfPeriods - the number of periods over which the historical data is used within the estimate of the volatility.
volatilityEstimate - estimate of the volatility per annum
Returns:
Double value of the Standard error associated with the historical volatility estimates historicalEstimate and historicalEstimateWithDividends.

historicalEstimateWithDividends

public double historicalEstimateWithDividends(double[] assetPrices,
                                              double[] dividendsPaid)
                                       throws IndicatorsException
Calculates the historical estimate of the present volatility taking into account the dividends or interest payments of the underlying asset.

Choosing the number of historical points used

The historical estimate is evaluated using a given number of historical values of the assets market price. Care should be taken when deciding on the number of historical values to use within the historical estimate of the present volatility. A balance needs to be made between using a large sample (resulting in the small standard error) and a smaller sample which does not take too distant historical values which may not fully reflect the present market dynamics. As a rule of thumb the number of days used in order to historical estimate the present daily volatility should (in generally) be between 90 and 180 days.

Parameters:
assetPrices - an array where the k-th term is the assets market value at the end of the k-th interval. Note that if we use daily values of the asset price then this method will return an estimate of the daily volatility.
dividendsPaid - an array where the k-th term corresponds to the dividends (or interest payments) from the asset within the k-th period. If we are estimating the daily volatility then the periods considered will correspond to days. The length of the array corresponding to the dividends (or interest payments) must have the same length as the array of asset prices used. If no payment is made within the i-th interval then the i-th element of the array in zero.
Returns:
A double which is an estimate of the present volatility based on historical values.
Throws:
OptionException - thrown when the number of asset prices is not equal to the number of dividends
IndicatorsException
See Also:
historicalEstimate(double[])

returnDuringithPeriod

public double returnDuringithPeriod(double ithPeriodAssetPrice,
                                    double i_1thPeriodAssetPrice)
Evaluates the continuously compounded return of an asset over one period (for example a period).

Parameters:
ithPeriodAssetPrice - this in the asset price at the close of business on the ith period (this period could be a period or a month etc).
i_1thPeriodAssetPrice - this is the asset price at the close of business on the i-1th period (this period could be a period or a month etc).
Returns:
Double value corresponding to the continuously compounded return of the asset considered.

WebCab Technical Analysis
v1.1
(J2SE Edition)