SlideShare una empresa de Scribd logo
1 de 10
(c) Higher Frequency Trading
Using BigDecimal and double
Using BigDecimal and double
(Or why you can use double for money)
Higher Frequency Trading
(c) Peter Lawrey
(c) Higher Frequency Trading
Nearest representable value

Floating point numbers are represented using
a sum of powers of two e.g. 9.75 = 8 + 1 + 0.5
+ 0.25

Values like 0.1 cannot be exactly represented
using floating point but when you print it, it
“knows” to print the simplest number which
would be represented at this value.
(c) Higher Frequency Trading
Rounding a double

Why do we get errors with double
– Representation errors,
• 0.1 is not exactly 0.1
• new BigDecimal(0.1)
– Using BigDecimal.valueOf(0.1) instead.
– Rounding errors,
• each calculation gives the closest match
(c) Higher Frequency Trading
Rounding a double

Rounding errors are not random errors. You
can predict that the error will be less than 1
ulp.

If you display a number with such as error it
will have a sane toString()

However, if you perform a calculation on a
value which cannot be exactly represented,
you will see the error.
(c) Higher Frequency Trading
Rounding a double
Ways to round to significant digits
public static double round2(double d) {
return Math.round(d * 1e2) / 1e2;
}
(c) Higher Frequency Trading
OpenHFT Java-Lang
/**
* Performs a round which is accurate to within 1 ulp.
* i.e. for values very close to 0.5 it might be rounded up or down.
* This is a pragmatic choice for performance reasons as it is
assumed you are not working on the edge of the precision of double.
*/
public static double round2(double d) {
final double factor = 1e2;
return d > WHOLE_NUMBER || d < -WHOLE_NUMBER ?
(long) (d < 0 ? d * factor - 0.5 : d * factor + 0.5) / factor : d;
}
(c) Higher Frequency Trading
Errors and double
Exercise 10 mins

Use BigDecimal to print the actual value of 0.1

Print the values of x for
for(double d = 0.0; d != 1.0; d += 0.1)
Print the values of x for
for(int x = 0; x != 10; x++) {
double d = x * 0.1;
Print the values of x for
for(int x = 0; x != 10; x++) {
double d = x / 10.0;
(c) Higher Frequency Trading
BigDecimal or double
Exercise 20 mins.

Write a loop to take the mid price of 1000 bid
and ask values as BigDecimal and double.

Use randomly generated prices.
– What sort of distribution should your use?

Test the mid values are the same.

How long does each take? Why?
(c) Higher Frequency Trading
rounding double
Exercise 20 mins.

Write a function for rounding a double
– Using Math.round
– Using / of whole numbers

Compare the result with BigDecimal.

Can this be written without Math.round?

Is this any faster?
(c) Higher Frequency Trading
Caching BigDecimal
Exercise 30 mins.

Write a function to cache BigDecimals created
from a double.
public BigDecimal intern(double d)

Compare the performance with
BigDecimal.valueOf() for values 0.01 to 1.00

Is this any faster?

Más contenido relacionado

La actualidad más candente

Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack IntroductionVikram Shinde
 
How to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyHow to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyInfluxData
 
Spark introduction and architecture
Spark introduction and architectureSpark introduction and architecture
Spark introduction and architectureSohil Jain
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1Maruf Hassan
 
Introduction to the Disruptor
Introduction to the DisruptorIntroduction to the Disruptor
Introduction to the DisruptorTrisha Gee
 
An Introduction to Elastic Search.
An Introduction to Elastic Search.An Introduction to Elastic Search.
An Introduction to Elastic Search.Jurriaan Persyn
 
Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016Sid Anand
 
RedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ TwitterRedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ TwitterRedis Labs
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at ScaleFabian Reinartz
 
Stop the Guessing: Performance Methodologies for Production Systems
Stop the Guessing: Performance Methodologies for Production SystemsStop the Guessing: Performance Methodologies for Production Systems
Stop the Guessing: Performance Methodologies for Production SystemsBrendan Gregg
 
TDC2017 - Misturando dados com Pentaho para insights mais significativos
TDC2017 - Misturando dados com Pentaho para insights mais significativosTDC2017 - Misturando dados com Pentaho para insights mais significativos
TDC2017 - Misturando dados com Pentaho para insights mais significativosAmbiente Livre
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream ProcessingSuneel Marthi
 

La actualidad más candente (20)

ELK Stack
ELK StackELK Stack
ELK Stack
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack Introduction
 
How to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyHow to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah Crowley
 
Spark introduction and architecture
Spark introduction and architectureSpark introduction and architecture
Spark introduction and architecture
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1
 
ELK introduction
ELK introductionELK introduction
ELK introduction
 
ElasticSearch
ElasticSearchElasticSearch
ElasticSearch
 
Introduction to the Disruptor
Introduction to the DisruptorIntroduction to the Disruptor
Introduction to the Disruptor
 
An Introduction to Elastic Search.
An Introduction to Elastic Search.An Introduction to Elastic Search.
An Introduction to Elastic Search.
 
De Mensajería hacia Logs con Apache Kafka
De Mensajería hacia Logs con Apache KafkaDe Mensajería hacia Logs con Apache Kafka
De Mensajería hacia Logs con Apache Kafka
 
Google Cloud Dataflow
Google Cloud DataflowGoogle Cloud Dataflow
Google Cloud Dataflow
 
RXJS 入門介紹
RXJS 入門介紹RXJS 入門介紹
RXJS 入門介紹
 
Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016
 
RedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ TwitterRedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ Twitter
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at Scale
 
Stop the Guessing: Performance Methodologies for Production Systems
Stop the Guessing: Performance Methodologies for Production SystemsStop the Guessing: Performance Methodologies for Production Systems
Stop the Guessing: Performance Methodologies for Production Systems
 
TDC2017 - Misturando dados com Pentaho para insights mais significativos
TDC2017 - Misturando dados com Pentaho para insights mais significativosTDC2017 - Misturando dados com Pentaho para insights mais significativos
TDC2017 - Misturando dados com Pentaho para insights mais significativos
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream Processing
 

Destacado

Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016Peter Lawrey
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @JavaPeter Lawrey
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconPeter Lawrey
 
Introduction to chronicle (low latency persistence)
Introduction to chronicle (low latency persistence)Introduction to chronicle (low latency persistence)
Introduction to chronicle (low latency persistence)Peter Lawrey
 
Advanced off heap ipc
Advanced off heap ipcAdvanced off heap ipc
Advanced off heap ipcPeter Lawrey
 
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint Petersburg
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint PetersburgUnsafe Java World - Crossing the Borderline - JokerConf 2014 Saint Petersburg
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint PetersburgChristoph Engelbert
 
Writing and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaWriting and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaPeter Lawrey
 
Introduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupIntroduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupPeter Lawrey
 
Thread Safe Interprocess Shared Memory in Java (in 7 mins)
Thread Safe Interprocess Shared Memory in Java (in 7 mins)Thread Safe Interprocess Shared Memory in Java (in 7 mins)
Thread Safe Interprocess Shared Memory in Java (in 7 mins)Peter Lawrey
 
7.[54 59]the determinants of leverage of the listed-textile companies in india
7.[54 59]the determinants of leverage of the listed-textile companies in india7.[54 59]the determinants of leverage of the listed-textile companies in india
7.[54 59]the determinants of leverage of the listed-textile companies in indiaAlexander Decker
 
Ruben Licera's Social Media Marketing via Facebook Success Secrets
Ruben Licera's Social Media Marketing via Facebook Success SecretsRuben Licera's Social Media Marketing via Facebook Success Secrets
Ruben Licera's Social Media Marketing via Facebook Success SecretsRUBEN LICERA
 
Final_DF_deck
Final_DF_deckFinal_DF_deck
Final_DF_deckJon Cline
 
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབ
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབཔོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབ
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབQuickoffice Test
 
Advancing learning and transforming scholarship in higher education
Advancing learning and transforming scholarship in higher educationAdvancing learning and transforming scholarship in higher education
Advancing learning and transforming scholarship in higher educationHELIGLIASA
 

Destacado (20)

Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @Java
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @Geecon
 
Introduction to chronicle (low latency persistence)
Introduction to chronicle (low latency persistence)Introduction to chronicle (low latency persistence)
Introduction to chronicle (low latency persistence)
 
Advanced off heap ipc
Advanced off heap ipcAdvanced off heap ipc
Advanced off heap ipc
 
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint Petersburg
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint PetersburgUnsafe Java World - Crossing the Borderline - JokerConf 2014 Saint Petersburg
Unsafe Java World - Crossing the Borderline - JokerConf 2014 Saint Petersburg
 
Writing and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaWriting and testing high frequency trading engines in java
Writing and testing high frequency trading engines in java
 
Introduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupIntroduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users Group
 
Thread Safe Interprocess Shared Memory in Java (in 7 mins)
Thread Safe Interprocess Shared Memory in Java (in 7 mins)Thread Safe Interprocess Shared Memory in Java (in 7 mins)
Thread Safe Interprocess Shared Memory in Java (in 7 mins)
 
7.[54 59]the determinants of leverage of the listed-textile companies in india
7.[54 59]the determinants of leverage of the listed-textile companies in india7.[54 59]the determinants of leverage of the listed-textile companies in india
7.[54 59]the determinants of leverage of the listed-textile companies in india
 
Aplicaciones Básicas de Ubuntu
Aplicaciones Básicas de UbuntuAplicaciones Básicas de Ubuntu
Aplicaciones Básicas de Ubuntu
 
Evolucion De La Comunicaion
Evolucion De La ComunicaionEvolucion De La Comunicaion
Evolucion De La Comunicaion
 
Unhealthy Developing World Food Markets
Unhealthy Developing World Food MarketsUnhealthy Developing World Food Markets
Unhealthy Developing World Food Markets
 
Aplicaciones basicas de unbuntu 14.02 LTE
Aplicaciones basicas de unbuntu 14.02 LTEAplicaciones basicas de unbuntu 14.02 LTE
Aplicaciones basicas de unbuntu 14.02 LTE
 
Ruben Licera's Social Media Marketing via Facebook Success Secrets
Ruben Licera's Social Media Marketing via Facebook Success SecretsRuben Licera's Social Media Marketing via Facebook Success Secrets
Ruben Licera's Social Media Marketing via Facebook Success Secrets
 
Risky Business
Risky BusinessRisky Business
Risky Business
 
Aboriginal Relations, Perspectives from both sides of the fence with Gordon M...
Aboriginal Relations, Perspectives from both sides of the fence with Gordon M...Aboriginal Relations, Perspectives from both sides of the fence with Gordon M...
Aboriginal Relations, Perspectives from both sides of the fence with Gordon M...
 
Final_DF_deck
Final_DF_deckFinal_DF_deck
Final_DF_deck
 
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབ
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབཔོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབ
པོི ུ ཧགཡད ིཇོོོིུནགཧཡཧཏ ཧཙགངགདཧཇ༄༄།ན ཙཅཛཟ ཅཅཅདརཛེ ཏཏེེཇིཇབ
 
Advancing learning and transforming scholarship in higher education
Advancing learning and transforming scholarship in higher educationAdvancing learning and transforming scholarship in higher education
Advancing learning and transforming scholarship in higher education
 

Similar a Using BigDecimal and double

Decimal arithmetic in Processors
Decimal arithmetic in ProcessorsDecimal arithmetic in Processors
Decimal arithmetic in ProcessorsPeeyush Pashine
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptGAURAVNAUTIYAL19
 
Data Representation - Floating Point
Data Representation - Floating PointData Representation - Floating Point
Data Representation - Floating PointFahim Fana
 
Lesson plan on data representation
Lesson plan on data representationLesson plan on data representation
Lesson plan on data representationPooja Tripathi
 
PMHMathematicaSample
PMHMathematicaSamplePMHMathematicaSample
PMHMathematicaSamplePeter Hammel
 
Lec 02 data representation part 1
Lec 02 data representation part 1Lec 02 data representation part 1
Lec 02 data representation part 1Abdul Khan
 
data representation
 data representation data representation
data representationHaroon_007
 
Pertemuan 2 - Sistem Bilangan
Pertemuan 2 - Sistem BilanganPertemuan 2 - Sistem Bilangan
Pertemuan 2 - Sistem Bilanganahmad haidaroh
 
Practice Exercise Set 1
Practice Exercise Set 1Practice Exercise Set 1
Practice Exercise Set 1rampan
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Cyrille Martraire
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxgerardkortney
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1Deepak John
 
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaAplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaLeslieMoncayo1
 
CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com  CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com williamwordsworth10
 

Similar a Using BigDecimal and double (20)

Decimal arithmetic in Processors
Decimal arithmetic in ProcessorsDecimal arithmetic in Processors
Decimal arithmetic in Processors
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.ppt
 
Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
 
Data Representation - Floating Point
Data Representation - Floating PointData Representation - Floating Point
Data Representation - Floating Point
 
Chapter 1
Chapter   1Chapter   1
Chapter 1
 
Lesson plan on data representation
Lesson plan on data representationLesson plan on data representation
Lesson plan on data representation
 
PMHMathematicaSample
PMHMathematicaSamplePMHMathematicaSample
PMHMathematicaSample
 
Lec 02 data representation part 1
Lec 02 data representation part 1Lec 02 data representation part 1
Lec 02 data representation part 1
 
Python Programming
Python Programming Python Programming
Python Programming
 
Es272 ch2
Es272 ch2Es272 ch2
Es272 ch2
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
data representation
 data representation data representation
data representation
 
Pertemuan 2 - Sistem Bilangan
Pertemuan 2 - Sistem BilanganPertemuan 2 - Sistem Bilangan
Pertemuan 2 - Sistem Bilangan
 
Practice Exercise Set 1
Practice Exercise Set 1Practice Exercise Set 1
Practice Exercise Set 1
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1
 
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaAplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
 
CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com  CIS 115 Education for Service--cis115.com
CIS 115 Education for Service--cis115.com
 

Más de Peter Lawrey

Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currencyPeter Lawrey
 
Chronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conferenceChronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conferencePeter Lawrey
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016Peter Lawrey
 
Deterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsDeterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsPeter Lawrey
 
Determinism in finance
Determinism in financeDeterminism in finance
Determinism in financePeter Lawrey
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughputPeter Lawrey
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda codePeter Lawrey
 
Responding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in JavaResponding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in JavaPeter Lawrey
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Streams and lambdas the good, the bad and the ugly
Streams and lambdas the good, the bad and the uglyStreams and lambdas the good, the bad and the ugly
Streams and lambdas the good, the bad and the uglyPeter Lawrey
 

Más de Peter Lawrey (10)

Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currency
 
Chronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conferenceChronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conference
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016
 
Deterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsDeterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systems
 
Determinism in finance
Determinism in financeDeterminism in finance
Determinism in finance
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughput
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda code
 
Responding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in JavaResponding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in Java
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Streams and lambdas the good, the bad and the ugly
Streams and lambdas the good, the bad and the uglyStreams and lambdas the good, the bad and the ugly
Streams and lambdas the good, the bad and the ugly
 

Último

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Último (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

Using BigDecimal and double

  • 1. (c) Higher Frequency Trading Using BigDecimal and double Using BigDecimal and double (Or why you can use double for money) Higher Frequency Trading (c) Peter Lawrey
  • 2. (c) Higher Frequency Trading Nearest representable value  Floating point numbers are represented using a sum of powers of two e.g. 9.75 = 8 + 1 + 0.5 + 0.25  Values like 0.1 cannot be exactly represented using floating point but when you print it, it “knows” to print the simplest number which would be represented at this value.
  • 3. (c) Higher Frequency Trading Rounding a double  Why do we get errors with double – Representation errors, • 0.1 is not exactly 0.1 • new BigDecimal(0.1) – Using BigDecimal.valueOf(0.1) instead. – Rounding errors, • each calculation gives the closest match
  • 4. (c) Higher Frequency Trading Rounding a double  Rounding errors are not random errors. You can predict that the error will be less than 1 ulp.  If you display a number with such as error it will have a sane toString()  However, if you perform a calculation on a value which cannot be exactly represented, you will see the error.
  • 5. (c) Higher Frequency Trading Rounding a double Ways to round to significant digits public static double round2(double d) { return Math.round(d * 1e2) / 1e2; }
  • 6. (c) Higher Frequency Trading OpenHFT Java-Lang /** * Performs a round which is accurate to within 1 ulp. * i.e. for values very close to 0.5 it might be rounded up or down. * This is a pragmatic choice for performance reasons as it is assumed you are not working on the edge of the precision of double. */ public static double round2(double d) { final double factor = 1e2; return d > WHOLE_NUMBER || d < -WHOLE_NUMBER ? (long) (d < 0 ? d * factor - 0.5 : d * factor + 0.5) / factor : d; }
  • 7. (c) Higher Frequency Trading Errors and double Exercise 10 mins  Use BigDecimal to print the actual value of 0.1  Print the values of x for for(double d = 0.0; d != 1.0; d += 0.1) Print the values of x for for(int x = 0; x != 10; x++) { double d = x * 0.1; Print the values of x for for(int x = 0; x != 10; x++) { double d = x / 10.0;
  • 8. (c) Higher Frequency Trading BigDecimal or double Exercise 20 mins.  Write a loop to take the mid price of 1000 bid and ask values as BigDecimal and double.  Use randomly generated prices. – What sort of distribution should your use?  Test the mid values are the same.  How long does each take? Why?
  • 9. (c) Higher Frequency Trading rounding double Exercise 20 mins.  Write a function for rounding a double – Using Math.round – Using / of whole numbers  Compare the result with BigDecimal.  Can this be written without Math.round?  Is this any faster?
  • 10. (c) Higher Frequency Trading Caching BigDecimal Exercise 30 mins.  Write a function to cache BigDecimals created from a double. public BigDecimal intern(double d)  Compare the performance with BigDecimal.valueOf() for values 0.01 to 1.00  Is this any faster?