SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:10 pm

QuoteI agree that returning a Boolean is not really nice. letting a user pass a policy that alows him to specify what type of behaviour he want is a userfriendy feature imo. I solved the "what shall I do, and what should the user do, or I want it to do it like this" problem.I agree.Quoteif you want to stick to the interface then NaN is a way of signaling an error using a double. Handling and checking NaN is however probdbly going to add a lot of boilerplate code?No.NaN is not the root cause. It is caused 'upstream' by setting S = 0 and then calling BS. If S <> 0 then we don't get this problem.A traceS = 0 => log(S/K) => NaN => goes into N() that thinks it has a number => BANG. Working backwards => "Customer is wrong". S = 0 ==> Show stopper. It has nothing to do with policies or clients; log(0) is just not on.
Last edited by Cuchulainn on March 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:36 pm

QuoteOriginally posted by: CuchulainnQuoteDoes one give a Husqvarna to a child?Trust no one.What happens if the user 1) no validation policy checks and 2) calls BS(y) with y < 0? Crash, _yes_? (1)Indeed! And why is a crash not the "correct" behavior for certain categories of code called with certain values of inputs? It's like a penalty clause in a contract. QuoteOriginally posted by: CuchulainnQuotePerhaps the signature of your code SHOULD be changed.No. You're kidding. Think of the consequences of your statement. You are changing the problem to fit your solution.You are probably right and my solution does not reflect all the clever features of C++. The point is there may be a category of user that wants the absolute highest possible runtime performance with the proviso that invalid values lead to a crash.
 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:39 pm

QuoteOriginally posted by: Traden4AlphaQuoteOriginally posted by: CuchulainnQuoteDoes one give a Husqvarna to a child?Trust no one.What happens if the user 1) no validation policy checks and 2) calls BS(y) with y < 0? Crash, _yes_? (1)Indeed! And why is a crash not the "correct" behavior for certain categories of code called with certain values of inputs? It's like a penalty clause in a contract. QuoteOriginally posted by: CuchulainnQuotePerhaps the signature of your code SHOULD be changed.No. You're kidding. Think of the consequences of your statement. You are changing the problem to fit your solution.You are probably right and my solution does not reflect all the clever features of C++. The point is there may be a category of user that wants the absolute highest possible runtime performance with the proviso that invalid values lead to a crash.The issues are really language-independent I think.Quotecategory of user that wants the absolute highest possible runtime performance Well, call log(S) with S = 0 and you will get fast response. "Customer is always wrong".
Last edited by Cuchulainn on March 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:41 pm

QuoteOriginally posted by: outrunI myself prefer pushing things upstream. Error checking can be done more efficient, and you know what you can expect... Nothing, ... very easy to exactly document.Wha happens if you forget?Upstream == at highest level client code? So S = 0 should be checked in a parser or Windows text box etc.? And don't forget?
Last edited by Cuchulainn on March 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:44 pm

QuoteOriginally posted by: CuchulainnQuoteI agree that returning a Boolean is not really nice. letting a user pass a policy that alows him to specify what type of behaviour he want is a userfriendy feature imo. I solved the "what shall I do, and what should the user do, or I want it to do it like this" problem.I agree.Quoteif you want to stick to the interface then NaN is a way of signaling an error using a double. Handling and checking NaN is however probdbly going to add a lot of boilerplate code?No.NaN is not the root cause. It is caused 'upstream' by setting S = 0 and then calling BS. If S <> 0 then we don't get this problem.A traceS = 0 => log(S/K) => NaN => goes into N() that thinks it has a number => BANG. Working backwards => "Customer is wrong". S = 0 ==> Show stopper. It has nothing to do with policies or clients; log(0) is just not on.One fix to N() is to invert the conditional to test If x<0, then call N(-x) else compute the formula.The existing structure contains the false assume that if not(x ≥ 0), then x < 0 which is true for real numbers but not for doubles.
 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 7:58 pm

QuoteOriginally posted by: Traden4AlphaQuoteOriginally posted by: CuchulainnQuoteI agree that returning a Boolean is not really nice. letting a user pass a policy that alows him to specify what type of behaviour he want is a userfriendy feature imo. I solved the "what shall I do, and what should the user do, or I want it to do it like this" problem.I agree.Quoteif you want to stick to the interface then NaN is a way of signaling an error using a double. Handling and checking NaN is however probdbly going to add a lot of boilerplate code?No.NaN is not the root cause. It is caused 'upstream' by setting S = 0 and then calling BS. If S <> 0 then we don't get this problem.A traceS = 0 => log(S/K) => NaN => goes into N() that thinks it has a number => BANG. Working backwards => "Customer is wrong". S = 0 ==> Show stopper. It has nothing to do with policies or clients; log(0) is just not on.One fix to N() is to invert the conditional to test If x<0, then call N(-x) else compute the formula.The existing structure contains the false assume that if not(x ≥ 0), then x < 0 which is true for real numbers but not for doubles.This is a symptom of y = 0 in this formuladouble d1 =( std::log(y/K) + (r+ (s2*s2)*0.5 ) * (t) )/ tmp;double d2 = d1 - tmp;N() will still crash IMO.Customer is wrong.
 
User avatar
AVt
Posts: 1074
Joined: December 29th, 2001, 8:23 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 8:13 pm

I do not quite understand the discussion: I would check *before* calling. As Traden4Alpha for said "P.S. You'll need to check the validity of these inputs" (for 0 < time [numerical] as well, etc). For me this is the difference between a "prototypic" and a productive solution.
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 8:21 pm

Well, Cuch, the underlying could reach 0.0 ;-)The option pricer had better take this into account (with the legal caveats amplifying the fun factor, as usual):http://investorplace.com/2011/04/option ... es/Dangers of Owning Puts Without Owning the Stock
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 8:35 pm

There's another little bug in N(). If you call N(x) with x = -1/0.33267 you might get a divide by zero although it won't be in the returned value. The calculation of k should be inside the conditional to avoid this and to prevent calculating k twice if x<0 .
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Simpl Black Code that is not robust: quiz and structural solution

March 25th, 2015, 9:02 pm

All of this seems to highlight a deeper flaw in either the language or development environment that lets one use data types in unsafe ways. A better language would allow one to adorn code with restrictions such as functions that only handle a subset of values of a datatype. A better IDE would use symbolic analysis to alert the programmer to potentially invalid, NaN, and crash conditions.It would be like outrun's "bank small print checker" in adorning function calls with warnings.
 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 26th, 2015, 6:33 am

QuoteOriginally posted by: PolterWell, Cuch, the underlying could reach 0.0 ;-)The option pricer had better take this into account (with the legal caveats amplifying the fun factor, as usual):http://investorplace.com/2011/04/option ... es/Dangers of Owning Puts Without Owning the StockIndeed. But does this necessarily mean that the algorithm should support the case S = 0? The software supplier could say:"If you provide S > 0 (require) I ensure that I will give you a price. I do not support S = 0". We hit a stone wall with log(S/K) when S = 0. Decisions.
Last edited by Cuchulainn on March 25th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Simpl Black Code that is not robust: quiz and structural solution

March 26th, 2015, 6:35 am

QuoteOriginally posted by: AVtI do not quite understand the discussion: I would check *before* calling. As Traden4Alpha for said "P.S. You'll need to check the validity of these inputs" (for 0 < time [numerical] as well, etc). For me this is the difference between a "prototypic" and a productive solution.How does on know what to check and what if you forget to check?
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On