Historical Volatility

ICE Data Services -

histVolatility() Built-in Study Functions


Historical volatility is a measure of how much the price fluctuated during a given time period.While historical volatility can be indicative of future volatility, it can also differ greatly from future volatility, depending on what was driving the price changes during the past period. Major expected news items are more important drivers of big moves in the price in the near future. In short, historical volatility is a very rough guide for future volatility, and therefore for implied volatility, which is used to price options. However, historical volatility can be a poor guide for implied volatility in certain situations.


Syntax

histVolatility( nLength , nLookback [, Series | sym() | inv() ][, nBarIndex ] )


Parameters

Parameter: Description: Default:
nLength Required. Number of bars to use for calculation volatility for a bar. n/a
nLookback Required. Number of bars that defines the time period for which volatility is calculated. n/a
Series or
sym() or
inv()
[Optional]  Series Object or function of sym() or inv() to determine symbol/interval source for the study. Base sym/inv
nBarIndex [Optional]   Bar index of series to retrieve . n/a


Return Value(s)

Returns a Series Object when nBarIndex is not specified.

Returns a single value when nBarIndex is specified.


Notes

Only available in versions 12.1 or later.

 

Code Examples

Single Line Indicator:
function main() {
  return histVolatility(14, 252);
}

 

Single Line Study-on-Study Indicator:
function main() {
  return histVolatility(14, 252, hl2());
}

 

Retrieve single values:

function main(){
	var nValue_0 = histVolatility(14, 252, 0); 
	// Current Bar Index    
	var nValue_1 = histVolatility(14, 252, -1); 
	// Prior Bar Index            
	return new Array(nValue_0, nValue_1);
    
}

 

Initialize a Series Object:
var xStudy = null;

function main(){
	if (xStudy == null)	{
		xStudy = histVolatility(14, 252);
	} 
	// retrieve single values for conditional statements 
	var nValue_0 = xStudy.getValue(0); 
	// Current Bar Index value 
	var nValue_1 = xStudy.getValue(-1); 
	// Prior Bar Index value 
	return nValue_0; 
	// Plot Current Bar Index Value
	}
 
Initialize a Series Object based on an external interval:
var xStudy = null;
var bInit = false; 
// Initialization flag
function main() { 
    if (bInit == false) { 
        xStudy = histVolatility(14, 252, inv(20)); // 20-min interval 
        bInit = true; 
        
    } // retrieve single values for conditional statements 
        var nValue_0 = xStudy.getValue(0); // Current Bar Index value
        var nValue_1 = xStudy.getValue(-1); // Prior Bar Index value 
        return getSeries(xStudy); // Synchronized Series plot
 }

 

Initialize a Series Object based on an external symbol and interval:
var xStudy = null;
var bInit = false;
// Initialization flag
function main() {
if (bInit == false) {
xStudy = histVolatility(14, 252, sym("IBM,20")); // IBM 20-min interval
bInit = true;

} // retrieve single values for conditional statements
var nValue_0 = xStudy.getValue(0); // Current Bar Index value
var nValue_1 = xStudy.getValue(-1); // Prior Bar Index value
return getSeries(xStudy); // Synchronized Series plot
}

 

See Also

Series Object
getSeries()
Built-in Study Functions
eSignal Forum Search Engine
Help Guides and Tutorials