Serving the Quantitative Finance Community

 
User avatar
Lapsilago
Topic Author
Posts: 5
Joined: October 15th, 2004, 7:36 am
Location: Germany

C++ complex< > in xll or dll

September 5th, 2006, 7:02 am

Hi all,I have the following problem using complex numbers within a c++ framework. I have createdan xll to use with Excel. Now, I want to implement some routines involving complex numbers.Simply including complex and declaring numbers complex<double> n gives not the desired resultsince I get warnings and errors when calling standard functions like conj, exp, etc...Are there any known problems using complex under certain circumstances?Thanks for your comments
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ complex< > in xll or dll

September 5th, 2006, 4:00 pm

QuoteOriginally posted by: LapsilagoHi all,I have the following problem using complex numbers within a c++ framework. I have createdan xll to use with Excel. Now, I want to implement some routines involving complex numbers.Simply including complex and declaring numbers complex<double> n gives not the desired resultsince I get warnings and errors when calling standard functions like conj, exp, etc...Are there any known problems using complex under certain circumstances?Thanks for your commentsWhat kinds of warnings/errors?
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ complex< > in xll or dll

September 5th, 2006, 4:00 pm

QuoteOriginally posted by: LapsilagoHi all,I have the following problem using complex numbers within a c++ framework. I have createdan xll to use with Excel. Now, I want to implement some routines involving complex numbers.Simply including complex and declaring numbers complex<double> n gives not the desired resultsince I get warnings and errors when calling standard functions like conj, exp, etc...Are there any known problems using complex under certain circumstances?Thanks for your commentsWhat kinds of warnings/errors?Is the Complex class your own or some kind of external library?
 
User avatar
quantie
Posts: 20
Joined: October 18th, 2001, 8:47 am

C++ complex< > in xll or dll

September 6th, 2006, 9:43 pm

QuoteOriginally posted by: LapsilagoHi all,I have the following problem using complex numbers within a c++ framework. I have createdan xll to use with Excel. Now, I want to implement some routines involving complex numbers.Simply including complex and declaring numbers complex<double> n gives not the desired resultsince I get warnings and errors when calling standard functions like conj, exp, etc...Are there any known problems using complex under certain circumstances?Thanks for your commentsYes you'd have to deal with picking the right branch cut of functions like Log.I don't know if the c++ standard deals with this. Cuch.. had a nice complex class it might be coming in his upcoming book.
 
User avatar
mj
Posts: 12
Joined: December 20th, 2001, 12:32 pm

C++ complex< > in xll or dll

September 7th, 2006, 3:55 am

if you look at 26.2.8 in the standard, it seems that you should be OK.My best guess is that the compiler is getting confused as to what version of the exp function you want to call. Try it when including the header file <complex> and no other header files.
Last edited by mj on September 6th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
mj
Posts: 12
Joined: December 20th, 2001, 12:32 pm

C++ complex< > in xll or dll

September 7th, 2006, 3:55 am

re quanties comments, the standard does specify the branch cut
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ complex< > in xll or dll

September 7th, 2006, 4:06 pm

QuoteOriginally posted by: quantieQuoteOriginally posted by: LapsilagoThanks for your commentsYes you'd have to deal with picking the right branch cut of functions like Log.I don't know if the c++ standard deals with this. Cuch.. had a nice complex class it might be coming in his upcoming book.Quantie,The Complex class is in there indeed with these kinds of functions, as well as some related classes for Jordan curves and integration. Even if Log(z) is not in a class you can make a C function to do the jobComplex log(Complex z){ // find the polars for z: r and thetareturn Complex(log(r), theta); // principal value}In fact I prefer friend functions for trig and hyperbolic instead of the more cumbersome (in this case) object 'dot' notation ) (or static member functions).
Last edited by Cuchulainn on September 6th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
quantie
Posts: 20
Joined: October 18th, 2001, 8:47 am

C++ complex< > in xll or dll

September 7th, 2006, 4:23 pm

Thanks MJ and Cuch it appears that this is addressed in the standard. I will try some test examples at home.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ complex< > in xll or dll

September 7th, 2006, 5:31 pm

QuoteOriginally posted by: quantieThanks MJ and Cuch it appears that this is addressed in the standard. I will try some test examples at home.You're welcome
 
User avatar
Lapsilago
Topic Author
Posts: 5
Joined: October 15th, 2004, 7:36 am
Location: Germany

C++ complex< > in xll or dll

September 8th, 2006, 7:59 am

Thanks everybode,seems that the compiler got confused. Firstly thought there are some problems with some other included files but at the end of the dayI decided to reboot the system... After that it worked!Use this stuff for implementation of BS like formula for sv and svj models.For calibration of these models many people recommend the excel solver. But I observed some instability especially when the number of option quotes is very high.Does anyone has a suggestion for stable, robust calibration algo where one can specify lower and upper bounds for the params.I thought about simulated annealing. Any experience?Best Lapsi
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ complex< > in xll or dll

September 8th, 2006, 8:16 am

QuoteI decided to reboot the system... After that it worked!Hi Lapsi,This reminds me of an anecdote. Years ago I had to go to Germany to fix a s/w problem for a graphics workstation. We all thought that the new version of the s/w was the cause, so I brought my 1600 bpi tapes (inclduing source code, libraries and compiler). It was Friday and I had to travel to the south of Germany the same day. Was expecting a marathon session.But before I started I rang head office just to check (just to be sure) that the cables were OK. Problem: green cable in red port and vice versa. Solution: swich cables and reboot. Solved, felt like the A team.That was my 10-minute stay in Hannover. Saved myself a lot of work. Just imagine spending the whole day reinstalling the s/w with crossed cables! That weekend could have turned out much differently.Have a nice weekend.
Last edited by Cuchulainn on September 7th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
quantie
Posts: 20
Joined: October 18th, 2001, 8:47 am

C++ complex< > in xll or dll

September 8th, 2006, 9:55 pm

I would also give Differential evolution a shot.