SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
Designing Customized Hash Function For High-
         Frequency Trading Systems




              Jim Wang, PhD, CFA
         Program in Financial Engineering
          Stevens Institute of Technology
            Hoboken, NJ, 07030, USA
Introduction

                                  TC
                 Trading Engine   P     GUI

    UDPx          TC
    5             P
                 Stock Exchange


● TCP messages between U and Exchanges
● UDP messages from all market participants
Source of Latency
● Propagation latency: speed of light 5us/km,
  Mahwah – Weehawken 40km.

● Transmission latency: high speed
  communication link throughput rate 1-10
  Gbps. 1us/1kb to serialize and transport.

● Processing latency. dedicated CPU for
  critical threads, kernel bypass, hardware
  acceleration.
Processing Latency
● Parallel Problem: With 10k symbols, 6
  major exchanges, relatively
  independent, tasks be streamlined.
● Through Software optimization:
  flexibility, take advantage of general
  purpose CPU improvements over time.
● Through Hardware Acceleration:
  specialized hardware, improve
  consistency by reducing jitter.
Software Optimization
● Separation of high speed vs high
  complexity. Latency sensitive task in
  critical path, computation intensive
  tasks offload to separate
  thread/process.
● memory caching: critical decision
  thread pined to a dedicated CPU.
● inline vs function calls: C, C++, Java.
Market Data Processing
● Data using ticker symbol as key
● String of Characters translation into
  integer memory location
● MS Windows and Linux systems
  standard of hash table (associative
  array, or memory map)
● Generic implementation without
  knowledge of input
Data Specificity
● Tickers are not made of equal tick
  event probability
● BAC, ADV of 180M shares
● BAC.PRE, ADV of 18K shares
● Difference of 10K times or more
● Search miss (or Collision) in ticker BAC
  is 10K more costly than that in BAC.
  PRE
Data Specificity
Implementation: Data Structure
#define NUM_SYMBOL 10000 // total symbol universe

struct tSym {                    // define a data structure to for tick events
   char m_pszTicker[12];          // Stock Symbol
   long long key;                // key to symbol
   short nextIndex;              // next search location if there is collision
};

tSym gSym[NUM_SYMBOL];             // allocate memory for symbol universe ticks

#define HASH_TABLE_SIZE 28091 // optimal size by empirical calibration

short keyToIndex[HASH_TABLE_SIZE]; // allocate memory for hash table

inline short symbolToIndex(long long key) { // search function
    short i = keyToIndex[key % HASH_TABLE_SIZE]; // find the key
   while ((i>-1) && (gSym[i].key != key)) i = gSym[i].nextIndex; // next if collision
    return i; // either find the matching key, or symbol unknown (return -1)
}
Implementation: Initialization
Assuming you have loaded g_nSym number of known symbol in descending
order of expected tick activity gSym[j].m_pszTicker, j=0 most active stock

void buildHashTable() // This function will initialize the hash table
{
  int i, j, k; short key;
  memset(keyToIndex, -1, sizeof(short)*HASH_TABLE_SIZE); // init cell to -1
  for (j=0; j<g_nSym; j++) { // first path
      gSym[j].nextIndex = -3; // initialize to resolution unknown
      gSym[j].key = *(long long *)gSym[j].m_pszTicker; // assign key
      key = gSym[j].key % HASH_TABLE_SIZE;                   // collision possible
      if (keyToIndex[key] == -1) { keyToIndex[key] = j; gSym[j].nextIndex = -1; }
  } // terminating, do not resolve collision
  for (j=0; j<g_nSym; j++) if (gSym[j].nextIndex == -3) { // second path
      i = keyToIndex[gSym[j].key % HASH_TABLE_SIZE];
      k = -2; // find an empty slot
      while (gSym[i].nextIndex > -1) { i = gSym[i].nextIndex; k--; }
      gSym[i].nextIndex = j; gSym[j].nextIndex = k; // k number of collisions
  }
}
Implementation: Expansion
Intraday, symbol not in known universe may appear (IPO, or symbol change).

int addSymbol(char *sym)
{
   int j = g_nSym++;
   strcpy(gSym[j].m_pszTicker, sym);
   gSym[j].key = *(long long *)gSym[i].m_pszTicker;

    short key = gSym[j].key % HASH_TABLE_SIZE;
    int i = keyToIndex[key];
    if (i == -1) { keyToIndex[key] = j; gSym[j].nextIndex = -1; }
    else {
        int k = -2; // find an empty slot
        while (gSym[i].nextIndex > -1) { i = gSym[i].nextIndex; k--; }
        gSym[i].nextIndex = j;
        gSym[j].nextIndex = k; // k number of steps, so we know
    }
    return j;
}
Implementation: Example



● HUN active stock, convert to long int, mod 28091, hash table
  location 3462, return symbol location 433, match key, done
  in 1 unit of time.
● RYN medium activity, convert to long int, mod 28091, hash
  table location 3462 (collision), return symbol location 433,
  not match, next location 1811, match key, done in 2 unit of
  time
● AHL.PR low activity, convert to long int, mod 28091, hash
  table location 3462 (collision), return symbol location 433,
  not match, next location 1811, not match, next location 5363,
  match key, done in 3 unit of time.
Optimal HASH_TABLE_SIZE
  Max Collision     Costs
Optimal HASH_TABLE_SIZE
Cost<500,TotalCollision<800,MaxCollision<=4,Minimize Size
Worst HASH_TABLE_SIZE

        ● 24 active Symbols start with "ST"
        ● When convert into long long, mode by
          24576, result the same key 5203 (24
          collisions)
        ● Size divisible by 256 are worst
        ● Byte Order Encoding
           ○ Big-endian
           ○ Little-endian
        ● Padding Convension
           ○ Null padding (ARCA)
           ○ Space padding (NASDAQ)
        ● Need to calibrate own system for best
          performance

Weitere ähnliche Inhalte

Was ist angesagt?

Design and minimization of reversible programmable logic arrays and its reali...
Design and minimization of reversible programmable logic arrays and its reali...Design and minimization of reversible programmable logic arrays and its reali...
Design and minimization of reversible programmable logic arrays and its reali...Sajib Mitra
 
NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)Igalia
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Igalia
 
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-TreePingCAP
 
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...zaidinvisible
 
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Igalia
 
Reversible logic gate
Reversible logic gateReversible logic gate
Reversible logic gateDebraj Maji
 
Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)Igalia
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfDenys Goldiner
 
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...VLSICS Design
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Kai Katsumata
 
Implementation of the Binary Multiplier on CPLD Using Reversible Logic Gates
Implementation of the Binary Multiplier on CPLD Using Reversible Logic GatesImplementation of the Binary Multiplier on CPLD Using Reversible Logic Gates
Implementation of the Binary Multiplier on CPLD Using Reversible Logic GatesIOSRJECE
 
Code GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowCode GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowMarina Kolpakova
 
Low cost reversible signed comparator
Low cost reversible signed comparatorLow cost reversible signed comparator
Low cost reversible signed comparatorVLSICS Design
 
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...IJERA Editor
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...Linaro
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebraAswiniT3
 
Tpr star tree
Tpr star treeTpr star tree
Tpr star treeWin Yu
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkAlexey Smirnov
 

Was ist angesagt? (20)

Design and minimization of reversible programmable logic arrays and its reali...
Design and minimization of reversible programmable logic arrays and its reali...Design and minimization of reversible programmable logic arrays and its reali...
Design and minimization of reversible programmable logic arrays and its reali...
 
NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
 
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree
[Paper Reading]Chucky: A Succinct Cuckoo Filter for LSM-Tree
 
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
 
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
 
Reversible logic gate
Reversible logic gateReversible logic gate
Reversible logic gate
 
Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdf
 
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...
A NEW DESIGN TECHNIQUE OF REVERSIBLE BCD ADDER BASED ON NMOS WITH PASS TRANSI...
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法
 
Implementation of the Binary Multiplier on CPLD Using Reversible Logic Gates
Implementation of the Binary Multiplier on CPLD Using Reversible Logic GatesImplementation of the Binary Multiplier on CPLD Using Reversible Logic Gates
Implementation of the Binary Multiplier on CPLD Using Reversible Logic Gates
 
Code GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowCode GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flow
 
Low cost reversible signed comparator
Low cost reversible signed comparatorLow cost reversible signed comparator
Low cost reversible signed comparator
 
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...
Implementation and Comparison of Efficient 16-Bit SQRT CSLA Using Parity Pres...
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Tpr star tree
Tpr star treeTpr star tree
Tpr star tree
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
 

Ähnlich wie Custom Hash Function for High Frequency Trading

GBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APIGBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APISri Ambati
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdfAyushKumar93531
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorMasahiko Sawada
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAprithan
 
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...InfluxData
 
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...Akihiro Hayashi
 
Introduction to CUDA
Introduction to CUDAIntroduction to CUDA
Introduction to CUDARaymond Tay
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterSeveralnines
 
A taste of GlobalISel
A taste of GlobalISelA taste of GlobalISel
A taste of GlobalISelIgalia
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Rakib Hossain
 

Ähnlich wie Custom Hash Function for High Frequency Trading (20)

Js2517181724
Js2517181724Js2517181724
Js2517181724
 
Js2517181724
Js2517181724Js2517181724
Js2517181724
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Reduction
ReductionReduction
Reduction
 
GBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APIGBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O API
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdf
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributor
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDA
 
Keccak
KeccakKeccak
Keccak
 
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...
Optimizing InfluxDB Performance in the Real World by Dean Sheehan, Senior Dir...
 
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...
Exploring Compiler Optimization Opportunities for the OpenMP 4.x Accelerator...
 
1530-shrivastava
1530-shrivastava1530-shrivastava
1530-shrivastava
 
Introduction to CUDA
Introduction to CUDAIntroduction to CUDA
Introduction to CUDA
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera Cluster
 
A taste of GlobalISel
A taste of GlobalISelA taste of GlobalISel
A taste of GlobalISel
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
 
LDPC Encoding
LDPC EncodingLDPC Encoding
LDPC Encoding
 

Kürzlich hochgeladen

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Kürzlich hochgeladen (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Custom Hash Function for High Frequency Trading

  • 1. Designing Customized Hash Function For High- Frequency Trading Systems Jim Wang, PhD, CFA Program in Financial Engineering Stevens Institute of Technology Hoboken, NJ, 07030, USA
  • 2. Introduction TC Trading Engine P GUI UDPx TC 5 P Stock Exchange ● TCP messages between U and Exchanges ● UDP messages from all market participants
  • 3. Source of Latency ● Propagation latency: speed of light 5us/km, Mahwah – Weehawken 40km. ● Transmission latency: high speed communication link throughput rate 1-10 Gbps. 1us/1kb to serialize and transport. ● Processing latency. dedicated CPU for critical threads, kernel bypass, hardware acceleration.
  • 4. Processing Latency ● Parallel Problem: With 10k symbols, 6 major exchanges, relatively independent, tasks be streamlined. ● Through Software optimization: flexibility, take advantage of general purpose CPU improvements over time. ● Through Hardware Acceleration: specialized hardware, improve consistency by reducing jitter.
  • 5. Software Optimization ● Separation of high speed vs high complexity. Latency sensitive task in critical path, computation intensive tasks offload to separate thread/process. ● memory caching: critical decision thread pined to a dedicated CPU. ● inline vs function calls: C, C++, Java.
  • 6. Market Data Processing ● Data using ticker symbol as key ● String of Characters translation into integer memory location ● MS Windows and Linux systems standard of hash table (associative array, or memory map) ● Generic implementation without knowledge of input
  • 7. Data Specificity ● Tickers are not made of equal tick event probability ● BAC, ADV of 180M shares ● BAC.PRE, ADV of 18K shares ● Difference of 10K times or more ● Search miss (or Collision) in ticker BAC is 10K more costly than that in BAC. PRE
  • 9. Implementation: Data Structure #define NUM_SYMBOL 10000 // total symbol universe struct tSym { // define a data structure to for tick events char m_pszTicker[12]; // Stock Symbol long long key; // key to symbol short nextIndex; // next search location if there is collision }; tSym gSym[NUM_SYMBOL]; // allocate memory for symbol universe ticks #define HASH_TABLE_SIZE 28091 // optimal size by empirical calibration short keyToIndex[HASH_TABLE_SIZE]; // allocate memory for hash table inline short symbolToIndex(long long key) { // search function short i = keyToIndex[key % HASH_TABLE_SIZE]; // find the key while ((i>-1) && (gSym[i].key != key)) i = gSym[i].nextIndex; // next if collision return i; // either find the matching key, or symbol unknown (return -1) }
  • 10. Implementation: Initialization Assuming you have loaded g_nSym number of known symbol in descending order of expected tick activity gSym[j].m_pszTicker, j=0 most active stock void buildHashTable() // This function will initialize the hash table { int i, j, k; short key; memset(keyToIndex, -1, sizeof(short)*HASH_TABLE_SIZE); // init cell to -1 for (j=0; j<g_nSym; j++) { // first path gSym[j].nextIndex = -3; // initialize to resolution unknown gSym[j].key = *(long long *)gSym[j].m_pszTicker; // assign key key = gSym[j].key % HASH_TABLE_SIZE; // collision possible if (keyToIndex[key] == -1) { keyToIndex[key] = j; gSym[j].nextIndex = -1; } } // terminating, do not resolve collision for (j=0; j<g_nSym; j++) if (gSym[j].nextIndex == -3) { // second path i = keyToIndex[gSym[j].key % HASH_TABLE_SIZE]; k = -2; // find an empty slot while (gSym[i].nextIndex > -1) { i = gSym[i].nextIndex; k--; } gSym[i].nextIndex = j; gSym[j].nextIndex = k; // k number of collisions } }
  • 11. Implementation: Expansion Intraday, symbol not in known universe may appear (IPO, or symbol change). int addSymbol(char *sym) { int j = g_nSym++; strcpy(gSym[j].m_pszTicker, sym); gSym[j].key = *(long long *)gSym[i].m_pszTicker; short key = gSym[j].key % HASH_TABLE_SIZE; int i = keyToIndex[key]; if (i == -1) { keyToIndex[key] = j; gSym[j].nextIndex = -1; } else { int k = -2; // find an empty slot while (gSym[i].nextIndex > -1) { i = gSym[i].nextIndex; k--; } gSym[i].nextIndex = j; gSym[j].nextIndex = k; // k number of steps, so we know } return j; }
  • 12. Implementation: Example ● HUN active stock, convert to long int, mod 28091, hash table location 3462, return symbol location 433, match key, done in 1 unit of time. ● RYN medium activity, convert to long int, mod 28091, hash table location 3462 (collision), return symbol location 433, not match, next location 1811, match key, done in 2 unit of time ● AHL.PR low activity, convert to long int, mod 28091, hash table location 3462 (collision), return symbol location 433, not match, next location 1811, not match, next location 5363, match key, done in 3 unit of time.
  • 13. Optimal HASH_TABLE_SIZE Max Collision Costs
  • 15. Worst HASH_TABLE_SIZE ● 24 active Symbols start with "ST" ● When convert into long long, mode by 24576, result the same key 5203 (24 collisions) ● Size divisible by 256 are worst ● Byte Order Encoding ○ Big-endian ○ Little-endian ● Padding Convension ○ Null padding (ARCA) ○ Space padding (NASDAQ) ● Need to calibrate own system for best performance