Consider the following code, where I try to calculate value and volatility of options from the generated
SPY option chain.
// Zorro v1.9.6.4
#include <contract.c>
#define DTE (42)
#define DIVIDEND (0.02)
function run()
{
set(LOGFILE);
BarPeriod = 1440; // 1 day bar
LookBack = 20;
StartDate = 20171018;
EndDate = 20171022;
assetList("AssetsIB");
asset("SPY");
// load todays' contract chain
contractUpdate("SPYa", 0, CALL);
if (is(LOOKBACK)) return;
var Price = priceClose();
var RiskFree = yield() / 100;
var HistVol = VolatilityOV(20);
// get first contract of today's bar
CONTRACT* c = Contracts;
var currVal = contractVal(c, Price, HistVol, DIVIDEND, RiskFree);
//var currVol = contractVol(c, Price, HistVol, currVal, DIVIDEND, RiskFree);
printf("<value=%.f>",currVal);
//printf("<value=%.f> <volatility=%.f>",currVal, currVol);
}
I get following output:
[27: Wed 17-10-18 15:40] (255.72)<value=80>
[28: Thu 17-10-19 15:40] (255.79)<value=80>
[29: Fri 17-10-20 15:40] (257.11)<value=78>
[30: Mon 17-10-23 15:40] (256.10)<value=79>
and when I add contractVol,
var currVal = contractVal(c, Price, HistVol, DIVIDEND, RiskFree, 0, 0, 0, 0, 0);
var currVol = contractVol(c, Price, HistVol, currVal, DIVIDEND, RiskFree);
//printf("<value=%.f>",currVal);
printf("<value=%.f> <volatility=%.f>",currVal, currVol);
I get following output:
[27: Wed 17-10-18 15:40] (255.72)<value=80> <volatility=0>
[28: Thu 17-10-19 15:40] (255.79)<value=80> <volatility=0>
[29: Fri 17-10-20 15:40] (257.11)<value=0> <volatility=0>
[30: Mon 17-10-23 15:40] (256.10)<value=0> <volatility=0>
Why I get the zero's and why the different result, when I just add a new function call against the R bridge?