Login  Register

Re: Re: Customizing QLAddin: mini how-to + question

Posted by eric ehlers on Feb 09, 2006; 4:08am
URL: http://quantlib.414.s1.nabble.com/Customizing-QLAddin-mini-how-to-question-tp4453p4458.html

> 1) I am not sure if it is possible, but it wold be nice to have a generic
> function in excel like "ohMethodValue(handle, methodName as string,
> parameterArray) as variant". The difference from "ohFieldValue" in this case is
> that "methodName" is a method of getObject, so that if methodName = "XYZ", it
> will call : returnValue = objectPointer->getObject().XYZ(parameterArray). If
> returnValue is an object the handle is returned.

It's a neat idea and yes it's possible.  There would have to be some
kind of message map which would associate strings with member
functions (not a straightforward task).  The code to initialize this
container might be generated by srcgen based on metadata.

This would greatly increase the complexity of the design and my first
reaction is that the cost exceeds the benefit but I'm open to
discussion.

> 2) Is it possible to access the addin functionality from VB? If so, how?

Here's an example VBA function to price an option.  This runs against
the latest CVS snapshot of QuantLibAddin - I'm pretty sure the same
approach works against the current production release 0.3.11.

Sub priceEuropeanOption()

Dim blackVolHandle As String

Dim blackScholesHandle As String

Dim optionHandle As String

Dim npv As Double

blackVolHandle = Application.Run("qlBlackConstantVol",
"blackconstantvol", 40250, 0.2, "Actual360")

blackScholesHandle = Application.Run("qlBlackScholesProcess",
"stoch1", blackVolHandle, 36, "Actual360", 40250, 0.06, 0)

optionHandle = Application.Run("qlVanillaOption", "eur1",
blackScholesHandle, "Put", "Vanilla", 35, "European", 43903, 0, "JR",
801)

npv = Application.Run("qlNPV", optionHandle)

Debug.Print npv

End Sub



> I missed the docs, that would have saved me some time.

That's my fault for not pointing the QuEP at the website, this is now
rectified.  Apologies for the confusion.

> If it is not too much
> trouble I think that it would be nice to add a few conversions for Date->long,
> InterestRate->double...

Ok I'll have a look at this when I get the time.

Regards,
Eric