Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 559 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Getting Implied Volatility from contractVol #466184
05/29/17 19:23
05/29/17 19:23
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
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?

Re: Getting Implied Volatility from contractVol [Re: GreenBoat] #466185
05/29/17 20:06
05/29/17 20:06
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
My guess would be that Price is the price of the underlying asset, and Value is the value of the option.

Re: Getting Implied Volatility from contractVol [Re: Dalla] #466188
05/29/17 22:53
05/29/17 22:53
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
Of course! Why didn't I think of that laugh
Thanks!

Re: Getting Implied Volatility from contractVol [Re: GreenBoat] #466192
05/30/17 10:44
05/30/17 10:44
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
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.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1