Advanced

Execution as a separate system

The decision and the action are two systems, and mixing them is how a bug becomes money. The decision system writes an intent; the execution system turns an intent into a position, and nothing else.

What you will see

One. An action with no intent field is an action nobody can explain later.

About 1 min of reading

Try It

Replay intents against an executor

1

Write three intents

printf 'call 0.05\ncall 0.05\nput 0.03\n' > /tmp/intents.txt; wc -l < /tmp/intents.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Three intents. The first two are the same, which is the case to catch.
2

Refuse a duplicate intent

sort -u /tmp/intents.txt | wc -l

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Two. A duplicate intent is a bug in the decision system, and the count says so.
3

Log the action with its intent

printf 'intent=call-1 action=filled size=0.05\n' > /tmp/act.txt; grep -c 'intent=' /tmp/act.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One. An action with no intent field is an action nobody can explain later.

Data Flow

An intent to a position
1 The decision writes an intent
↓
2 The executor checks the current position
↓
3 The executor refuses or acts
↓
4 The action is logged with the intent that caused it
Why this works
Why the two systems have different failure modes

The decision system fails by being wrong. The execution system fails by being slow or stuck. Those need different fixes and different logs.

The state that must be rebuilt

The executor's position must be readable from the broker, never from memory. A restart that forgets a position is a restart that trades.

Examples

The intent is the interface

One line: instrument, side, size, reason. Anything richer is a channel where a bug can hide.

Why the executor never decides

An executor that adjusts size is making a decision nobody modelled. It is allowed to refuse, not to change.

The replay is the test

Feed yesterday's intents to today's executor. If the positions differ, the change was in the executor, and now you know where.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← The paper trade log
Previous Lesson
The paper trade log
Next Lesson
Hedging a position across legs
Hedging a position across legs →