Moving Towards Real Time Calculation of VaR – Real Time VaR Part 3

So far in this blog posts series, I discussed about the project and the 3 most commonly used methods to calculate VaR for a given portfolio. A portfolio is a collection of assets.

Today in my blog, I describe the technical background of the project. The 3 methods were required to be implemented as some extensions written to WSO2 Siddhi (as described in the post Real Time VaR Part 1). A Siddhi extension provides a way of incorporating Siddhi custom code and functions. It has a namespace and a set of functions declared within this namespace. The basic structure of an extension used in a Siddhi query is as follows:

<namespace>:<function name>(<parameter 1>, <parameter 2>,…)

Each term can be described as:

  • namespace – provides the function an extension group and also allow Siddhi to identify a function as an extension

  • function name – function declared within the namespace. This is used to call a predefined functionality implemented in Java as an extension.

  • Parameters – the parameters required by the function.



There are 5 basic types of extensions. They are:

  • Custom Function

  • Aggregate Function

  • Window Function

  • Stream Function

  • Stream Processor

For this project we have to manipulate a set of historical data and then calculate the VaR for that set of data. Until it gets the required number of events, the extension should not give an output. Once the required number of events are received, the extension should give an output for each future event by sliding a window which has the size of the required number of events.

That is, for example let’s say the batch size is 250. The extension waits until it collects 250 events from the external event stream. Once it gets the 250th event, it should calculate the VaR for the past 250 events and give it as an output. When it receives the 251st event it should slide the window which has a length of 250 events by one event so that the window now contains events from 2 to 251. Then it should calculate the VaR for that window. The best extension that suits these requirements is the Stream Processor. Hence we selected it to implement our extensions.

At first we were not very familiar with writing Siddhi extensions or deploying them in the DAS 3.0.0. Hence we wrote some sample extensions using StreamProcessor. Among the samples were extensions to convert Celsius to Fahrenheit and vice versa. Once we got familiar with the extensions, we started writing the extension for Historical Simulation method.

Since one requirement was to implement a set of extensions, and not a single extension, we decided to implement three separate extensions for each method, Historical Simulation, Parametric and Monte Carlo Simulation.

The method signature used in the Siddhi Query for Historical Simulation is as follows:

var:historical(batch_size, confidence_level, Symbol, Price, symbols_list, shares_list)

  • var: the namespace name

  • historical: method name

  • batch_size: the window size that should be considered when calculating VaR

  • confidence_level: the level of confidence required in the answer

  • Symbol: the attribute “Symbol” from the input stream

  • Price: the attribute “Price” from the input stream

  • symbols_list: list of symbol separated by comma. These are the symbols of a given portfolio

  • shares_list: the corresponding number of shares for each symbol in the given portfolio

Note that the above query calculates the VaR for a single portfolio only. Later these implementations were changed to support multiple portfolios which will be discussed later in this blog posts series.

In my next blog post, I will include more details on the extension we wrote for the Historical Simulation method. Hope this post would give you some thing new for your knowledge.


One thought on “Moving Towards Real Time Calculation of VaR – Real Time VaR Part 3

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s