Excel Guide#
Key Functions#
The main objective of rateslib-excel is to fully replicate the Python API methods of rateslib, callable from Excel, with successful integration into the Excel calculation dependency tree.
There are 4 key cell functions to replicate the different types of Python’s general API:
Class instance creation.
Class method calls.
Class attribute value fetching.
Isolated Function calls.
|
Initialise any rateslib Class provided with a dict of keyword args. |
|
Perform any rateslib Class method provided with a dict of keyword args, |
|
Get an attribute value of a Class instance. |
|
Perform any rateslib function provided with a dict of keyword args. |
Three of these also have extentions to force the returned value to be a Python object, instead of allowing Pyxll to type convert it automatically. This is often useful for chaining and/or for visualisation when structuring a spreadsheet.
Note
General guidance is to try the above methods first. If the result is not suitable
and a general representation would be better wrapped into a single cell, then use the
object
return variant below.
|
Perform any rateslib Class method provided with a dict of keyword args, returned as a cached Python object. |
|
Get an attribute value of a Class instance, returned as a cached Python object. |
|
Perform any rateslib function provided with a dict of keyword args, returned as a cached Python object. |
Type Wrapping#
Because rateslib is a Python library it relies on Python types. Excel cannot natively pass Python objects, from cells, to Excel functions. The way to solve this is to create object wrappers. This means a wrapper, once created, can then be passed to an Excel function and treated as a Python object.
Rateslib-excel makes use of the following wrappers to cache Python objects to worksheet cells:
Wrapper type |
Contained Python type |
Wrapping function |
---|---|---|
datetime.datetime |
||
integer |
||
rateslib.NoInput |
||
dict |
||
tuple |
||
list |
||
list (as Excel array) |
||
pandas.Series |
||
pandas.DataFrame |
None |
Notice that a Python list
is included in this table twice. The difference is how these
objects will be interpreted in function calls, and specifically, how they are unwrapped.
A
PyList
is a genuine Python list of values. Suppose the keyword of the function wasinstrument_labels
and the desired input is a list of strings, e.g. [“1M”, “2M”, “3M”]. This input would require aPyList
object.A
PyInputs
is a list of values associated to each keyword of the function. Suppose the keywords weresettlement
,ytm
andmetric
, then, since these are distinct keywords, an array of cells would be permissible, e.g. (A1:A3 or A1:C1). However, if the array is not contiguous, then aPyInputs
wrapper can be used to collect these values from across a worksheet, inside a list which acts as an Excel array, and passed to a function call.
Displaying Objects#
Some sorts of values returned by rateslib functions contain DataFrames, or chart figures.
To visualise these correctly in an Excel worksheet requires the conversion method, such as
rl_to_arr()
or rl_to_plot()
.
|
Display an object, such as |
Display an object, such as |
|
|
Display the float() value of a Python object in a cell. |
|
Display a matplotlib.figure as a visible embedded image in Excel. |
|
Perform the unwrap() method on any |
Compositing#
Some objects, e.g. Curves, have more complex inputs, especially nodes
. These need to be
created, or composited, in the sheet and then passed to a Curve type constructor.
These Curves can be plotted replicating the usual method from Python.
Special Functions#
Some functions are so common that it is much more user friendly to provide specific
functionality. For example, with rl_dt()
, it is far more convenient to
use rl_dt(2022, 12, 16)
than using the function replicator
rl_fn_obj()
method (which will still work) via
rl_fn_obj("dt", {"year", "month", "day"}, rl_seq_input("vals", rl_int(2022), rl_int(12), rl_int(16)))
.
Note the integer inputs also need to be wrapped.
Calendar Functions#
|
Create a wrapped Python datetime object. |
|
Implement the rateslib |
|
Implement the rateslib |
The Solver#
The rateslib Solver is a key element that calibrates Curves and Surfaces and is integral to all risk sensitivity calculations. In Python it dynamically mutates certain objects (Curves, Surfaces and FXForwards) which are all stored in the local namespace memory. To avoid breaking the Excel dependency tree calculation, which is very important for spreadsheet structuring, this special function will package the mutated objects and return them to excel so that dependent calculations can rely on these objects. It will also package some of the Solver result parameters including if it was a success or failure.
|
Initialise the rateslib |