Using the Command Line Tools - netrium/Netrium GitHub Wiki

The following works through using the Netrium command line tools on Windows:

Assumptions:

  • You've created a folder where all files will be saved;
  • You've got Netrium running and in a command line window, it will execute if you enter the command normalise --version

Step 1: Author the Sample Contract

The sample contract we are using to show how the tools works is very simple - it delivers a GBP amount defined by 'cpardAmount' on two dates.

contract = when (at (date 2011 07 20)) (scale cpardAmount (one (Financial gbp cash Nothing))) `and` when (at (date 2011 07 21)) (scale cpardAmount (one (Financial gbp cash Nothing)))

Copy this text, and save it to a file named demo.contact

Step 2: Author the Contract Observables file

To successfully compile the contract, we have to let Netrium know what the type of 'cpardAmount' is. To do this, we will need to author a contract specific Observables file to define the types of variables declared in the contract. Create a file named demo.obsdb.xml, add the below text, and save it.

<?xml version='1.0' ?>
<ObservableDB>
  <ObservableDecl name="cpardAmount"><Double/></ObservableDecl>
</ObservableDB>

Note that there is an Observable Declaration for cpardAmount, and it has a type of Double. Netrium only supports Boolean and Double types.

Step 3: Author or reuse a UnitsDB

UnitsDB files are used to introduce new language elements into Netrium to add various static data elements, such as currencies, cash flow types etc.

For this sample, copy the Units.DB.xml file from the examples folder into your working folder.

Step 3: Compile the contract

In a command line window, we will need to now issue the command:

normalise --obs-db=demo.obsdb.xml --units-db=units.db.xml demo.contract

This will now compile the contract, and produce an output demo.contract.xml file which we can use further. For information, the contract now looks (note the relatively non-standard HaXml formatting; this can be turned off by using the --fast flag) as follows:

<?xml version='1.0' ?>
<And
  ><When
    ><At
    >2011-07-20 00:00:00 UTC</At
    ><Scale
      ><NamedVal
      >cpardAmount</NamedVal
      ><One
        ><Financial
          ><Currency
          >gbp</Currency
          ><CashFlowType
          >cash</CashFlowType></Financial></One></Scale></When
  ><When
    ><At
    >2011-07-21 00:00:00 UTC</At
    ><Scale
      ><NamedVal
      >cpardAmount</NamedVal
      ><One
        ><Financial
          ><Currency
          >gbp</Currency
          ><CashFlowType
          >cash</CashFlowType></Financial></One></Scale></When></And>

Step 4: Visualise the Contract

Now that we have a contract that has been compiled, we can visualise it to see what it looks like in a tree form. To do this, we use the visualise command line tool:

visualise demo.contract.xml --png

This command creates a PNG file named demo.contract.png representing the contract. Note that GraphViz is used internally, and it has limits to the size of PNG file that it can author. It is recommended for larger contracts that SVG files are used.

Step 5: Prepare a Contract Simulation

To simulate the contract, we need to define what the simulation is. For the sake of a demo, lets assume that the contract is acquired on 2011-04-15 at 14:21:44 UTC, and that cpardAmount has a continuous value from 2011-04-15 00:00:00 UTC of 3.

Copy the text below, and save it into demo.timeseries.xml file:

<?xml version="1.0"?>
<SimulationInputs>
	<Time>2011-04-15 14:21:44 UTC</Time>
	<ObservationSeries type="Double" var="cpardAmount">
		<SeriesEntry>
			<Time>2011-04-15 00:00:00 UTC</Time>
			<Double>3</Double>
		</SeriesEntry>
		<SeriesUnbounded/>
	</ObservationSeries>
	<Choices/>
</SimulationInputs>

Step 6: Execute the Contract Simulation

In the command line, issue the command:

simulate demo.contract.xml demo.timeseries.xml demo.out.xml

This takes the compiled contract, demo.contract.xml and the time series file demo.timeseries.xml and outputs the simulation results to demo.out.xml.

Once executed, the file demo.out.xml will be created, which contains:

<?xml version='1.0' ?>
<SimulationResult
  ><SeriesEntry
    ><Time
    >2011-07-20 00:00:00 UTC</Time
    ><Receive
      ><Double
      >3.0</Double
      ><Financial
        ><Currency
        >gbp</Currency
        ><CashFlowType
        >cash</CashFlowType></Financial></Receive></SeriesEntry
  ><SeriesEntry
    ><Time
    >2011-07-21 00:00:00 UTC</Time
    ><Receive
      ><Double
      >3.0</Double
      ><Financial
        ><Currency
        >gbp</Currency
        ><CashFlowType
        >cash</CashFlowType></Financial></Receive></SeriesEntry
  ><Finished
  /><Time
  >2011-07-21 00:00:00 UTC</Time
  ><Zero
  /><ProcessState
    ><Time
    >2011-07-21 00:00:00 UTC</Time
    ><BlockedThreads
    /><RunnableThreads/></ProcessState></SimulationResult>

This shows:

  • The receipt of 3 gbp cash on 2011-07-20 at 00:00:00 UTC and 2011-07-21 at 00:00:00 UTC
  • The simulat process finished at 2011-07-21 at 00:00:00 UTC
  • There were no remaining Blocked or Runnable threads

Depending on how the simulation is defined, the system can be left with threads blocked by exhausted data (there is missing observable data required for further execution), or left in an otherwise runnable state (such as with a Anytime/Until contract).

⚠️ **GitHub.com Fallback** ⚠️