Function Router

All the C# code examples presented on this page can be found in the related demo function of MS Visual Studio project FinaquantProtosStarter which can be downloaded at the product page of the free .NET library finaquant® protos.
As explained in the related article, subtable transformation is a simple way of applying the same table function on every subtable of an input table.

Function Router1 extends this concept further; with the table functions of the .net library finaquant® protos like FunctionRouterA() it is possible to apply selected table functions on selected subtables of an input table, as the examples below will illustrate.

Function Router

The entity attributes (all the text and numeric attributes of an input table excluding subtable fields) determine which table function is to be applied on which subtable (sub-data of an entity).

Following scenarios may give you an idea about the use of function routers in practice:

  1. You want to calculate expected population of some cities in ten years from now depending on historical data like birth rate, population, migration rate and so on. You have an input table containing historical data for many cities, and depending on some attributes of the cities (entity attributes) like size (small, medium, big), altitude (low, high), average income category etc., you need to apply different formulas (table functions) for different cities to obtain the estimated population for each city in a result table.
  2. Scenario analysis: For the same scenario above, you may want to calculate the expected population for each city under different discrete scenarios like optimistic, realistic and pessimistic, and you may need to apply totally different formulas (or functions), each with its own set of additional parameters, to compute the expected populations for each scenario (see 2. example below).
  3. You want to calculate a performance measure for some financial assets, and for each asset group (entity attribute) you need to apply a group-specific performance function (table function). You have an input table containing data for multiple assets belonging to several asset groups, and you want to obtain the performance measure for each asset in a result table.
  4. For the same scenario above, you might have written your performance functions with another library for matrix computations like ILNumerics, R or matlab. You want to calculate the performance of each asset by feeding its subtable to its group-specific matrix function, provided that all the subtable fields are numbers; that is, either numeric attributes or key figures in the finaquant data structure (see 4. example below).
  5. You have some numbers like estimations, prices, costs etc. related with some entities like city, product, or invoice in a table. You want to check and validate these numbers, and generate warnings if something is wrong. For each entity-group you may need to apply a different set of validation functions (table or matrix functions). In that sense, a function router can also work like a rules engine! With the parameters of a function router you can set dynamically which validation functions are to be applied on which entities (see 5. example below).

Continue reading

Digiprove sealCopyright secured by Digiprove © 2013 Tunc Ali Kütükcüoglu
  1. The term “function router” is first used by the author of this article in this context and meaning. []
Posted in Calculation engine | Tagged , , | 2 Comments

Table functions for transforming subtables

All the C# code examples presented on this page can be found in the related demo function of MS Visual Studio project FinaquantProtosStarter which can be downloaded at the product page of the free .NET library finaquant® protos.
Sometimes, you want to execute the same set of table operations (table function) on every subtable of an input table; this is a quite common calculation pattern in many applications in business and science.

Subtable transformation1 is a simple way of applying the same table function on every homogenous subtable of an input table.

Following scenarios may give an idea about the use of subtable transformation:

  • You have a complex formula for computing the expected population of a city depending on historical data like birth rate, migration, population and so on. You have a table containing all these historical data for many cities, and you want to apply the same formula on the sub-data (i.e. subtable) of each city to obtain the expected population for each city.
  • You have a well-tested standard function for calculating the performance of a financial asset depending on parameters like historical prices and benchmark values. You have a table containing all these parameters for multiple assets, and you want the obtain the performance measure for every asset in the table.
  • You have a quite complex matrix function written with another library for matrix computations like ILNumerics, R or matlab, which calculates some statistical estimations based on historical data related with an entity like city, person or product. You have an input table with historical data of multiple entities, and you want to apply your matrix function on sub-data (subtable) of each entity in order to obtain a result table comprising the estimations for each entity (see 3. example below: submatrix transformation).

Expected average temperature in May

As an introduction to the code examples below, assume you have a table function for calculating the expected average temperature of a certain location next year in May, based on historical average temperatures.

Calculating expected average temperature with a table function

You have a table including historical average temperatures of many locations, and you want to calculate the expected temperature for each location. Then you need a subtable transformer like the table function TransformSubTables in the uncommercial .net library finaquant® protos.

Calculating expected temperature for each location with subtable transformer Continue reading

Digiprove sealCopyright secured by Digiprove © 2013 Tunc Ali Kütükcüoglu
  1. The term “subtable transformation” is first used by the author of this article in this context and meaning. []
Posted in Calculation engine | Tagged , , | Leave a comment

Transforming rows: row-by-row processing of tables

All the C# code examples presented on this page can be found in the related demo function of MS Visual Studio project FinaquantProtosStarter which can be downloaded at the product page of the free .NET library finaquant® protos.
Even though quite easy to understand and use, TransformRowsDic()1 in the free .net library finaquant® protos is one of the most versatile and useful table transformation functions. This table function offers a simple way for applying user-defined formulas on each row of a table.

Using this row transformer you can:

  1. derive the value of a field of a table in terms of other related fields.
  2. apply logical and mathematical operations on some fields of table.

Following examples illustrate how TransformRowsDic() can be used in practice for the purposes listed above. All the examples start with the TestTable below as the primary input parameter2. Continue reading

Digiprove sealCopyright secured by Digiprove © 2013 Tunc Ali Kütükcüoglu
  1. Transform rows of a table using dictionaries as associative arrays for keeping field names and values. []
  2. These examples can be found as demo function in the Visual Studio project “FinaquantProtosStarter” which can be downloaded at the product page of finaquant® protos, in versions 1.02 and higher. []
Posted in Calculation engine | Tagged , , | Leave a comment

Filtering and sampling tables by dates

All the C# code examples presented on this page can be found in the related demo function of MS Visual Studio project FinaquantProtosStarter which can be downloaded at the product page of the free .NET library finaquant® protos.
Assume, you have a data table containing daily prices of different products in each entry, and you want to exclude all rows of table associated with weekend days. That is, you want to have only entries with business days from Monday to Friday in your table. Then you need a date filter.

Assume, you have a data table containing temperatures measured at different locations almost daily (with some days missing), and you want to have only month-end measurements to calculate the yearly volatility of temperature for each location. If a measurement is missing on the last day of a certain month, the nearest previous temperature should be taken as a proxy value for the month-end day. In such a case, you need a date sampler with search options like previous (backward), next (forward) and nearest as shown below with examples.

Date-related variations like “last Monday value of each month”, “quarterly month-end averages”, “monthly business-day maximums” and so on can be obtained with date samplers and filters of finaquant® protos1 with the help of the table aggregation functions wherever necessary. Continue reading

Digiprove sealCopyright secured by Digiprove © 2013 Tunc Ali Kütükcüoglu
  1. Table functions for date filtering and sampling are available in releases 1.02 and higher. []
Posted in Calculation engine | Tagged , , , | Leave a comment