Exploring the language 3 - netrium/Netrium GitHub Wiki
Making Decisions
Return to Increasing the Complexity
Real world contracts include 4 main types of decision making:
- Or - when the contract holder has to make one choice or another at an instant in time;
- Anytime - when the contract holder can make once choice or another at any moment in time;
- Until - when a contract is valid only until an observable external condition has been met;
- Conditional - when a contract only becomes valid upon an observable condition becoming true.
Introducing Optionality
The or
keyword allows the contract to make a decision at a precise moment in time (for example, with a European option). Decisions must always be supplied - with a timestamp that they were made at - in the Observable database. This can be used to support options and other path dependent contracts. or
is always accompanied by a label, which allows the decision to be addressed at runtime.
contract = or "foo" (one (Financial gbp cash Nothing)) Zero
In the above example, the decision named 'foo' must be supplied by the contract acquirer. If they select to take the option 'foo', they will receive one GBP, otherwise Zero.
The Syntax Tree:
The Decision Tree:
Contract Termination Upon Events
contract = until cparbFoo (one (Financial gbp cash Nothing))
In the above contract (which is rather abnormal!), the contract acquirer will receive one GBP unless at the moment of acquisition, the external observable cparbFoo
has the value True
. This is normally used for certain families of options and limit contracts.
The Syntax Tree:
The Decision Tree:
Contract Enablement Upon Events
contract = anytime "foo" cparbFoo (one (Financial gbp cash Nothing))
In the above contract (which is also rather abnormal!), the contract acquirer will receive one GBP only once the external observable cparbFoo
has the value True
. This is normally used for certain families of options (such as American or Bermudan exercise options).
The Syntax Tree:
The Decision Tree (note the increased complexity!):
Making Conditional Decisions
Sometimes, contracts need to do one thing or another, based not upon a contractual decision, but rather due to an external observable - for example, a Barrier Option.
contract = cond cparbFoo (one (Financial gbp cash Nothing)) (one (Financial eur cash Nothing))
The above contract works as follows: if, at the moment of acquisition, the external observable cparbFoo
is True, the acquirer receives one GBP, otherwise one EUR.
The Syntax Tree:
The Decision Tree:
Making Complex Decisions
Sometimes the decisions to be made are not simply Yes/No, but rather a complex chain of decisions, such as is found in a Gas Swing contract. A Gas Swing Contract allows the contract holder to make 3 decisions on regular schedule - to select a low, a normal or a high level of gas delivery. A snippet from the Decision Tree for a Gas Swing:
The above diagram shows the two tiers of decisions required to make 3 possible selections. For example:
- To select Normal delivery level, the contract execution process sets the choice "selection[normal]" to true;
- To select High delivery level, the contract execution process has to perform the following selections: "selection[normal]" and "selection[low-high]" must be both false;
- To select Low delivery level, the contract execution process has to perform the following selections: "selection[normal]" must be false and "selection[low-high]" must be true;
Since these contracts are normally highly customised, it is normal for a custom user interface to be built to execute and manage them. In these cases, the user interface can easily be authored to hide this complexity.