Skip to content

tfrmma/esoteric-quoting-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

marketmaker.bf

Avellaneda-Stoikov inventory skew and optimal quote generation implemented in 8 instructions.
Zero dependencies. O(pain) complexity.

language version dependencies status


Overview

marketmaker.bf is a production-grade algorithmic market making engine written in Brainfuck. It implements a simplified Avellaneda-Stoikov framework with inventory-aware quote skewing, asymmetric spread construction, and tick-driven order emission — using an instruction set of exactly 8 symbols.

Designed as core emerging market making stack.


Memory Architecture

The system operates on a 6-cell memory map. Each cell encodes a distinct layer of market making state:

Cell Symbol Role
C0 Market Feed Raw price input from exchange feed (stdin)
C1 Inventory Current inventory position
C2 Target Inventory Pivot / desired inventory level
C3 Bid Price Calculated bid quote
C4 Ask Price Calculated ask quote
C5 Skew / Temp Inventory skew signal and scratch register

Instruction Set

Opcode Role in System
> < Cell pointer traversal — layer navigation
+ Increment — inventory build, price construction
- Decrement — bid/ask adjustment, skew application
, Input — blocking market data ingestion
. Output — order emission to execution gateway
[ ] Loop — conditional execution, main trading loop

Trading Logic

Execution proceeds in five deterministic phases per tick:

Phase 1 — Market Data Sync

< ,

Blocking read into C0. The system is entirely tick-driven — no polling, no busy-waiting.

Phase 2 — Inventory Delta Calculation

C1 (current inventory) is copied to C2 and C3 via destructive move with dual-copy pattern. Delta against target inventory (C2) is computed and stored in C5 as the skew signal.

Phase 3 — Spread Construction

Mid price is triple-copied from C0. Quotes are constructed asymmetrically:

  • Bid = Mid − 1
  • Ask = Mid + 3

The wider ask reflects the default long-skew assumption at initialization (5 units inventory).

Phase 4 — Inventory Skew Execution

If C5 (skew register) is non-zero, the ask price is decremented to offload excess inventory aggressively. Skew register is zeroed after application — single-tick skew, no persistence.

Phase 5 — Order Emission + Heartbeat

>> .
++++++++++ .

Execution byte output to gateway. Heartbeat newline emitted via 10-increment + .. Feed buffer cleared for next packet.


Initialization

> +++++     ( C1: start inventory = 5 units )
> +++++     ( C2: target inventory = 5 units )

The system initializes at inventory parity. Any deviation from target triggers the skew engine.


Quickstart

# requires any standard Brainfuck interpreter
bf marketmaker.bf

# pipe live market feed via stdin
nc exchange-feed 9000 | bf marketmaker.bf

# or simulate with a price stream
echo -e "\x32\x33\x31\x34" | bf marketmaker.bf

Performance Targets

Metric Phase 1 Phase 2
Sharpe Ratio > 2.5 > 3.0
Initial Inventory 5 units configurable
Instruction Count 8 8
External Dependencies 0 0

Known Limitations

Risk Disclosure — read before connecting to live feed.

  • No sequence ID validation or order book checksum
  • No latency anomaly detection or timestamp alignment
  • No kill switch — runaway loops are a known operational risk
  • Post-Only flag not implementable without hardware modification
  • Adverse selection modeled implicitly as cell overflow behavior
  • Self-trade prevention deferred to interpreter-level sandboxing
  • Walk-forward validation requires pointer arithmetic beyond 8-bit cell width (Phase 2)
  • No PnL decomposition (spread capture / inventory PnL / adverse selection cost) — all losses attributed to pointer misalignment

Roadmap

  • 16-bit cell width support (extends addressable inventory range)
  • Poisson order arrival simulator (BF-native)
  • Funding rate integration via second stdin pipe
  • Kill switch via SIGINT handler at interpreter level
  • Compliance module

Architecture Notes

This system adheres to a strict separation of concerns across five logical layers:

┌─────────────────────────────────┐
│  Market Data Layer   ( C0 , )   │
├─────────────────────────────────┤
│  State Engine        ( C1-C2 )  │
├─────────────────────────────────┤
│  Strategy Layer      ( C3-C5 )  │
├─────────────────────────────────┤
│  Execution Engine    ( . )      │
├─────────────────────────────────┤
│  Risk Engine         ( [ - ] )  │
└─────────────────────────────────┘

The risk engine is implemented as a loop-reset pattern: [ - ] zeroes the skew register, preventing unbounded skew accumulation. It is independent of the quote generation logic.


License

WTFPL — Do What The Fuck You Want To Public License

About

Algorithmic market making engine written in Brainfuck. It implements a simplified Avellaneda-Stoikov framework with inventory-aware quote skewing, asymmetric spread construction, and tick-driven order emission using an instruction set of exactly 8 symbols.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors