4. Informatics

34

Transcript of 4. Informatics

Quantitative Finance: a brief overviewPart 4/4 - Informatics

Dr. Matteo L. BEDINI

Central University of Finance and Economics, Beijing, PRC

27 March 2015

Disclaimer

The opinions expressed in these lectures are solely of the author and do notrepresent in any way those of the present/past employers.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 2 / 32

Objective

The objective of this lecture is to provide two example showing theever-growing relevance of Informatics in modern Finance.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 3 / 32

Agenda - IV1

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

1The author would like to thank Ferdinando Ametrano for the interesting discussionon Bitcoin and cryptocurrencies, and Roberto Daluiso for the useful material onAlgorithmic Di�erentiation.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 4 / 32

The Bitcoin Protocols Preliminaries

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 5 / 32

The Bitcoin Protocols Preliminaries

Preliminaries

Hash functions (SHA-256)

Asymmetric cryptography (private/public keys encryption)

Digital signatures

Example

h_SHA256("Hello, world!0") =

1312af178c253f84028d480a6adc1e25e81caa44c749ec81976192e2ec934c64

h_SHA256("Hello, world!4250") =

0000c3af42fc31103f1fdc0151fa747ff87349a4714df7cc52ea464e12dcd4e9

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 6 / 32

The Bitcoin Protocols The Bitcoin protocols

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 7 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 1/62

�[...] Digital signatures provide part of the solution [...]� [N]

Basic information�I, Alice, am giving

Bob one bitcoin�

Better�I, Alice, am giving

+ Alice's digital signatureBob one bitcoin�

Even Better�I, Alice, am giving

+ Alice's digital signatureBob the bitcoin # 123654�

Who's printing serial the serial number 123654? A bank certifying that:

1 bitcoin #123654 actually belongs to Alice

2 Alice hasn't yet spent the bitcoin #123564

hence guaranteeing and authorizing the transaction from Alice to Bob?2Next slides follows [Ni]Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 8 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 2/6

�[...] the main bene�ts are lost if a trusted third party is required to

prevent double spending [...]� [N]

Idea: everybody is a bank thanks to a blockchain.

Bob, before accepting a payment from Alice, has to

1 check his own copy of the blockchain

2 broadcast the transaction on the Bitcoin network.

When enough users (50? 50%?) will have con�rmed (?) the transaction,this will be actually registered on Bob's account.

Two problems remain to be solved:

1 Who's printing serial numbers on bitcoins?

2 Double-spending cannot be di�cult, it must be practically impossible.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 9 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 3/6

�[...] The network timestamps transactions by hashing them into an ongoing chain of

hash-based proof-of-work , forming a record that cannot be changed without redoing the

proof-of-work [...]� [N]

Validating transaction is computationally costly (�nd the nonce).

Reward (today 25 BTC) for the user validating a block.

Mining: 1 CPU = 1 vote

1 Check block's transaction integrity

2 Find the nonce satisfying a given target (such that. . . )

3 Broadcast on Bitcoin block + nonce

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 10 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 4/6

�[...] The longest chain not only serves as a proof of the sequence of

events witnessed, but proof that it came from the largest pool of CPU

available [...]� [N]

Every block points to the previous one (from which then name:blockchain).

Forks may occur whenever two blocks are simultaneously validated.

Keep track of the forks, but always work on the longest chain.

A transaction is con�rmed when 5 other blocks are validated after itsblock on the longest chain.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 11 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 5/6

�[...] As long as a majority of CPU power is controlled by nodes that are

not cooperating to attack the network, they'll generate the longest chain

and outpace the attackers [...]� [N]

Problem of Double-Spending: how to do it?

1 Two transactions TxB and TxC in the same block B? NO. Even ifAlice validates B, other network users will not.

2 Transaction TxB in block B1 and transaction TxC in block B2? NO.Even if Alice validates and broadcast the two blocks, only one of thetwo blocks will be part of the blockchain (i.e., the one reaching thepool of miners with greater computing power).

3 Alice waits for Charlie accepting the transaction, goes back of 6blocks, forks the blockchain and try to outpace it with her newbranch. OK only if Alice (alone) has at least the 51% ofcomputing power of the whole network.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 12 / 32

The Bitcoin Protocols The Bitcoin protocols

Bitcoin 6/6

Bitcoin is a peer-to-peer protocol enabling transaction in bitcoins.The result is an online payment system that does not need trustedthird party.

Starting from 2009, 50 BTC are generated and given to those whovalidate a block.

This amount halves every four years (today: 25 BTC).

This is the only way of creating new bitcoins.

In 2140 there will be 21 mln of bitcoins and the total supply ofbitcoins will cease to grow.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 13 / 32

The Bitcoin Protocols bitcoins: Further Considerations

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 14 / 32

The Bitcoin Protocols bitcoins: Further Considerations

The bitcoins economyBTC ecosystem (http://www.coindesk.com/data/bitcoin/) � 25th March2015:

Total blocks: 348,323Total bitcoins: 13,958,025Market cap: ≈3,432,676,151.21 USD (≈ 7 770 550 893 USD July '14)First block mined on the 3rd January 2009

Figure: Closing prices of bitcoinsDr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 15 / 32

The Bitcoin Protocols bitcoins: Further Considerations

A note on mining

Who is (was) getting rich in a gold race?

Figure: Source: BusinessWeek

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 16 / 32

The Bitcoin Protocols bitcoins: Further Considerations

A new fast-changing world

1 Are bitcoins good moneys?

I BTW: Are bitcoins a currency or a commodity?I Good money should provide stable purchasing power which, in turns,

depends on both demand and supply.I The lack of political manipulation can be viewed both as a plus and as

a minus when it comes to judge the success of bitcoins as a currency.

2 Lot of development

I Ethereum https://www.ethereum.org/: decentralized application.I Ripple https://ripple.com/: agnostic peer-to-peer payment system.I Litecoin, Dodgecoin, ...I Hayeck-money (see the paper of Ametrano [A])I ...

3 Bitcoin technology holds some promises, bitcoins as a currency is probably�only� a (very) successful experiment.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 17 / 32

Algorithmic Di�erentiation Preliminaries

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 18 / 32

Algorithmic Di�erentiation Preliminaries

The Chain-Rule

In its simplest form:df (g (x))

dx=

df (u)

du

∣∣∣∣u=g(x)

· dg (x)

dx.

Example: y := f (x1, x2) = x1x2 + sin (x1)

We want to compute ∇y :1 y = u + v ⇒ ∂y

∂u = 1, ∂y∂v = 1, where

2 u := x1x2 ⇒ ∂u∂x1

= x2,∂u∂x2

= x1

3 v := sin (x1) ⇒ ∂v∂x1

= cos (x1), ∂v∂x2

= 0

Consequently

∇y =

[∂y∂x1∂y∂x2

]=

[∂y∂u

∂u∂x1

+ ∂y∂v

∂v∂x1

∂y∂u

∂u∂x2

+ ∂y∂v

∂v∂x2

]

=

[1 · x2 + 1 · cos (x1)

1 · x1 + 1 · 0

]=

[x2 + cos (x1)

x1

]Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 19 / 32

Algorithmic Di�erentiation Motivation

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 20 / 32

Algorithmic Di�erentiation Motivation

Computing the Greeks of an option

The value V of �nancial derivative is a function of some input parameter θ(d-dimensional)

V = V (θ) .

The Greeks represents the sensitivity of the price to changes of theunderlying parameter θ and this is what we are interested in

dV

dθ.

Example: 4 of a European call option (θ = s)

V (s) = sN (d+)− Ke−rτN (d−), d± =[ln(sK

)+(r ± σ2

2

)τ]/ (σ√τ).

4 :=dV

ds= N (d+) .

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 21 / 32

Algorithmic Di�erentiation Motivation

How to compute?

Finite di�erence:dV

dθ≈ V (θ + h)− V (θ)

h.

Problems:

1 Accuracy: if h is too big the estimate is rough, if h is too small,numerical error at numerator is ampli�ed.

2 Computational cost:

Cost(V (θ) & dV

)Cost (V (θ))

= # of partial derivatives + 1.

Note that the number of derivatives may be large, not just 1 or 2: e.g.for a vanilla 10Y EUR swap it may be 42 (see, e.g., [H]).

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 22 / 32

Algorithmic Di�erentiation Motivation

Monte Carlo pricingKeep in mind that the value V (θ) of a derivative is often computed via MonteCarlo pricing methods, which are computationally expensive:

V (θ) := E [Φ (Z , θ)] , Z is a r.v.

≈ 1

N

N∑i=1

Φ (Z (ωi ) , θ) , for only one price!

Idea

We compute the derivative path-by-path

dV

dθ=

d

dθE [Φ (Z , θ)]

!= E

[∂

∂θΦ (Z , θ)

]≈ 1

N

N∑i=1

∂θΦ (Z (ωi ) , θ)

and using Algorithmic Di�erentiation (AD) and we can achieve

Cost(V (θ) & dV

)Cost (V (θ))

≤ 4.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 23 / 32

Algorithmic Di�erentiation Algorithmic Di�erentiation: the main Idea

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 24 / 32

Algorithmic Di�erentiation Algorithmic Di�erentiation: the main Idea

Algorithmic Di�erentiation 1/2

The idea is that a function implemented as a computer program is just thecomposition of simpler functions and then one can use the chain rule:

�[...] Algorithmic di�erentiation (AD) [...] is a set of programming

techniques for the e�cient calculation of the derivatives of functions

implemented as computer programs. The main idea underlying these

techniques is the fact that any such function, no matter how complicated,

can be interpreted as a composition of basic arithmetic and intrinsic

operations that are easy to di�erentiate. [...]� [CG]

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 25 / 32

Algorithmic Di�erentiation Algorithmic Di�erentiation: the main Idea

Algorithmic Di�erentiation 2/2

�[...] What makes AD particularly attractive, when compared to

�nite-di�erence methods is its computational e�ciency. In fact, AD

exploits the information on the structure of the computer code in order to

optimize the calculation. In particular, when one requires the derivatives of

a small number of outputs with respect to a large number of inputs, the

calculation can be highly optimized by applying the chain rule through the

instructions of the program in opposite order with respect to their original

evaluation. [...]� [CG]

Tangent method: forward application of the chain rule.

Adjoint method: backward application of the chain rule.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 26 / 32

Algorithmic Di�erentiation Algorithmic Di�erentiation: the main Idea

Example Adjoint Method

Figure: Backward di�erentiation of f (x1, x2) = x1x2 + sin (x1). Source [wiki].

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 27 / 32

Algorithmic Di�erentiation Algorithmic Di�erentiation: the main Idea

Other aspects

The interested audience can �nd further interesting material in

Marc Henrard's paper [H] which pays attention to the problem ofcalibration using the implicit function theorem.

Luca Capriotti's paper [C] which provides interesting numericalexperiments.

References given in the above papers can give an idea of the increasinginterest of the �nancial community in this programming technique that canbe of crucial importance.

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 28 / 32

Bibliography and Informatics Brainteasers

Agenda - IV

1 The Bitcoin ProtocolsPreliminariesThe Bitcoin protocolsbitcoins: Further Considerations

2 Algorithmic Di�erentiationPreliminariesMotivationAlgorithmic Di�erentiation: the main Idea

3 Bibliography and Informatics Brainteasers

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 29 / 32

Bibliography and Informatics Brainteasers

Informatics Brainteaser 1/3

Add arithmetic operators (plus, minus, times, divide) to make the followingexpression true:

3 1 3 6 = 8.

You can use any parentheses you'd like.

(Source [X2]).

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 30 / 32

Bibliography and Informatics Brainteasers

Informatics Brainteaser 2/3

Consider the following piece of code:

double x = 1.0;

double a = x*x - 2.0*x + 1.0;

if(a==0.0){/*do stuff here*/}

Why you may never execute the code inside the if-cycle?

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 31 / 32

Bibliography and Informatics Brainteasers

Informatics Brainteaser 3/3

How many are the functions from a set of m elements into a set of nelements?

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 32 / 32

Bibliography and Informatics Brainteasers

F. Ametrano. Hayek Money: The Cryptocurrency Price Stability

Solution. Available at http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2425270.

L. Capriotti. Fast Greeks by algorithmic di�erentiation. The Journal ofComputational Finance, 3-35, Volume 14/Number 3, Spring 2011.Available at http://www.luca-capriotti.net/pdfs/Finance/jcf_capriotti_press_web.pdf.

L. Capriotti, M. Giles. Algorithmic Di�erentiation: Adjoint Greeks

Made Easy. 2011. Available at http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1801522.

T. F. Crack. Heard on the Street: Quantitative Questions from Wall

Street Job Interview. Paperback, 2014 ([X1] of brainteasers).

M. Henrard. Adjoint Algorithmic Di�erentiation: Calibration and

Implicit Function Theorem. OpenGamma Quantitative Research,November 2011. Available at

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 32 / 32

Bibliography and Informatics Brainteasers

http://www.opengamma.com/sites/default/files/

adjoint-algorithmic-differentiation-opengamma1.pdf.

G. Laakmann McDowell. Cracking the Coding Interview: 150

Programming Questions and Solutions. Paperback, 2011 ([X2] ofbrainteasers).

S. Nakamoto. Bitcoin: A peer-to-peer electronic cash system.https://bitcoin.org/bitcoin.pdf, October 2008.

M. Nielsen. How the Bitcoin protocols actually works.http://www.michaelnielsen.org/ddi/

how-the-bitcoin-protocol-actually-works/, December 2013.

R. Poulsen. Four Things You Might Not Know about the

Black-Scholes Formula. 2007. Paper available athttp://papers.ssrn.com/sol3/papers.cfm?abstract_id=991344

([X3] of brainteasers).

http://en.wikipedia.org/wiki/File:

ReverseaccumulationAD.png

Dr. Matteo L. BEDINI Quantitative Finance IV: Informatics CUFE - 27 March 2015 32 / 32