Overview
This simple add-in contains a calculator for calculating the
value and derivatives of a vanilla option.
It is typical of financial calculator add-ins, and offers a useful
model for an XLL+ add-in which makes use of existing pure C libraries.
Features
The sample displays the following features:
- The CfRevalCashflows add-in function accepts two vector arguments,
of dates and cashflows.
The Function Wizard generated all the code that deals with
extracting and validating the vectors' values from the cell arrays
passed by Excel.
- The library includes a function which returns a range of values
(BsCalc) and a set of functions (BsValue, BsDelta etc)
which return only one value, extracted from the range returned by BsCalc.
- The Div argument to the Black-Scholes functions is flexible.
It can contain either a single number (representing
dividend yield) or two columns containing the dates and values
of predicted dividends.
Implementation
The following steps were significant in creating and completing the
SimpOpt application.
- Pre-cooked header and source files were added to the project,
containing code for the business functions.
- The Calendar functions (CalDiffYears, CalDiffDays,
CalDaysInYear and CalDayCountText)
were each implemented as a thin shell around existing business functions,
with the majority of the code being generated by the XLL+ Function Wizard.
This is typical of most real-world add-in functions.
- Each of Black-Scholes functions has the same arguments.
Therefore only one was entered into the XLL+ Function Wizard.
All the rest were created as clones of the first function, using the
Copy signature from... field of the
New Function dialog.
- Each of the single value Black-Scholes functions (BsValue,
BsDelta etc) calls the array function (BsCalc), via
CXlOper::CallAddin.
The value of interest is then extracted from the array
and returned to Excel.
- The BsCalc function, which returns an array, allocates
the array with CXlOper::AllocArray
and populates it using CXlOper::Cell.
- The Div argument to the Black-Scholes functions is specified
as a COper type, meaning that it can contain any or no data.
Code was written (in BsCalc) to examine the contents of the Div argument,
and handle it differently depending on its shape.
- The Excel date functions
(XlLSerialToDate and
XlDateToLSerial)
were used for all date conversions.
This makes the code immune to problem of the user setting an unusual
zero date in Excel's options.
Functions used
Project files
If you are using MS Developer Studio 6, then you should open the project file
SimpOpt.dsp.
If you are using MS Visual Studio .NET 2002, then you should open the solution file
SimpOpt.sln
or the project file SimpOpt.vcproj.
If you are using MS Visual Studio .NET 2003, then you should open the solution file
SimpOpt71.sln
or the project file SimpOpt71.vcproj.
If you are using MS Visual Studio 2005, then you should open the solution file
SimpOpt8.sln
or the project file SimpOpt8.vcproj.
See Also
List of Sample Projects
| Samples and Walkthroughs