Appendices

Appendix A: Quantlab Types and C++

Primitive Types

Type

Identifier for arg_spec

Representation

Test

number

"number"

double

valid

date

"date"

double

valid_date

logical

"logical"

double

valid

Object Types

Type

Identifier

Representation

Test

algorithm

"algorithm"

handle

if

calendar

"calendar"

handle

if

curve

"curve"

handle

if

fit_result

"fit_result"

handle

if

instrument

"instrument"

handle

if

model

"model"

handle

if

point_date

"point_date"

handle

if

point_number

"point_number"

handle

if

weight_scheme

"weight_scheme"

handle

if

String-Based Types

Type

Identifier

Representation

Test

curve_name

"curve_name"

string

if

instrument_name

"instrument_name"

string

if

day_count_method

"day_count_method"

string

if

quote_side

"quote_side"

string

if

rate_type

"rate_type"

string

if

string

"string"

string

if

Compound Types

Type

Identifier

Representation

Test

vector of <type>

"vector(<type>)"

handle

if

matrix of <type>

"matrix(<type>)"

handle

if

series of <type>

"series(<type>)"

handle

if

Appendix B: API Functions in ql_base.h

Vector Functions

Function

Description

get_v_size(obj)

Returns the size of a vector

get_v_n(vec, i)

Returns a number element

get_v_i(vec, i)

Returns an integer element

get_v_l(vec, i)

Returns a logical element

get_v_d(vec, i)

Returns a date element

get_v_s(vec, i)

Returns a string element (handle)

get_v_o(vec, i)

Returns an object element (handle)

create_v_n(size)

Creates a vector of numbers

create_v_i(size)

Creates a vector of integers

create_v_s(size)

Creates a vector of strings

create_v_d(size)

Creates a vector of dates

create_v_o(size)

Creates a vector of objects

set_v_n(vec, i, val)

Sets a number element

set_v_i(vec, i, val)

Sets an integer element

set_v_s(vec, i, obj*)

Sets a string element

set_v_o(vec, i, obj*)

Sets an object element

Matrix Functions

Function

Description

get_m_size(mat, &rows, &cols)

Returns rows and columns

get_m_n(mat, row, col)

Returns a number element

create_m_n(rows, cols)

Creates a matrix of numbers

create_m_s(rows, cols)

Creates a matrix of strings

set_m_n(mat, row, col, val)

Sets a number element

set_m_s(mat, row, col, obj*)

Sets a string element

Validation & Null Sentinel Functions

Function

Description

valid_number(number_t)

Tests if a number is valid (not NaN)

valid_logical(logical_t)

Tests if a logical is valid

valid_date(date_t)

Tests if a date is valid

valid_month(month_t)

Tests if a month is valid

valid_timestamp(timestamp_t)

Tests if a timestamp is valid

valid_enum(enum_t)

Tests if an enum value is valid

null_number()

Returns null/invalid number (NaN)

null_logical()

Returns null logical

null_date()

Returns null date

null_month()

Returns null month

null_timestamp()

Returns null timestamp

null_enum()

Returns null enum

String Functions

Function

Description

create_string(const char *)

Creates a QL string handle

create_string(const char *, int_t len)

Creates string with explicit length

create_string(const wchar_t *)

Creates string from wide-char

get_string(const object &)

Extract C string (checked, throws)

get_string_0(const object *)

Extract C string, null-safe (returns nullptr)

get_strlen(const object &)

Returns string length

Date / Month / Timestamp Functions

Function

Description

date(y, m, d)

Creates a date value

date_today()

Returns today’s date

split_date(date, &y, &m, &d)

Decomposes date into components

add_years(date, n)

Add n years to date

add_months(date, n)

Add n months to date

month(y, m)

Creates a month value

split_month(month, &y, &m)

Decomposes month

timestamp(y, mon, d, h, min, s, ms)

Creates a timestamp

timestamp(date, h, min, s, ms)

Creates timestamp from date + time

timestamp_now()

Current local timestamp

timestamp_now_ut()

Current UTC timestamp

split_timestamp(ts, &y, &m, &d, &h, &min, &s, &ms)

Decomposes timestamp

Calendar Functions

Function

Description

create_calendar(holidays, non_holidays, weekend_mask)

Creates a calendar object

empty_calendar()

Creates an empty calendar

merge_calendars(c1, c2)

Merges two calendars

is_holiday(calendar, date)

Tests if date is a holiday

move_bus_days(calendar, date, n)

Move n business days

Blob Functions

Function

Description

create_blob(size, data)

Creates a binary blob

blob_size(obj)

Returns blob size in bytes

blob_data(obj)

Returns pointer to blob data

Error Functions

Function

Description

error(error_t, const char *)

Creates and throws a QL error (returns handle)

error(error_t, object &msg)

Creates error with QL string message

error_type_to_str(error_t)

Converts error code to string

get_error_type(const object &)

Extracts error type from error handle

get_error_msg(const object &)

Extracts error message from error handle

Raw Data Access

Function

Description

get_raw_data(object &)

Returns ref_t union with typed pointers (.n for double*, .i for int_t*, etc.)

Use for high-performance access to vector/matrix internals without per-element function calls.

Appendix C: Blending Functions

Four C++ blending functions for combining deposit, FRA, and swap curves. Also available in QLang:

curve blend_curves_depo_swap(curve depo_c, curve swap_c)
    option(category: 'Curve blending')
{
    if (swap_c.empty())
        return depo_c;
    else {
        depo_c = depo_c.chop_long(v_min(swap_c.instruments.maturity) - 1);
        return merge(depo_c, swap_c);
    }
}

Appendix D: User-Defined Yield Curve Models

Using QL::model_create_custom() you can define your own yield curve model. Inherit from QL::custom_model and implement four virtual functions: n_params(), default_param_guess(), default_param_min(), default_param_max(), and disc_fact().