When you return to your source code, you will see that some of the generated code has been changed.
// Function: HISTVOL // Purpose: Returns the historical volatility of a series of daily prices //{{XLP_SRC(HISTVOL) // NOTE - the FunctionWizard will add and remove mapping code here. // DO NOT EDIT what you see in these blocks of generated code! IMPLEMENT_XLLFN2(HISTVOL, "RPB", "HISTVOL", "Prices,DaysPerYear", "Statistical", "Returns the historical volatility of a" " series of daily prices", "Series of daily prices\0Number" " of samples per year", "B()Prices Series of daily" " prices\0\0", 1) extern "C" __declspec( dllexport ) LPXLOPER HISTVOL(const COper* Prices, double DaysPerYear) { CXlOper xloResult; BOOL bOk = TRUE; std::vector<double> vecPrices; bOk = bOk && Prices->ReadVector(vecPrices, "Prices", xloResult); if (!bOk) return xloResult.Ret(); //}}XLP_SRC double dHistVol; if (CalcHistVol(vecPrices.begin(), vecPrices.size(), 250.0, &dHistVol)) xloResult = dHistVol; else xloResult = xlerrNum; return xloResult.Ret(); }
Notice that your code outside the //{{XLP_SRC delimiters is unchanged; all the changes occur within the delimiters.
Make one more change to the function, to pass the new argument to our CalcHistVol(), as shown below:
extern "C" __declspec( dllexport )
LPXLOPER HISTVOL(const COper* Prices, double DaysPerYear)
{
...
double dHistVol;
if (CalcHistVol(vecPrices.begin(), vecPrices.size(), DaysPerYear, &dHistVol))
xloResult = dHistVol;
else
xloResult = xlerrNum;
return xloResult.Ret();
}
The new release of the function is now complete, and ready for building and testing.
Existing users of the function will be inconvenienced by this change, since they will now get a #NUM! error in all their existing spreadsheets.
Later, we will revisit this function, and replace DaysPerYear with an optional argument, which, if omitted, will be defaulted to 250. That way, the existing users are unaffected, and new users can choose to specify the days per year or to omit it, as they prefer.