Exploring The Language 2

shaunlaurens edited this page Mar 25, 2012 · 14 revisions

The role of Time

Return to Making Decisions

Time is a critical element to Netrium. When executing a contract via simulate, a key parameter is the contract acquisition time. Take the following example:

import Common

contract =
       (fixedFee generalFee 100)
       (Market gas thm nbp)
       0.67 gbp cash
       [ (date 2010 12 31), (date 2011 1 1) ]
       [ (date 2010 12 31), (date 2011 1 1) ]

In the above example, the following happen: at the moment of contract acquisition, the acquirer pays a 100 GBP fee. Then, at 00:00:00 on 31 December 2010, 670 GBP are paid and 1000 Therms of UK NBP Gas are received. The same for 00:00:00 on 1 January 2011.

The Syntax Tree for this contract looks like this: (direct link):

Impact of Time

Note how the syntax tree shows the 31 December 2010 events as well as the 1 January 2011 events.

The Decision Tree clearly shows the impact of time - in this case, the contract was acquired at 00:00:00 on 01 January 2011. Netrium will simply discard any contract events which have happened in the past, as is the case with real world financial contracts. The Decision Tree looks like this: (direct link).

Impact of Time

Partial Executions

In order to integrate the contracts into an executing system with live contracts, it is usually required to be able to partially execute a contract. The simulation process allows us to to this by adding a second <Time> element to the <SimulationInputs>

<?xml version="1.0"?>
    <Time>2012-03-24 09:25:01 UTC</Time> <!-- start -->
    <Time>2012-04-24 09:25:01 UTC</Time> <!-- forced end -->

Dates and Calendars

Haskell's standard Date handling libraries are normally relatively complex to work with. Netrium includes a suite of methods to ease working with dates and calendars. These have been extracted and outsourced into a more general project, available on Hackage.


  • Find the first, next, previous day of type (weekend, business day, working day etc.)
  • Find the business day or working day n days earlier or later
  • Count the number of business or working days etc in a calendar.
  • Easily construct a date or date time
  • Add or subtract Days, Months, Quarters & Years
  • and more.


Observing External Data

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.