Egor Kraev's Homepage
  Code Issues and Downloads
Book Home
Code
VC++ 2003
Typos
FAQ
 
 

This page contains discussion of known code issues throughout the book, bugs as well as some additions, organized by chapter.

Talking about code, what version control approach do you use? If the answer is none, or Visual Source Safe (which is pretty much the same thing), I (EK )recommend you take a look at Subversion, a free solution that does atomic commits/rollbacks, directory-level snapshots (so you never have to worry about file dependencies when reverting to older versions), and lots more. Through TortoiseSVN it integrates nicely with Windows Explorer, and through AnkhSVN with VS.NET. EK tried it half a year ago and never looked back...

Chapter 5: The Property Pattern In Financial Engineering
Chapter 13: Two-point Boundary Value Problems
Chapter 19: My First Finite Difference Solver
Chapter 22: A C++ Application for Displaying Numeric Data
Chapter 29: Advanced Excel Interfacing

Chapter 5: The Property Pattern In Financial Engineering

Entity.hpp on the CD is missing some #include statements and has two typos as well. Here is the corrected version.

SimplePropertySet.cpp needs to be updated to work with compilers other than VS 6.0. The modified version is here.

To make life a little easier for those trying to put it together, here is the complete contents of PropertyPattern directory wrapped up as a VS.NET 2003 project, that had compiled successfully for EK.

back to top

Chapter 13: Two-point Boundary Value Problems

Source code of Figure 13.1 in Section 13.7. It implements a design pattern in C++ for a 'microcosm' for BS. The basic structure should be OK but you might have to do a bit of tweaking. Chapter 19 does this stuff for parabolic structure but figure 13.1 is a clean OO and patterns way to set up your C++ code. It is the essence of what I (DD) am doing in other problems, i.e. separation of concerns.

back to top

Chapter 19: My First Finite Difference Solver

To use the code in the PDEFDM directory, you will need the FunctionSet.*pp files, and these are affected by the different treatment of typename by VS 6.0 as opposed to the C++ standard, discussed here. A version of these files for compilers other than VC++ 6.0 is here.

ParabolicFDM

Below is a discussion from the forum; EK will try to compile the modified version and will post the modified ParabolicFDM here if successful.

From a reader ...

Many thanks for your quick response and the code you sent to me. Please I will have one more question about ParabolicFDM. It seems to me that when you benchmark the price against the true B&S solution, only he Theta scheme with Theta=0 works. I wander if there is a problem with Crank Nicholson and full Implicit Scheme within the code. In the Example on page 223 I changed the Maturity to One Year.

Theta =0; S=11; C=3.233165
Theta =0; S=10; C=2.402779
Theta =0; S=9; C=1.661030
Theta =0.5; S=10; C=0.003567
Theta =1; S=10; C=0.000029
True B&S price S=10; C=1.661030

By the way, It appear that there is probably a shift between S value and the Call Value it the file output.dat. Any help would be great.

Jan 1, 2005 7:01:50 PM Answer from cuchulainn: Possible short-term solution

Thanks for the reply. It is a bug. I will need to look into it. The code was written before some changes were made to Vector class and the Double Sweep method; I suspect that an index got shifted from 0 to 1 and that's probably a NASTY bug.

I am working on a more clean, design pattern approach (not dissimilar to the design in section 13.7) of my book. This will in my new FDM book out in June 2005.

Anyway, please make sure that you use the Double Sweep from the PDEFDM directory and not from somewhere else. Actually, I tested the the Double Sweep but NOT on this ParabolicFDM, yet.

Jan 8, 2005 6:49:49 PM Answer from a reader

Hi Daniel,

I changed this inside the file ParabolicFDM in order to price American Option:

//========********** AMERICAN OPTION *************
/*
Vector<V,long> mytmp;
mytmp = Vector<V,long> (J-1, 1);
mytmp = ss.result();
for (long mj = mytmp.MinIndex() + 1; mj <= mytmp.MaxIndex(); mj++)
{
tmp[mj] =(mytmp[mj]>K-XARR[mj]) ? mytmp[mj] : K-XARR[mj];
}
*/

You should take care about the bound of integration only...

back to top

Chapter 22: A C++ Application for Displaying Numeric Data

Getting the Excel Driver to work is not quite trivial, and is covered on its own page. If you compile it successfully under Office XP or Office 2003, but get a "type mismatch" runtime error instead of results when trying to run it, you need to use this version instead. As Martin Nisbit (who provided that version) discovered, one has to replace all occurrences of "something.Value" by "Something.Value2" for the driver to work under these versions of Office, so for example instead of

item->Value = label.c_str();

you have to use

item->Value2 = label.c_str();

Also, the Excel Driver, even when it runs successfully, tends to crash upon exit - happened to me both when using Office 2000 and Office 2003, and Martin reports the same behavior under Office XP. When I will figure out what causes it, I'll write it here - or if you know, please write me!

back to top

Chapter 29: Advanced Excel Interfacing

I want my function to be recalculated every time the user presses Shift-F9 in Excel - what do I do?

Answer by robert2098 on wilmott.com:.
Just call Application.Volatile from your worksheet function.
In the Automation .dll from the book I've added the following random fuction:

STDMETHODIMP CMyExcelFunctions::MyRnd(DOUBLE* result)
{
// It is a volatile function
m_xl->Volatile(true);

// Return a random value
*result=rand();

// No errors
return S_OK;
}

Here the member variable "m_xl" is the Excel application object that was set in the OnConnection() method when the Automation add-in is loaded.
Now whenever you change something in the sheet or when you press F9 or <shift>+F9 the cell with the MyRnd() function gets a new random value.

Robert

back to top