Investment Studio > Views > System > Rules

Under Rules, you specify how and when transactions are to be generated by the portfolio's trading system.

The system's date range (start date to end date) is set using the date controls in the toolbar. Individual rules are entered in the grid below the toolbar:

The system is executed (1) when it's been modified and you leave the System view and (2) whenever the underlying data (quotes, manually specified transactions) changes. Any old soft transactions in the system's date range are deleted prior to system execution.

Rules toolbar

The toolbar contains five control groups. They can be repositioned by dragging their beveled "grip"

and hidden by unchecking the corresponding entry in the pop-up menu's Toolbar submenu (right-click the grid or the toolbar to open it). With the exception of the date range controls, all toolbar controls also have functional equivalents in the pop-up menu.

The toolbar is visible only if it contains a least one visible control group and is itself set to visible.
 
"Rules" group

New. Click to enter a new rule.

If the selected portfolio contains only one asset, a new rule for that asset will be added to the system (after the selected rule, if any; after existing rules otherwise) and selected. You can then proceed to edit the new rule in the grid.

If the selected portfolio contains more than one asset, you will be presented with a list of all assets in the portfolio:

The list can be sorted alphabetically by Name, Symbol or Currency (to do so, click the column headers; click again to reverse the sort order) and assets can also be located by name using a standard Find dialog (right-click the list, then use Find).

Select one or more assets (for multiple selections, click each asset while pressing the Ctrl key; to select a range, click its boundary elements while pressing the Shift key) and click OK. A new rule record will be added to the system for each selected asset. Proceed to edit the new rule record(s) in the grid as usual.

To close the asset list without creating new rule records, click .

Copy. Like New, except that the new rules are copies of the selected rule.
Delete. Click to delete the selected rule.
 
"Orientation" group

Standard grid orientation buttons:
Rowwise display. When this button is depressed, each rule is displayed in a grid row (rule fields map to grid columns).
Columnwise display. When this button is depressed, each rule is displayed in a grid column (rule fields map to grid rows).
 
"Position" group

Standard grid position buttons, plus a reference number aid:
Move up / left. Click to move the selected rule toward the beginning of the list.
Move down / right. Click to move the selected rule toward the end of the list.
Renumber. Click to renumber all rules by their position in the grid.
Grid position does not affect rule evaluation and execution.
 
"Changes" group

Commit. Click to commit to all changes made in the Rules grid since the System view was last selected or since the latest Rules Commit operation (if more recent). Leaving the System view causes an implied Commit operation.
Discard. Click to discard all changes made in the Rules grid since the System view was last selected or since the latest Rules Commit operation (if more recent).
 
"Dates" group
Use these controls to set the system's date range.

Upon system execution, the dates in this range are stepped through in chronological order. For each step, the system rules are evaluated and transactions are generated when the specified conditions are satisfied (Condition field = TRUE).

To disable the entire system, simply enter a date range well into the future (e.g. a start date somewhere in the 24th century). Note also that rules can be individually Enabled and disabled.

From left to right:

First date. Click to set the system's start date = date of first transaction in portfolio.
First common date. Click to set the system's start date = first common date in portfolio (defined as the date of the most recent initial transaction in a porfolio asset).
System start date. Click the spin button for a calendar.

Can be read by expressions throughout the System view using the built-in symbol FROM_DATE.

One frame back. Click to back the system's date range (start and end date) by the current frame length.
One day back. Click to back the system's date range (start and end date) by one day.
Days in range. Frame length (start date to end date) in calendar days. Click the spin button for a list of commonly used frame lengths.
One day forward. Click to advance the system's date range (start and end date) by one day.
One frame forward. Click to advance the system's date range (start and end date) by the current frame length.
System end date. Click the spin button for a calendar.

Can be read by expressions throughout the System view using the built-in symbol TO_DATE.

Last common date. Click to set the system's end date = last common date in portfolio (defined as the date of the oldest last quote for a portfolio asset).
Last date. Click to set the system's end date = date of last quote for a portfolio asset.
 

Rules grid

The system's rules are directly responsible for transaction generation. The rule records listed in the Rules grid therefore reflect the structure of transaction records: each rule must specify an asset, a number of units, a principal value, any fees and an optional message (to be displayed as a comment in the Transactions view). A boolean condition determines when the rule generates a transaction:

Rules can be added, copied and deleted using in the toolbar or the Rules submenu in the grid's pop-up menu.

The rule records fields are:

Field Interpretation
Nr A unique integer number > 0 identifying the rule. Assigned automatically when the rule is created.

Read-only, but rule records can be renumbered collectively by grid position using Position > Renumber in the grid's pop-up menu or in the toolbar.

The rule number can be read by expressions in the Rules grid using the built-in symbol RULE. This can be used to generate messages (for display in the Transactions view) which identify the rule responsible for creating a transaction; see the screenshot above for an example.

Asset An asset symbol specifying the transaction asset for all transactions generated by the rule.

Permanently assigned when the rule is created. Read-only. If you enter a rule and then discover that you got the asset wrong, copy the rule to the correct asset, then delete it.

Enabled Must be checked for the rule to have any effect. Rules which are not enabled are simply ignored upon system execution.

Use the date range control to disable the entire system.

Condition A boolean expression which must = TRUE for a transaction to be generated.

In practice, this is usually a reference to an expression in the Symbols grid.

Units A float expression specifying the number of asset units involved in the generated transaction (see Transaction units).

In practice, this is usually a reference to an expression in the Symbols grid.

Principal A float expression specifying the principal value of the generated transaction (see Transaction value).

In practice, this is usually a reference to an expression in the Symbols grid.

Fees A float expression specifying the cost of the generated transaction (see Transaction fees).

In practice, this is usually a reference to an expression in the Symbols grid.

Flag A string expression specifying the content of the flag field in the generated transaction record.

Transaction flags can be read using the asset_flag and portfolio_flags functions and used to keep track of state changes in the trading system. Another possible use it to give the Portfolios or Assets views advance warning about the trading system's intents for tomorrow, before the quotes needed to book actual transactions become available.

Message A string expression specifying the content of the custom property _COMMENT in the generated transaction record.

Note that the Transactions view's Grid object must be set up with a corresponding custom property definition for the message string to be displayed there.

Tip: use the built-in symbol RULE to obtain the rule's number and create a message (for display in the Transactions view) which identifies the rule responsible for generating the transaction (see screenshot above).

Comment A free-format comment. Has no effect on rule evaluation or system execution.

Should not be confused with the message field!

All asset symbols and built-in symbols available in Symbol grid expressions can also be used in Rules grid expressions.