WebCab Options and Futures Demo v2.5 (J2SE Edition)

## webcab.lib.finance.options
Class Volatility

    java.lang.Object
      |
      +--webcab.lib.finance.options.Volatility

All Implemented Interfaces:
  Serializable

public class Volatility
extends Object
implements Serializable

This class consists of a collection of methods for estimating and rescaling the volatility. Recall, that the volatility of an asset is merely the standard deviation of the price function and is used to measure the degree of uncertainty which the price function displays.

The methods provided for estimating the volatility include:

- Standard historical estimate
- Autoregressive Conditional Heteroscedasticity (ARCH)
- Exponentially Weighted Moving Average (EWMA)
- Generalized Autoregressive Conditional Heteroscedasticity (GARCH)

An important issue in the estimation of the volatility is whether all days or only trading days should be taken into account. That is, is the volatility a phenomenon generated from trading activity or is volatility created from external factors. Where appropriate we will allow the user of this class to select which point of view to adopt.

See Also:
  Serialized Form

Constructor Summary
`Volatility()` Creates a new instance.

Method Summary
`double` `archVolatilityEstimate(double longTermVolatility, double weightOfVolatility, double[] observations, double[] weights)` Returns the estimate of the volatility according to the ARCH model.
`double` `daysYearRescaling(double volPerPeriod, double daysInPeriod, int convention)` Evaluates the annual volatility when the volatility of a given number of days is known.
`double` `ewmaVolatilityEstimate(double weightRatio, double i_1thDayEstimateOfVolatility, double endi_1thDay, double starti_1thDay)` This method returns the estimate of the volatility for the ith day made at the end of the previous (i-1)th day, using an estimate of the volatility on the (i-1)th day according to the EWMA model with respect to changes in the market variable.
`double` `ewmaVolatilityEstimateInduction(double weightRatio, double firstDaysVolatilityEstimate, double[] endOfDay, double[] startOfDay)` Estimates of the volatility for the ith day made at the end of the previous (i-1)th day, using an estimate of the volatility on the 0th day, according to the EWMA model with respect to changes in the market variable.
`double` `garchVolatilityEstimate(double longTermVariance, double longTermVarianceWeight, double ithDayVolatilityEstimate, double ithDayVolatilityEstimateWeight, double ithDayAssetPrice, double i_1thDayAssetPrice, double assetPriceWeight)` Estimates of the volatility according to the GARCH(1,1) model for the (i+1)th day.
`double` `historicalEstimate(double[] assetPrices)` Evaluates the historical estimate of the present volatility.
`double` `historicalEstimateStandardError(double numberOfDays, double volatilityEstimate)` Returns the estimate of the standard error of the standard historical estimation given by the functions volatilityHistoricalEstimate and volatilityHistoricalEstimateWithDividends.
`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` `returnDuringithDay(double ithDayAssetPrice, double i_1thDayAssetPrice)` This function returns the continuously compounded return of an asset over one day which is required by the method garchVolatilityEstimate.
`double` `variance(double[] historicalReturns)` Evaluates the variance of the historical returns of an asset.
`double` `variance(double[] probability, double[] returns)` Calculates the variance of the expected returns of an asset given the assets returns in given market states and the probability of those market states occurring.
`double` `yearDaysRescaling(double volPerAnnum, double daysRescaledTo, int convention)` Calculates the value of the volatility over a given number of days when the annual volatility is known.

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

### yearDaysRescaling

    public double yearDaysRescaling(double volPerAnnum,
                                    double daysRescaledTo,
                                    int convention)
                             throws OptionsException,
                                    VolatilityDemoException

  Calculates the value of the volatility over a given number of days when the annual volatility is known. The annual volatility may be given with respect to either the 252, 360 or 365 days convention.

  Parameters:
    `volPerAnnum` - is the volatility per annum expressed in decimal format (i.e. 1 pecent = 0.01)
    `daysRescaledTo` - is the number of days which the volatility is rescaled to. In particular, the doubled returned with represent volatility per d days.
    `convention` - One of the day count conventions listed inside the OptionsConstants class: ANNUAL_DAY_COUNT_252, ANNUAL_DAY_COUNT_360, or ANNUAL_DAY_COUNT_365.
  Throws:
    `OptionsException` - thrown when the day count convention is not correctly specified
    `VolatilityDemoException`
  See Also:
    `OptionsConstants.ANNUAL_DAY_COUNT_252`, `OptionsConstants.ANNUAL_DAY_COUNT_360`, `OptionsConstants.ANNUAL_DAY_COUNT_365`

### daysYearRescaling

    public double daysYearRescaling(double volPerPeriod,
                                    double daysInPeriod,
                                    int convention)
                             throws OptionsException,
                                    VolatilityDemoException

  Evaluates the annual volatility when the volatility of a given number of days is known. The annual volatility may be evaluated with respec to either the 252, 360 or 365 days convention.

  Parameters:
    `volPerPeriod` - the volatility over the given number days considered.
    `daysInPeriod` - the number of days in period over which volatility is known. In the case that the daily volatility is given this parameter will be 1.
    `convention` - One of the day count conventions listed inside the OptionsConstants class: ANNUAL_DAY_COUNT_252, ANNUAL_DAY_COUNT_360, or ANNUAL_DAY_COUNT_365.
  Throws:
    `OptionsException` - thrown when the day count convention is not correctly specified
    `VolatilityDemoException`
  See Also:
    `OptionsConstants.ANNUAL_DAY_COUNT_252`, `OptionsConstants.ANNUAL_DAY_COUNT_360`, `OptionsConstants.ANNUAL_DAY_COUNT_365`

### historicalEstimate

    public double historicalEstimate(double[] assetPrices)
                              throws VolatilityDemoException

  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 days used in order to historical estimate the present daily volatility should (in generally) be between 90 and 180 days.

  Parameters:
    `assetPrices` - an array of the assets price at the end of each interval. Note that if we use daily values of the asset price then this methods will return an estimate of the daily volatility.
    `VolatilityDemoException`
  See Also:
    `historicalEstimateWithDividends(double[], double[])`

### historicalEstimateWithDividends

    public double historicalEstimateWithDividends(double[] assetPrices,
                                                  double[] dividendsPaid)
                                           throws OptionsException,
                                                  VolatilityDemoException

  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 of the assets market value at the end of each 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 of the dividends (or interest payments) from the asset within each 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.
  Throws:
    `OptionException` - thrown when the number of asset prices is not equal to the number of dividends
    `OptionsException`
    `VolatilityDemoException`
  See Also:
    `historicalEstimate(double[])`

### historicalEstimateStandardError

    public double historicalEstimateStandardError(double numberOfDays,
                                                  double volatilityEstimate)
                                           throws VolatilityDemoException

  Returns the estimate of the standard error of the standard historical estimation given by the functions volatilityHistoricalEstimate and volatilityHistoricalEstimateWithDividends.

  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:
    `numberOfDays` - the number of days over which the historical data is taken
    `volatilityEstimate` - estimate of the volatility per annum
    `VolatilityDemoException`

### archVolatilityEstimate

    public double archVolatilityEstimate(double longTermVolatility,
                                         double weightOfVolatility,
                                         double[] observations,
                                         double[] weights)
                                  throws OptionsException,
                                         VolatilityDemoException

  Returns the estimate of the volatility according to the ARCH model. If the sum of the weights is not within 0.1 of 1, or the number of weights does not correspond to the number of observations them the method will throw an exception. Note that for the input arrays the first value `observations[0]` is the latest observation and `observations[1]` is the previous observation and so on.

  Parameters:
    `observations` - an array of historical observations
    `weights` - an array of weights associated to the historical observations
    `longTermVolatility` - this is the long term volatility
    `weightOfVolatility` - this is the weight assigned to the volatility
  Throws:
    `OptionsException` - thrown when the number of observations is not equal to the number of weights
    `VolatilityDemoException`

### ewmaVolatilityEstimate

    public double ewmaVolatilityEstimate(double weightRatio,
                                         double i_1thDayEstimateOfVolatility,
                                         double endi_1thDay,
                                         double starti_1thDay)
                                  throws VolatilityDemoException

  This method returns the estimate of the volatility for the ith day made at the end of the previous (i-1)th day, using an estimate of the volatility on the (i-1)th day according to the EWMA model with respect to changes in the market variable. The EWMA model is a special case of the ARCH model, where the weights assigned to the historical volatility measure decreases by a constant factor.

  Remarks:

  - Updating Formulae - this method updates the volatility estimate for the (i-1)th day with the volatility estimate for the ith day. This method can be inductively applied in order to derive the volatility on the ith day from the volatility on the 0th day. This method `ewmaVolatilityEstimateInduction` is an implementation of this.
  - Weight Ratio - J.P.Morgan's Riskmetrics group found that across a range of market variables, by taking weightRatio = 0.94, the forecasts of the volatility rate came closest to the realized volatility.
  - Market Variable - the volatility can to measured with respect to any market variable. The most common used market variable will be asset price in which case this method will estimate the volatility of the price.

  Parameters:
    `weightRatio` - this constant between one and zero, is the ratio between the ith weight and the (i-1)th weight. The smaller the value used the more sensitive the model is to resent changes in the volatility.
    `i_1thDayEstimateOfVolatility` - this is the previous reading or estimate of the volatility on the (i-1)th day
    `endi_1thDay` - the market variable (for example, asset price) at the close of the (i-1)th day
    `starti_1thDay` - the market variable (for example, asset price) at the start of the (i-1)th day
    `VolatilityDemoException`
  See Also:
    `ewmaVolatilityEstimateInduction(double, double, double[], double[])`

### ewmaVolatilityEstimateInduction

    public double ewmaVolatilityEstimateInduction(double weightRatio,
                                                  double firstDaysVolatilityEstimate,
                                                  double[] endOfDay,
                                                  double[] startOfDay)
                                           throws VolatilityDemoException

  Estimates of the volatility for the ith day made at the end of the previous (i-1)th day, using an estimate of the volatility on the 0th day, according to the EWMA model with respect to changes in the market variable. The EWMA model is a special case of the ARCH model, where the weights assigned to the historical volatility measure decreases by a constant factor.

  Remarks:

  - Weight Ratio - J.P.Morgan's Riskmetrics groups found that across a range of market variables, by taking weightRatio = 0.94, the forecasts of the volatility rate came closest to the realized volatility.
  - Market Variable - the volatility can to measured with respect to any market variable. The most common used market variable will be asset price in which case this method will estimate the volatility of the price.

  Parameters:
    `weightRatio` - this constant between one and zero, is the ratio between the kth weight and the (k-1)th weight, for all k. The smaller the value used the more sensitive the model is to resent changes in the volatility.
    `firstDaysVolatilityEstimate` - this is the estimate of the volatility on the 0th day
    `endOfDay` - this is an array of length i+1, where the first term is the closing value of the market variable (for example, the asset price) on the 0th day, the second element is the closing value of the market variable on the 1st day and so on...
    `startOfDay` - this is an array of length i+1, where the first term is the opening value of the market variable (for example, the asset price) on the 0th day, the second element is the opening value of the market variable on the 1st day and so on...
    `VolatilityDemoException`
  See Also:
    `ewmaVolatilityEstimate(double, double, double, double)`

### returnDuringithDay

    public double returnDuringithDay(double ithDayAssetPrice,
                                     double i_1thDayAssetPrice)
                              throws VolatilityDemoException

  This function returns the continuously compounded return of an asset over one day which is required by the method garchVolatilityEstimate.

  Parameters:
    `ithDayAssetPrice` - this in the asset price at the close of business on the ith day
    `i_1thDayAssetPrice` - this is the asset price at the close of business on the i-1th day excelFunction return
    `VolatilityDemoException`

### variance

    public double variance(double[] probability,
                           double[] returns)
                    throws VolatilityDemoException

  Calculates the variance of the expected returns of an asset given the assets returns in given market states and the probability of those market states occurring.

  Parameters:
    `probability` - `probability[s]` is the probability of the state `s` occurring
    `returns` - `returns[s]` is the return (increase in market value) for the asset in the state `s`
    `VolatilityDemoException`

### variance

    public double variance(double[] historicalReturns)
                    throws VolatilityDemoException

  Evaluates the variance of the historical returns of an asset.

  Parameters:
    `historicalReturns` - `historicalReturns[t]` is the return of the asset in the `t`th period
    `VolatilityDemoException`

### garchVolatilityEstimate

    public double garchVolatilityEstimate(double longTermVariance,
                                          double longTermVarianceWeight,
                                          double ithDayVolatilityEstimate,
                                          double ithDayVolatilityEstimateWeight,
                                          double ithDayAssetPrice,
                                          double i_1thDayAssetPrice,
                                          double assetPriceWeight)
                                   throws OptionsException,
                                          VolatilityDemoException

  Estimates of the volatility according to the GARCH(1,1) model for the (i+1)th day. Note that the sum of the weights associated with the long term variance, previous estimate of the volatility and asset price should add up to one.

  Parameters:
    `longTermVariance` - long term average variance
    `longTermVarianceWeight` - the weight given to the long term variance
    `ithDayVolatilityEstimate` - the estimate of the volatility for the ith day
    `ithDayVolatilityEstimateWeight` - the weight given to the estimate of the volatility from the ith day
    `ithDayAssetPrice` - the market price of the asset at the close on the ith day
    `i_1thDayAssetPrice` - the market price of the underlying asset at the open of the previous business day
    `assetPriceWeight` - the weight associated within the model to the influence of the return on the asset over the last day.
  Throws:
    `OptionsException` - thrown when the sun of the weights associated with the long term variance, previous estimate of the volatility and the asset price are not equal to 1.
    `VolatilityDemoException`

WebCab Options and Futures Demo v2.5 (J2SE Edition)