2 registered members (VoroneTZ, TipmyPip),
1,333
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
unexpected behaviour with R bridge
#476536
03/08/19 10:37
03/08/19 10:37
|
Joined: Jan 2017
Posts: 13
nocide
OP
Newbie
|
OP
Newbie
Joined: Jan 2017
Posts: 13
|
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?
|
|
|
Re: unexpected behaviour with R bridge
[Re: jcl]
#476543
03/08/19 14:22
03/08/19 14:22
|
Joined: Jan 2017
Posts: 13
nocide
OP
Newbie
|
OP
Newbie
Joined: Jan 2017
Posts: 13
|
Ok, I've tracked down to this values and got following error: > Type <- 'put' > Strike <- 335 > Expiry <- 0.4 > Price <- 257 > Value <- 78.7 > Volatility<- 0.03 > Dividend <- 0.02 > RiskFree <- 0.01 > Vol <- AmericanOptionImpliedVolatility(Type,Value,Price,Strike,Dividend,RiskFree,Expiry,Volatility) Fehler in americanOptionImpliedVolatilityEngine(type, value, underlying, : root not bracketed: f[1e-007,4] -> [1.047432e-002,1.953335e+002] Since Price+Value (257+78,7) is bigger than Strike (335), this code in contract.c doesn't prevent the crash (and should probably be improved):
if((c->Type&PUT) && Price+Value <= Strike) return 0.;
So it seems, the value is to small for this contract? Which part should be improved, to prevent this sort of problem?
|
|
|
|