Serving the Quantitative Finance Community

 
User avatar
mayl
Topic Author
Posts: 0
Joined: July 14th, 2002, 3:00 am

The joy of browsing J. London's "Modeling Derivatives in C++"

June 25th, 2006, 1:50 pm

There are probably a few threads in Wilmott on London's "Modeling Derivatives in C++". However, those all seem to be serious discussions. So I hope you will forgive me for starting a new one discussing the bits and pieces in that book that can make you laugh (as they say laughter is the best medicie).For the sake of my reputation, I strongly deny that I have actually read or intend to read the aforementioned book. I merely browsed through a few pages of it quickly in order to spot a few funny bits for my own entertainment before the start of the football game this afternoon. on page 492pu[j] = 0.167 + ...;pm[j] = 0.666 – ...;pd[j] = 0.167 + ...;on page 529,node->pu = (1.00000/6.00000) + ...;node->pm = (2.00000/3.00000) – ...;node->pd = (1.00000/6.00000) + ...;If you do what Mr. London did on page 492, your manager (a competent but aggressive front-office type, I assume) will scream at you until you burst into tears. If you do what Mr. London did on page 529, your colleagues will laugh at you until they burst into tears.OK, OK, I may have exagerated a bit and you may not find these lines of code funny at all. But please do share what you have found (do not waste too much time though).
 
User avatar
doreilly
Posts: 0
Joined: February 1st, 2005, 1:22 am

The joy of browsing J. London's "Modeling Derivatives in C++"

June 26th, 2006, 12:10 pm

QuoteOriginally posted by: maylThere are probably a few threads in Wilmott on London's "Modeling Derivatives in C++". However, those all seem to be serious discussions. So I hope you will forgive me for starting a new one discussing the bits and pieces in that book that can make you laugh (as they say laughter is the best medicie).For the sake of my reputation, I strongly deny that I have actually read or intend to read the aforementioned book. I merely browsed through a few pages of it quickly in order to spot a few funny bits for my own entertainment before the start of the football game this afternoon. on page 492pu[j] = 0.167 + ...;pm[j] = 0.666 – ...;pd[j] = 0.167 + ...;on page 529,node->pu = (1.00000/6.00000) + ...;node->pm = (2.00000/3.00000) – ...;node->pd = (1.00000/6.00000) + ...;If you do what Mr. London did on page 492, your manager (a competent but aggressive front-office type, I assume) will scream at you until you burst into tears. If you do what Mr. London did on page 529, your colleagues will laugh at you until they burst into tears.OK, OK, I may have exagerated a bit and you may not find these lines of code funny at all. But please do share what you have found (do not waste too much time though).So what exactly are we laughing/screaming at ?
 
User avatar
cemil

The joy of browsing J. London's "Modeling Derivatives in C++"

June 26th, 2006, 12:32 pm

I have another best suggestion instead of "on page 529, node->pu = (1.00000/6.00000) + ...;" you can write like this:on page 529,node->pu = (1.000000000000000000000000000000000000000000000000000000/6.0000000000000000000000000000) + ...;:-)
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

The joy of browsing J. London's "Modeling Derivatives in C++"

June 26th, 2006, 3:00 pm

QuoteOriginally posted by: doreillySo what exactly are we laughing/screaming at ?On the one hand, 0.167 and 0.666 are rounding 1/6 and 2/3 to three decimal places. Any result starting from those data will have at best that precision---probably much worse, as such rounding errors will accumulate at each tree node. With a few hundreds time steps the end result might carry a substantial relative error.On the other hand, 1.00000 is overkill. 1.0 is just as accurate. But at least, this one won't do any damage.Luigi
 
User avatar
Cuchulainn
Posts: 22937
Joined: July 16th, 2004, 7:38 am

The joy of browsing J. London's "Modeling Derivatives in C++"

June 26th, 2006, 4:33 pm

> On the other hand, 1.00000 is overkill. 1.0 is just as accurate. But at least, this one won't do any damage.LuigiEven better is Fortran: in this language you can wriite just "1."nice, yes? Saves a bit of typing.BTW bravo Italia oggi
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

The joy of browsing J. London's "Modeling Derivatives in C++"

June 26th, 2006, 6:45 pm

QuoteOriginally posted by: CuchulainnEven better is Fortran: in this language you can wriite just "1."Same in C/C++. But I like 1.0 better. Just personal taste.Luigi
 
User avatar
Cuchulainn
Posts: 22937
Joined: July 16th, 2004, 7:38 am

The joy of browsing J. London's "Modeling Derivatives in C++"

June 27th, 2006, 4:48 pm

QuoteOriginally posted by: lballabioQuoteOriginally posted by: CuchulainnEven better is Fortran: in this language you can wriite just "1."Same in C/C++. But I like 1.0 better. Just personal taste.Luigiwow!must try that to see how it works
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

The joy of browsing J. London's "Modeling Derivatives in C++"

June 30th, 2006, 4:29 pm

Mayl brings us to a valid point.Is there a whole page of code in that book which you'd not be embarassed to have written ?I can imagine adopting a style that makes it clear to the reader that you are using a floating point value, not an integer. I have been personally bitten by the fact that VB and C++ treat constant literal arithmetic expressions differently.But in straight C++ code it's not clear why he did this unless he somehow feels that the compiler needs the extra zeroes to make sure that it gets the message ?Which of the voices in his head do you think picked 5 zeroes. Why not 6 ? Also what I find a little bizarre is why he writes things like (0.00000 - ( 1.00000/3.00000)) in so many places ?Not wrong as such of course, but it feels like he translated it from some other language. But I don't know of any that makes you do this, pssibly a defective dialect of SQL ?Does his next book contain ideas on how to do Monte Carlo in SQL or REXX ?He initialises constant though as if he knew what he doing.double x=0;Also what do you think he believesdouble B[20][20] = {0.0}; does ?Note the different number of decimal places.Also browsing this "code", I find he gives the impression of not knowing about references, and thus uses pointers more than people have done since the mid 90s.Again this is not wrong, though would get embarassing at a code review. Sometimes it means that he uses the slightly lessreadable XX-> syntax which is a bad choice for a book which is explaining how to do code.But it also impacts performance.On page 531 and other places he passes an vector by value, not reference, though it does hold pointers to an underyling object.The implication is that the voice in his head that screams "efficiency" in a bad Austin Power imitation genuinely thinks that it's fast because he's passing pointers, not the actual objects.Look at the udm function on p 528, (but not if you've just eaten).How redundant is that code ?Yet again it's (probably) not wrong but this time volume of code makes the routing harder to read. A decent optimiser would reduce it by about 50%, but that doesn't help the student.Of course I could be wrong, and he simply doesn't care how fast the code goes, but forcing the pointless creation and destruction of many vectors is not the sort of thing that you want to encourage.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

The joy of browsing J. London's "Modeling Derivatives in C++"

June 30th, 2006, 9:05 pm

QuoteOriginally posted by: DCFCMayl brings us to a valid point.Is there a whole page of code in that book which you'd not be embarassed to have written ?Well, I probably wrote quite a few pages of the QuantLib code he included in the book Luigi
 
User avatar
glendale
Posts: 0
Joined: July 14th, 2002, 3:00 am

The joy of browsing J. London's "Modeling Derivatives in C++"

July 1st, 2006, 1:14 am

QuoteOriginally posted by: lballabioQuoteOriginally posted by: DCFCMayl brings us to a valid point.Is there a whole page of code in that book which you'd not be embarassed to have written ?Well, I probably wrote quite a few pages of the QuantLib code he included in the book LuigiCan someone please tell me which are the pages I can trust? I would like to learn... but only if the codes are correct and efficient.
 
User avatar
Cuchulainn
Posts: 22937
Joined: July 16th, 2004, 7:38 am

The joy of browsing J. London's "Modeling Derivatives in C++"

July 1st, 2006, 12:56 pm

QuoteAlso what do you thinkdouble B[20][20] = {0.0}; does ?Shudder. I have not progammed it but off the top of may head, any one of the following is possible:1. compiler error2. All 400 values are 03. B[0][0] is 0, the other values are undefined.4. Any other guess.BTW '20' is a magic number and should not be done in this way. Betterconst int Row = 20;const int Col = 20;double B[Row][Col];CS 101.
Last edited by Cuchulainn on June 30th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22937
Joined: July 16th, 2004, 7:38 am

The joy of browsing J. London's "Modeling Derivatives in C++"

July 1st, 2006, 12:59 pm

QuoteOn page 531 and other places he passes an vector by value, not reference, though it does hold pointers to an underyling object.Well, not wrong as such, just very slow. Rule is: always use const references for non-atomic types in parameter lists. Efficient and safe. Quotepassing pointers, not the actual objects.Pointer are very 80's (C). These days use (const) references.
Last edited by Cuchulainn on June 30th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

The joy of browsing J. London's "Modeling Derivatives in C++"

July 2nd, 2006, 2:43 pm

Cuch's right. A lot of Mr. London's code is useful to the newbie as exercise in spotting defects in code.This is good interview practice.There are quite literally several hundred things that you might expect to get in an interview where they say "discuss this code".As they say on Despair"It could be that the purpose of your life is only to serve as a warning to others."Const ref's ain't a new C++ idiom, and as for "magic numbers", I recall being told they're bad in the in mid 1970s. I am conflicted as a pimp when I meet a newbie who claims to have read and liked this book.
Last edited by DominicConnor on July 1st, 2006, 10:00 pm, edited 1 time in total.