Getting Implied Volatility from contractVol

Posted By: GreenBoat

Getting Implied Volatility from contractVol - 05/29/17 19:23

I am trying to get implied volatility from the function contractVol.

I don't understand the specification of the function contractVol.

From the manual:
contractVol (CONTRACT*, var Price, var HistVol, var Value, var Dividend, var RiskFree): var

What is Price and Value? If Price is the price of the option, then what is Value?
Posted By: Dalla

Re: Getting Implied Volatility from contractVol - 05/29/17 20:06

My guess would be that Price is the price of the underlying asset, and Value is the value of the option.
Posted By: GreenBoat

Re: Getting Implied Volatility from contractVol - 05/29/17 22:53

Of course! Why didn't I think of that laugh
Thanks!
Posted By: GreenBoat

Re: Getting Implied Volatility from contractVol - 05/30/17 10:44

I can't make it work.

This is my script:
Code:
#include <contract.c> // needed for options
#include <r.h>

/* Test of R */

function run()
{
	BarPeriod = 1440; // 1 bar is 24 hours
	StartDate = 20060101;
	EndDate = 20061231;
	set(PRELOAD|LOGFILE|PLOTNOW);
	PlotHeight1 = 1024; // height of the chart with results
	PlotWidth = 1700;

	assetList("AssetsIB");
	assetHistory("SPY",FROM_YAHOO); // ticker
	asset("SPY");
	if(is(INITRUN)) {
		initRQL();	// run R
		dataLoad(1,"SPY_Options.t8",9);
	}

// load today's contract chain
	contractUpdate(Asset,1,CALL|PUT);
	Multiplier = 100;

// prices
	vars Price = series(price());
	vars Close = series(priceClose());
  	vars Vol = series(Volatility(Price,20));
  	if(is(LOOKBACK)) return;
	
// determine the current underlying price (unadjusted)
	var CurrentPrice = Contracts->fUnl;
	
// choose contract
	CONTRACT* CImp = contract(PUT|ONLYW3,20,CurrentPrice);

// Implied Volatility test
  	var OptionPrice = contractPrice(CImp); // bid/ask average price
	var ImpliedVol = contractVol(CImp,CurrentPrice,Vol[0],OptionPrice,0,0); // calculate Implied volatility
	printf("#nImpliedVol %i ",ImpliedVol);
}



Log file:
Code:
[85: Tue 06-01-10 00:00] (128.3900)
ImpliedVol 0 

[86: Wed 06-01-11 00:00] (129.0200)
ImpliedVol 0 

[87: Thu 06-01-12 00:00] (129.0800)
ImpliedVol 0 

[88: Fri 06-01-13 00:00] (128.5700)
ImpliedVol 0



I am not sure if the problem is with RQuantLib or wrong function inputs.
© 2024 lite-C Forums