Saturday, February 9, 2008

QuantLibXL - Discovering Enumerations

It took me a while to figure out how I could "guess" what inputs are expected from a certain function. For example when QuantLib expects and Option Type as an argument, I guessed that it could be "Call" or "Put".

Now, guessing is not what the authors intended their users to do. This is why they documented these "string constants" in the enumerations section. The "string constants" are not really text constants, instead QuantLib uses a "Registration Manager" to translate these string constants into QuantLib Objects.

In the exampe above, if we try to create an option object in Excel and we pass the string "Put" as an argument to the constructor of this object, a "put option"-object is created.

All of these enumerations are nicely documented on http://quantlib.org/quantlibxl/auto/enums.html#enum_type_16.

But they can also be queried at runtime, which I found to be very useful.

Here is how you do it:
# Select in a column about 30 rows
# Type "ohListEnumeratedTypes ()"
# Press CTRL + Shift + Enter (to enter an array function)

QuantLib responds by filling your array with 27 enumerated types:


class QuantLib::Calendar
class QuantLib::Currency
class QuantLib::DayCounter
enum QuantLib::Average::Type
enumQuantLib::Barrier::Type
enum QuantLib::BusinessDayConvention
enum QuantLib::CapFloor::Type
enum QuantLib::CmsMarketCalibration::CalibrationType
enum QuantLib::Compounding
enum QuantLib::CubicSplineInterpolation::BoundaryCondition
enum QuantLib::DateGeneration::Rule
enum QuantLib::Duration::Type
enum QuantLib::EndCriteria::Type
enum QuantLib::Frequency
enum QuantLib::GFunctionFactory::ModelOfYieldCurve
enum QuantLib::Month
enum QuantLib::Option::Type
enum QuantLib::Position::Type
enum QuantLib::PriceType
enum QuantLib::Replication::Type
enum QuantLib::SalvagingAlgorithm::Type
enum QuantLib::Settlement::Type
enum QuantLib::TimeUnit
enum QuantLib::VanillaSwap::Type
enum QuantLib::Weekday
enum QuantLibAddin::RateHelper::DepoInclusionCriteria
enum QuantLibAddin::Token::Interpolator
enum QuantLibAddin::Token::Traits
Each one of those enumeration types can now be queried.

# Select two rows in your worksheet
# Type in "ohEnumeratedType (enum QuantLib::Option::Type)"
# Press CTRL + Shift + Enter

QuantLib responds by filling your array with the valid strings for "Option Type" that you can use as parameters when creating an object that requires an "Option Type" argument:

Call
Put

With other enumerations it works in the same way. In order to get all valid Calendars:

# Select 51 rows in your worksheet
# Type in "ohEnumeratedType (class QuantLib::Calendar)"
# Press CTRL + Shift + Enter

QuantLib responds with:

Argentina::Merval
Australia
Brazil::Exchange
Brazil::Settlement
Canada::Settlement
Canada::TSX
China
CzechRepublic::PSE
Denmark
EUR
Finland
GBP
Germany::Eurex
Germany::FrankfurtStockExchange
Germany::Settlement
Germany::Xetra
HongKong::HKEx
Hungary
Iceland::ICEX
India::NSE
Indonesia::BEJ
Indonesia::JSX
Italy::Exchange
Italy::Settlement
JOINHOLIDAYS(ITALY::EXCHANGE,TARGET,UNITEDKINGDOM::EXCHANGE,UNITEDSTATES::NYSE)
Japan
LONDON
Mexico::BMV
NewZealand
Norway
Null
NullCalendar
Poland
SaudiArabia::Tadawul
Singapore::SGX
Slovakia::BSSE
SouthAfrica
SouthKorea::KRX
Sweden
Switzerland
TARGET
Taiwan::TSEC
Turkey
Ukraine::USE
UnitedKingdom::Exchange
UnitedKingdom::Metals
UnitedKingdom::Settlement
UnitedStates::GovernmentBond
UnitedStates::NERC
UnitedStates::NYSE
UnitedStates::Settlement

These are all the valid calendars that can be passed as parameters whenever an object requires a calendar.

Besides enumerated types there are also enumerated classes. The difference between them is that enumerated types are stateless while enumerated classes are stateful.

The enumerated classes are returned by =ohListEnumeratedClasses() are:

class QuantLib::IborCouponPricer
class QuantLib::Interpolation
class
QuantLib::Interpolation2D
class QuantLib::Payoff
class
boost::shared_ptr (__cdecl*)(class
boost::shared_ptr const
&)
class boost::shared_ptr
(__cdecl*)(class boost::shared_ptrQuantLib::GeneralizedBlackScholesProcess> const &,long const &)

The most important enumerated class is the PayOff class.

When we select several rows in a worksheet an type =ohEnumeratedClass(class QuantLib::PayOff) and press CTRL + Shift + Enter we get:

AssetOrNothing
CashOrNothing
Gap
PercentageStrike
PlainVanilla
SuperFund
SuperShare
Vanilla

These are mandatory arguments when creating PayOff object in QuantLib and QuantLibXL.

2 comments:

Nelnik said...

The information above is very helpful. Thanks

Amar said...
This comment has been removed by a blog administrator.