Calling FIA from Python

From Flametree Technologies
Jump to navigation Jump to search

Assigning configuration settings in Python

Configuration settings are assigned using functions.

For instance, suppose we need to instruct FIA to use STB for sovereign curve decomposition. To do this we assign the string value 'STB' to the variable SovereignCurveDecomposition.

In a configuration file, we would include the line

SovereignCurveDecomposition= STB

From Python, we use the following statement:


Let's describe what is going on here in detail.

Firstly, SovereignCurveDecomposition takes a string value, so we use the FIA_set_string function to set its value. This function call is prefixed with 'FIA_python36' because this is the name of the module in which the function is defined. (This also requires that we have an import FIA_python36 at the start of the Python program).

The function takes two arguments: an integer that corresponds to the SOVEREIGN_CURVE_DECOMPOSITION setting, and the value "STB". However, integers are not very readable, so instead we use a symbolic constant called FT_STRING_SOVEREIGN_CURVE_DECOMPOSITION, where

  • FT shows that this is a Flametree-defined constant
  • STRING shows that this constant corresponds to a string value
  • SOVEREIGN_CURVE_DECOMPOSITION is the variable we are assigning.

The symbolic constant is prefixed by FIA_API_constants as this is the module in which the value is defined. As above, this also requires an 'import FIA_API_constants' statement at the start of the Python program.

Assigning data arrays in Python

The starting point for a data array in Python is a Flametree-defined data structure called a stringmatrix. This structure is defined in module FIA_python36 and allows the user to initialise it in terms of lists of lists.

For instance, to set up yield curve data using static declarations, we could write

y = FIA_python36.stringmatrix() y = [

       ["BASE_CURVE", "2010-Jan-01", "0.0",   "0.050"],
       ["BASE_CURVE", "2010-Jan-01", "4.0",   "0.050"],
       ["BASE_CURVE", "2010-Jan-01", "8.0",   "0.050"],
       ["BASE_CURVE", "2011-Jan-01", "0.0",   "0.045"],
       ["BASE_CURVE", "2011-Jan-01", "4.0",   "0.045"],
       ["BASE_CURVE", "2011-Jan-01", "8.0",   "0.045"],
       ["SECTOR_CURVE", "2010-Jan-01", "0.0",  "0.055"]


This data can now be assigned as described in the following section. To assign data rather than indiviudal settings, we use a different function called FIA_set_matrix.

The following function does the same as setting


in a configuration file. Instead, we write

FIA_python36.FIA_set_matrix( FIA_API_constants.FT_MATRIX_YIELDCURVE, y );

Despite the additional apparent complexity of calling FIA in this way, it carries many advantages - speed, robustness, and ease of deployment. In particular, the ability to pass large quantities of data in memory rather than via disk files means you can process your portfolio much more quickly.