1 of 33

MesoSim: �Overview and �Basic operations

Tibor Kiss <tibor@deltaray.io>

2023. 02. 09.

🏗️ Work In Progress version! 👷

1

© DeltaRay. 2022. All Rights Reserved

2 of 33

Agenda

  • Overview�
  • Portal overview�

  • Prerequisite crash course:
    • JSON
    • Lua�
  • Theory: Job Definition
    • Structure
    • Entry and Exit
    • Adjustments
    • Indicators
    • Simulator Settings
    • Variables
    • Functions

  • Workflow�
  • Practice: Strategies
    • Short Put
    • Strangle
    • Iron Condor�
  • Backtest Analytics

2

© DeltaRay. 2022. All Rights Reserved

3 of 33

MesoSim - Overview

  • Automated Backtest Service specialized in Options

  • Goal #1: Enable quick and precise validation of advanced Options Strategies

  • Goal #2: Reduce barrier of entry for automated Options Strategy development
    • Compared to QuantConnect, Backtrader, Zipline, etc.� �
  • High resolution (5min) data for Intraday modeling:
    • SPX: 2005 .. Yesterday - sourced from CBOE
    • BTCUSD / ETHUSD: 2019 .. Today sourced from Deribit
    • More to come in 2023!

3

© DeltaRay. 2022. All Rights Reserved

4 of 33

4

© DeltaRay. 2022. All Rights Reserved

5 of 33

Prerequisite Crash Course: JSON

  • “JSON is a … file format … that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays” - Wikipedia
  • Used in MesoSim to specify the job / backtest.��
  • Example:�{

"Title": "Dynamic Hedging",

"Author": "Nassim Taleb",

"Publication Year": 1996,

"Categories": � [

"Options",

"Hedging",

"Derivative Securities"

]

}

Attribute (aka key)

Value

Text (aka string)

Number (aka integer)

Array (or list) of strings

Object�declaration

5

© DeltaRay. 2022. All Rights Reserved

6 of 33

Prerequisite Crash Course: JSON pt2

6

© DeltaRay. 2022. All Rights Reserved

7 of 33

Prerequisite Crash Course: Lua

  • “Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications.” [Wikipedia]�
  • Used in MesoSim to evaluate Statements
  • Examples:�Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio

> 1 + 1

2

> 3 < 5

true

> 100 + (2 * 7) / 4.3

103.25581395349

> max(1, 5)5

> abs(-4.3)�4.3

Prompt

Statements

Result

Statements with function call

7

© DeltaRay. 2022. All Rights Reserved

8 of 33

Concept: Job Definition

  • The easy language of options trading:
    • Domain Specific Language to describe the entire trade lifecycle
    • JSON Structure with LUA Statements

  • Example mental model:
    • Environment: Backtesting on SPX with $10000 Planned Capital between 2020 and 2023
    • Structure: Trading Put Butterflies 60 days out�
    • Entry: Initiating the trade 60 minutes after open every Monday�
    • Exit: Closing after 20 days in trade or when TP or SL hits�
    • Adjustment: Adjust the Upper Long leg if trade becomes too directional�
    • SimSettings: Expect fills at Mid Price with slippage of 0.05 per contract

8

© DeltaRay. 2022. All Rights Reserved

9 of 33

Concept: High Level Job Definition

What to trade: Butterfly, Iron Condor, etc

When to enter

How to adjust

When to exit

Environment

9

© DeltaRay. 2022. All Rights Reserved

10 of 33

Concept: Environment & SimSettings

  • Top level environment related variables:
    • Name: Identifier of the run. Use generate to create a new one
    • TemplateName: Custom text.
    • Start / End: Defines the backtest period
    • Cash: Planned Capital for the run ($/BTC/ETH)
    • Symbol: Defines that underlying to trade� ��
  • SimSettings - Simulation related settings:
    • commission: Amount of commission value per leg ($/BTC/ETH)
    • slippage: Amount of slippage per leg ($/BTC/ETH)
    • fill model: AtBidAsk or AtMidPrice

10

© DeltaRay. 2022. All Rights Reserved

11 of 33

Concept: Structure [1/2]

  • Describes what’s being traded:�Structure = Name + Expirations + Leg�
  • Name: �Unique name (such as: Iron Condor)�
  • Expirations: �List of Expiration Objects defining tenors �using Dates Till Expiration within Min-Max range.�
  • Legs:�List of Leg Objects defining Options Contracts�with their respective Quantity. Leg refers back�to Expiration using Expiration’s Name.�

11

© DeltaRay. 2022. All Rights Reserved

12 of 33

Concept: Structure [2/2]

  • StrikeSelector (object):�Selects Strike of the Option Contract based on one of:�Price, Greeks, IV or absolute strike value (Statement). ��Min-Max (optionally) defines the range for selection�

Full example with no lower boundary:�

12

© DeltaRay. 2022. All Rights Reserved

13 of 33

Concept: Entry [1/2]

  • Describes when to potentially enter trades �
  • Schedule: �Defines when entries are considered.�Accepted values for Every:�day, mon, tue, wed, thu, fri, sat, sun, 5min
  • Conditions: �Gates entry with a pre-condition. �Example use: IV Rank check�
  • AbortConditions:�Gates entry with a post-condition, evaluated the position is planned.�Example use: Abort entry if Position Theta is negative�

13

© DeltaRay. 2022. All Rights Reserved

14 of 33

Concept: Entry [2/2]

  • ReentryDays (integer):�How many days to wait until a new trade is taken.�Valid values: 0 .. inf
  • Concurrency (object):Enables multiple trades in flight (aka Campaign mode)�
  • VarDefines (attribute-value):Capture state at trade initiation. ��Example use: Record Position Theta at initiation�and exit later, when position deta decayed.

14

© DeltaRay. 2022. All Rights Reserved

15 of 33

Concept: Exit

  • Schedule:�When to consider Exiting the position. See Entry…�
  • MaxDaysInTrade (integer):�Exit trade after a certain amount of days reached.�
  • ProfitTarget (statement):�Exit trade when the specified amount of profit is reached.�
  • StopLoss (statement):�Exit trade when the specified amount of loss is reached.�
  • Conditions (list of statements):�Exit when any of the included statement evaluates to true��Example: Exit when Position’s Theta decreases to 25% compared to Theta at Initiation.

15

© DeltaRay. 2022. All Rights Reserved

16 of 33

Concept: Adjustment [1/2]

  • Describes when and how to adjust the position. [Optional]�Adjustment = Schedule + Conditions + Adjustment Actions��
  • Adjustments are conditional: �When the Statement evaluates to true then the�Adjustment Action is taken.��
  • Adjustment Actions:
    • MoveLegAdjustment:Close the specified leg and re-open at a new strike.
    • AddStructureAdjustment:�Planned, but not available at the moment.�

16

© DeltaRay. 2022. All Rights Reserved

17 of 33

Concept: Adjustment [2/2]

  • Conditional Adjustments in detail:��"ConditionalAdjustments": {

"abs(pos_delta) > 5": {

"MoveLegAdjustment": {

"LegName": "short_put",

"StrikeSelector": {

"Min": null,

"Max": null,

"Delta": "pos_delta - leg_short_put_delta"

}

}

}

}

  • Condition: abs(pos_delta) > 5Becomes true when the absolute value of position delta is bigger than 5�
  • Delta selection: pos_delta - leg_short_put_delta�Take the position delta (before removing any leg) and subtract the specified leg delta. �That number will be our target delta for the new leg.

Statements

New Strike definition

17

© DeltaRay. 2022. All Rights Reserved

18 of 33

Concept: Indicators

  • TA Indicators on the Underlying�
  • Indicator values accessible as variables in all Statements

  • Example:�

18

© DeltaRay. 2022. All Rights Reserved

19 of 33

Concept: Variables

  • Purpose: Represent state in the simulator

  • Can be used in statements for conditions and calculations�
  • Types:
    • Built-in
    • Indicator
    • User Defined (via Entry.VarDef)

  • Built in variables:

19

© DeltaRay. 2022. All Rights Reserved

20 of 33

Concept: Functions

  • Lua Functions available �in Statements:
    • abs
    • min
    • max
    • random
    • sqrt
    • pow
    • log
    • ceil
    • floor

  • Example: Adding randomness to entries

  • Example: Compounding

20

© DeltaRay. 2022. All Rights Reserved

21 of 33

MesoSim Workflow

Simple Run

Analyze

Clone

Run

Change

Save as template

Run from template on period of interest

Iterate

Analyze

For�each�period

Once�happy

21

© DeltaRay. 2022. All Rights Reserved

22 of 33

- Strategies -

22

© DeltaRay. 2022. All Rights Reserved

23 of 33

Practice - Strategies - Built-in Templates

Template name

Strategy

Note

[Strangle]

Short Strangle

Contains adjustments to maintain delta neutrality.

[Strangle-DownDay]

Short Strangle

Enters on days where open < yesterday’s close.�Demonstrates Entry.Conditions.

[Strangle-ThetaFilter]

Short Strangle

Enters only if pos_theta > 50. �Demonstrates Entry.AbortCondition.

[Strangle-Campaign]

Short Strangle

Demonstrates Multiple Positions in Flight (aka Campaign mode).�

[IC-0DTE]

Iron Condor

0 Days Till Expiration Iron Condor. �Intraday strategy.

[ShortPut-EMACross]

Short Put

Demonstrates Indicators. �

[ShortPut-HighIV]

Short Put

Demonstrates IV Rank.�

[ThetaEngine]

Short Put

David Sun’s Theta Engine.�Demonstrates Credit Targeted Dynamic Sizing.

To be added: BoxCar-NG

Condor

Currently not a built-in template, but clonable from here:�https://blog.deltaray.io/boxcar-ng-an-optimized-boxcar

23

© DeltaRay. 2022. All Rights Reserved

24 of 33

Practice - Strategies - Short Put - Simple Run:

24

© DeltaRay. 2022. All Rights Reserved

25 of 33

Practice - Strategies - Short Put - Job Definition:

25

© DeltaRay. 2022. All Rights Reserved

26 of 33

- Strategy live coding -

26

© DeltaRay. 2022. All Rights Reserved

27 of 33

Backtest Analytics:

  • PnL Graph: Log Returns!�
  • Trade Statistics table�
  • Greeks Graph�
  • Indicator Graph

  • Intra-trade PnL (MAE / MFE) graph�

  • Events Tab (keyboard navigation)�
  • Full tearsheet (very soon)

  • Trade Export to ONE�
  • NAV CSV Export �
  • Events JSON export for post-processing�

27

© DeltaRay. 2022. All Rights Reserved

28 of 33

Event Viewer:

  • Provides observability to:
    • Expiration selection
    • Strike Selection
    • Entries
    • Exits
    • … Pretty much everything�
  • Keyboard navigation enabled:�Click and use arrow keys for quick nav.��
  • Exposes variables for every event�

28

© DeltaRay. 2022. All Rights Reserved

29 of 33

References

29

© DeltaRay. 2022. All Rights Reserved

30 of 33

Thank You!�Any questions?

30

© DeltaRay 2022.- All Rights Reserved

30

© DeltaRay. 2022. All Rights Reserved

31 of 33

Backup slides

31

© DeltaRay 2022.- All Rights Reserved

31

© DeltaRay. 2022. All Rights Reserved

32 of 33

MesoSim - Timeline

  • Development started: March 2022�
  • Private beta: June 2022�
  • Public GA (v1.0): July 2022

  • Milestones since v1.0:
    • v2.0: Multiple Positions in Flight, Indicators, IV Rank & Pct
    • v2.1: Event Log Export, Better Missing Data Handling, Mobile improvements
    • v2.2: Simple Run interface
    • v2.3: Crypto (beta), MaxLegs=20, RootSelector�
  • 2023 Plans:
    • More flexibility by scheduled Statement Execution
    • CSV Input Support
    • Relative Expirations
    • Content: Education, Blog posts, trades

32

© DeltaRay. 2022. All Rights Reserved

33 of 33

MesoSim: Portal

  • Backtests: �Lists the executed backtests including it’s statistics�
  • New Run
    • Simple: Simplified user interface to quickly check ideas.�
    • JobEditor: Complete user interface for strategy development.�
    • Templated: Run previously saved strategies in various time frames easily�
  • Manage Templates:
    • Create / Modify / Delete templates. Not a replacement for JobEditor!�
  • User menu: Simulation Preferences, Subscription Management

  • Site:
    • Service Status, Contact form and T&C�
  • References: Blog, Docs, Slack

33

© DeltaRay. 2022. All Rights Reserved