Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

Loop parameters

Loop parameters are a mechanism in the QuantLib addin to call a function multiple times while keeping all but one of its parameters constant and iterating the remaining parameter (loop parameter) over an array of input values. The array of input values is supplied to QuantLib by passing a range of cells to the loop parameter of the functions.

The primary reason for using loop parameters is efficiency: some of the parameters to a function can be time-consuming to construct and therefore re-using these while changing the remaining parameter can provide a significant efficiency in improvement.

Example

Below is a simple example which makes use of the loop parameter for qlCalendarAdvance to compute three dates in one call to this function. Note the use of array formula to output the results of qlCalendarAdvance to multiple cells – this is essential in order for the loop parameters to be useful.

Date

Advanced date

->

Date

Advanced date

2011-12-01

Note the use of loop paramer

->

2011-12-01

Note the use of loop paramer

1D

{=qlCalendarAdvance(“TARGET”,R[-1]C[-1], RC[-1]:R[2]C[-1])}

->

1D

2011-12-02

1W

{=qlCalendarAdvance(“TARGET”,R[-1]C[-1], RC[-1]:R[2]C[-1])}

->

1W

2011-12-08

1M

{=qlCalendarAdvance(“TARGET”,R[-1]C[-1], RC[-1]:R[2]C[-1])}

->

1M

2012-01-02

The array formula is shown in each of the cells of the array but the relative offsets are measured only from the first, i.e., top most, cell