Allowing functionA in an XLL to call functionB in the same XLL

Feb 21, 2014 at 2:49 PM
I created an XLL that has an option pricing function that actually returns a double but is declared to return an LPOPERX type. Now I need an function in the same XLL to call the option pricing function multiple times to converge to a certain value using a bisection method.

I had tired to call it and assign it to a "double" type variable, but of course it complained and said that a type LPOPERX couldn't be converted to double.

How do I define and call one function from another function in the same XLL?
Coordinator
Feb 21, 2014 at 3:45 PM
Edited Feb 21, 2014 at 3:49 PM
In general you want to write platform independent code. Use the xll library as a thin wrapper that gets the arguments from Excel, calls your platform independent function, and returns the result to Excel.

See https://fmsgjr.codeplex.com/SourceControl/latest#black.h for a robust Black-Scholes implied volatility routine and https://xllgjr.codeplex.com/SourceControl/latest#xllblackiv.cpp for the Excel implementation. Note the https://fmsXXX for platform independent code and https://xllXXX for the Excel implementation.

Also note that returning a double that is a NaN results in #NUM! in Excel.
Feb 21, 2014 at 4:13 PM
I'm using a trinomial for american options.

So the short answer is, can't be done?

To calculate an implied volatility, I have to call the option pricing formula while varying the volatility until the calculated price matches the market price.

I guess I'll just write a VBA Macro to call Solver for the implied vols, using the pricing formula in the XLL.

Thanks anyway.

Steve

On 2/21/2014 10:46 AM, keithalewis wrote:

From: keithalewis

In general you want to write platform independent code. Use the xll library as a thin wrapper that gets the arguments from Excel, calls your platform independent function, and returns the results to Excel.

See https://fmsgjr.codeplex.com/SourceControl/latest#black.h for a robust Black-Scholes implied volatility routine and https://xllgjr.codeplex.com/SourceControl/latest#xllblackiv.cpp for the Excel implementation. Not the https://fmsXXX for platform independent code and https://xllXXX for the Excel implementation.

Note that returning a double that is a NaN results in #NUM! in Excel.

Coordinator
Feb 21, 2014 at 4:34 PM
You do realize that you can get the double value from an XLOPER x by x.val.num. Right?
Feb 21, 2014 at 4:49 PM
No. I'm a NOOB. Ancient Unix, C programmer.
I'll research it.
Is there a definitive book on this stuff?

On 2/21/2014 11:34 AM, keithalewis wrote:

From: keithalewis

You do realize that you can get the double value from an XLOPER x by x.val.num. Right?

Coordinator
Feb 21, 2014 at 6:20 PM
M3 t00, but I've had to learn Windows because most of my clients use that. It is not as bad as it used to be.
http://www.pearsonhighered.com/educator/product/Tour-of-C-A/9780321958310.page is the best way to get up to speed with modern C++.
For the Excel SDK Steve Dalton's book is your best bet.
You can also spelunk the source code in the Related Projects on the home page. Even better, find a project you like and start adding to it. A lot of those are just breadcrumbs showing the way, e.g., https://xllgsl.codeplex.com.
Feb 21, 2014 at 10:23 PM
Thanks Keith.

On Feb 21, 2014, at 1:20 PM, keithalewis wrote:

From: keithalewis

M3 t00, but I've had to learn Windows because most of my clients use that. It is not as bad as it used to be.
http://www.pearsonhighered.com/educator/product/Tour-of-C-A/9780321958310.page is the best way to get up to speed with modern C++.
For the Excel SDK Steve Dalton's book is your best bet.
You can also spelunk the source code in the Related Projects on the home page. Even better, find a project you like and start adding to it. A lot of those are just breadcrumbs showing the way, e.g., https://xllgsl.codeplex.com.