You are on page 1of 112

Dynamic Asset

Pricing Theory
Pr. Eymen Errais
2023

1
© 2023 University of Tunis - Tunis Business
School
Table of Contents
Acknowledgment ........................................................................................................................ 4
Why this Book? And How Will It Benefit You? ........................................................................... 5
The Story of the village of Capitalis ..................................................................................................... 5
I. Introduction to Probability Theory ...................................................................................... 8
and Stochastic Processes ............................................................................................................ 8
Introduction......................................................................................................................................... 8
The Concepts of Certainty and Likelihood .......................................................................................... 8
What is Probability theory? ................................................................................................................. 8
Sample Space, Sigma-algebra (Sigma-field) and probability measures .............................................. 8
1. Sample Space........................................................................................................................... 9
2. Sigma-algebra (Sigma-field)................................................................................................... 10
3. Measurable space.................................................................................................................. 12
4. Probability measure .............................................................................................................. 12
5. Probability space ................................................................................................................... 13
Random variables and their properties............................................................................................. 14
1. Random variable.................................................................................................................... 16
2. Generated sigma-algebra ...................................................................................................... 18
3. Cumulative distribution ......................................................................................................... 19
4. Density function .................................................................................................................... 20
Stochastic processes, filtrations, and stopping times. ...................................................................... 22
How Can I Differentiate Between Randomness and Stochasticity? .................................................. 22
1. Stochastic processes.............................................................................................................. 23
2. Filtrations............................................................................................................................... 24
3. Stopping time ........................................................................................................................ 28
II. Conditional Expectation .................................................................................................... 32
Why Do You Need to Add a Condition When You Are Making a Prediction? ................................... 32
1. Conditional Probability .......................................................................................................... 34
2. Conditional Expectation ........................................................................................................ 35
3. Properties of Conditional Expectation .................................................................................. 38
4. Conditional Expectation and orthogonal projection. ............................................................ 38
III. Martingales.................................................................................................................... 40
1. Introduction ........................................................................................................................... 42
2. Martingale Properties ........................................................................................................... 42
3. Additional Exercises............................................................................................................... 47

2
IV. Brownian Motion........................................................................................................... 51
Introduction ................................................................................................................................... 52
V. Stochastic Calculus ........................................................................................................ 60
1. Ito Process ............................................................................................................................. 62
2. Quadratic variation................................................................................................................ 62
3. Itô’s Lemma ........................................................................................................................... 63
4. Quadratic covariation ............................................................................................................ 67
5. Multiplication theorem ......................................................................................................... 67
6. Itô Isometry ........................................................................................................................... 68
VI. Credit Risk Modeling ..................................................................................................... 71
1. Structural models .................................................................................................................. 71
2. Reduced form models ........................................................................................................... 74
VII. Interest rate Modeling .................................................................................................. 78
Short rate models .......................................................................................................................... 78
References ................................................................................................................................ 82
Appendix ................................................................................................................................... 85
I. Math Review ............................................................................................................................. 85
II. Introduction to R .................................................................................................................... 101
1. Working with Rstudio .......................................................................................................... 101
2. Working Directories:............................................................................................................ 102
3. Packages .............................................................................................................................. 103
4. Import data into R ............................................................................................................... 104
5. Manipulating Data ............................................................................................................... 107
6. Visualizing data .................................................................................................................... 110

3
Acknowledgment

This book emerged from my students' urgent need for a comprehensive guide to stochastic
calculus tailored for non-mathematics majors. Initially, it took shape from my lecture notes,
evolving significantly through invaluable inputs from my students and teaching assistants. I
extend my heartfelt gratitude to Iheb Dhaouadi, Taha Yacine Ayoub, Alae Amami, Mouna Turki,
Manar Labidi, Karim Razgallah, and Ons Harrabi for their contributions. Special appreciation is
due to Nour Causseini and Takwa Karoud for their exceptional roles. Nour's creative approach
made complex measure theory concepts accessible and engaging, weaving them into a fairy
tale narrative. Takwa's rigor and discipline were instrumental in developing an annex vital for
non-math students. Lastly, I must express my deepest thanks and love to my wife, Cyrine, for
her extraordinary patience during the countless nights spent completing this book.

4
Why this Book? And How Will It Benefit You?

The Story of the village of Capitalis

Once upon a time in the magical village of Capitalis,


there lived a clever, yet lazy boy named Investire1. In this
whimsical land, people traded their belongings every morning
at the center of the village and never kept their objects for
more than a day as they believed it brought bad luck. Investire
had a special giant apple tree from which he would pick an
apple, bite it, and then exchange it for a small book each day.
One fateful day, he overslept and couldn't find anyone to
trade with. Desperate to save face, he pretended nothing
happened and hatched a plan to exchange his apple a day
later. To his surprise, it worked, and he received two books
instead. Investire kept trying this trick, sometimes he
overslept for a night, for a week, or even a month, and
accumulated a library full of books as a result. And his trick
found success. But one day, it failed.

One night, Investire gazed at the twinkling stars and thought to himself, "Oh, if only
I could know the future value of my apples! I would know exactly when to go to the center of
Capitalis and when to stay in my orchard, snuggled in my cozy bed. That way, I could time my
apple sales perfectly for maximum profit and plan for my dream library!" But that wasn't the
only puzzle troubling Investire's curious mind. Among the stacks of books he collected, there
were some ancient spell books that held secrets to the value of knowledge. "What if I could
learn if these books become more valuable the longer, I keep them?" he wondered. "Then I
could exchange them for even rarer tomes and still enjoy the juicy apples from my orchard!"

Driven by his dreams of owning the most magnificent library, Investire set off on a
thrilling adventure to seek answers to his questions. He roamed through mystical forests,
consulted wise sages, and travelled to the far corners of Capitalis. His journey finally led him to
a hidden chamber within the town's ancient library. As he rummaged through a pile of dusty
old books, Investire stumbled upon an ancient spell book with a mysterious title: "Theoria
Pretiorum Res Mobilium Dynamica." Intrigued, he opened it and found the first page inscribed
with magical words: "May these lines be your guide to foresee the rhythm and motion of what
you own, just as you gaze upon the stars in their celestial path and see how they move and
where they go. With this wisdom, you shall navigate the stormy seas of Capitalis uncertainty,
avoiding the siren calls of risky ventures and steering towards the shores of prosperity." With
excitement coursing through his veins, Investire realized that this magical spell-book would
help him predict the future value of his precious apples. The tome was divided into chapters,

1
The origin of the word to invest “investire” in Latin.
5
each containing a legendary treasure map with missing parts that needed to be filled in. Little
did Investire know that this book held the key to a powerful spell.

Curious and excited, Investire discovered that


when he uttered the name of something he owned, who
owned it before him, the date, and other information, the
spell book would reveal the future value of his belongings
and guide him on the perfect time to journey to the center
of Capitalis. It was like having a crystal ball, but with
numerical insights!

Eager to share this magical knowledge with his


best friend Finis2., Investire invited him over to witness the
wonders of the spell book. Finis was amazed by the mystical
tome but urged Investire to check its accuracy. "How can we be sure this magic speaks the
truth?", Finis questioned. "You must put it to the test," he suggested. "Brilliant!" cried Investire.
And so, they devised a plan. Finis had secretly recorded the worth of Investire's apples over
time, and they decided to test the spell book’s powers. By shouting the values of apples from
100 days ago, 200 days ago, and even a decade ago, the spell book would reveal the apples'
current value. Each time, the spell book shimmered with light, confirming its accuracy.

With days passing by, Investire became the owner of the biggest library in Capitalis
and Finis the alchemist who transformed uncertainty into truth and was sought by kings and
queens from distant lands.

Takeaway Message:

We entered the world of Capitalis, where Investire, the apple trader, sought the appreciation
of the value of his apples before going to the center of the village! That’s Investing! Investire
dreamt of knowing the future worth of his apples, to time his investment just right, manage
risks, and craft the perfect hedging strategy. His wish came true with the spell book "Theoria
Pretiorum Res Mobilium Dynamica" – Dynamic Asset Pricing Theory (DAPT). Legends within,
like APT and CAPM, were passed down to you already, but the true marvels were the complex
legends of valuing other types of financial assets, that you are also familiar with, like
derivatives. These legends had missing parts that needed to be filled in. Indeed, these
mathematical models require variables to reveal asset value. Investire's friend, Finis was
intrigued and questioned the accuracy of DAPT. To test their accuracy, they delved into
Empirical Dynamic Asset Pricing, where models turned from myths to powerful tools. Who are
the kings and queens who sought Finis and wanted to know more about Dynamic Asset Pricing
Theory? It's you, yes indeed most of you, the future researchers, academics, economists willing
to help policy makers and central banks make sounder decisions, financial engineers,
quantitative analysts, financial risk managers, and investors. Remember, though DAPT is a
sophisticated area of finance that unveils the future price of assets. However, life happens, and

2
The origin of the word Finance in Latin Finis or the end, it referred to the settlement of debts.
6
probability is not certainty. Yet it is certainly worth being taught. That’s why it’s now time for
some probability theory and some stochastic processes.

7
I. Introduction to Probability Theory

and Stochastic Processes

Introduction

The Concepts of Certainty and Likelihood


It is obvious that the Finance world is not a magical village like Capitalis; although it is
as mesmerizing, in the real world, we cannot predict the exact future value of an asset with
certainty. In fact, the future of most financial investments is uncertain. We are unable to make
statements such as: “In T days our investment WILL be worth X dollars”. Instead, the uncertain
world is full of open questions such as: “What is the LIKELIHOOD that in T days, our investment
will be worth X dollars?”

What is Probability theory?


Probability Theory is the branch of mathematics that studies the likelihood of random
events and so provides us with the scientific approach we need to describe and analyze the
nature of financial investments. In this chapter we set up a toolbox of precisely the right
mixture of probabilistic concepts that we will need to make a start, as the story evolves, then
so too will this toolbox.

Sample Space, Sigma-algebra (Sigma-field) and probability

measures
Organizing the Library

Investire, the ultimate bookworm, now owns the grandest


library in Capitalis. His entire book collection is like a 'sample space,'
which means all the books he has. Every single book represents an
event. Now, think of 'sigma-algebra' as his super-organized system of
sorting books. He makes categories for everything: 'all my books,'
'fiction,' 'non-fiction,' 'biographies,' 'autobiographies,' 'Harry Potter,'
'Game of Thrones,' and so on. Sigma-algebra is the set of rules he
follows to keep his categories neat and tidy. What's fascinating is that
there's no single set of fixed rules; hence, there is no unique sigma
algebra.

8
A true bookworm, like a mathematician with sigma-algebra, can come up with
countless creative ways to sort their books and keep things super organized. However, there is
a limit to the number of categories he can create; defined by the cardinality of his library, which
is the number of books he possesses. Interestingly, Investire realized that no matter how hard
he tried to invent new ways to categorize his books, his record was always 2 raised to the
power of the cardinality.

Investire came with so many ways of categorizing his books, and although he hates to admit
it, he sometimes forgets how to navigate his library. That’s why for every categorization
method, that is for every sigma algebra, he created a navigation map to help him make sense
of all his books (sample space) and how he organized them (sigma algebra) and that he calls
his measurable space.

Investire loves to read, however he has always been indecisive about what to read. This led
him to ask his friend Finis to pick up a book for him every day. The moment Finis enters
Investire’s Library he feels like he is in a Playground of Randomness. He wanders in the library
(sample space), through the shelves where Investire organized his books into different
categories following his set of rules (sigma-algebra) and should choose a book for Investire
while enjoying seeing him so nervous. Indeed, every night, Investire was eagerly awaiting the
next day’s literary adventure. So, he decided to consult his spell book, again, to predict the next
tome he will be reading. The spell book instructed “Take your navigation map and to each book
featuring on the map, close your eyes and assign a number from 0 to 1; You shall find yourself
in an uncertain space that will diminish your uncertainty and Finis’s Playground of Randomness
will be less perplexing. The next step will be revealed in the next page”. In simpler terms this
means that Investire takes his measurable space, and to each event within it (represented by
books) he randomly assigns a number from 0 to 1. This number will quantify the likelihood of
each event occurring; by doing so Investire creates his probability measure and Finis’
Playground of Randomness, which is the Probability Space that takes into consideration the
sample space, the sigma algebra, and the probability measure Investire created and defined on
his measurable space, will be more understandable. And the next step to execute will be
discovered in the next part of this chapter.

1. Sample Space

An experiment is any procedure that can be infinitely repeated and has a well-defined set of
possible outcomes3.

The set of all possible outcomes of an experiment is called the sample space.

Definition: A sample space, 𝛺 = {𝜔𝑖 : 𝑖 ∈ 𝐼} is the set of all possible results of a random
experiment. I being a set of indices.

Any subset A of the sample space is known as an event with A ⊆ Ω.

Example 1.1: Suppose our random experience is rolling a dice.

3
Events
9
The sample space is: Ω = {1,2,3,4,5,6} There are 6 possible outcomes: Numbers from 1, to 6.

Example 1.2: Suppose our random experience is rolling a dice and getting either odd or even.

The sample space is: Ω = {{1,3,5}, {2,4,6}} There are 2 possible outcomes: the odd and the
even numbers.

Example 1.3: Suppose our random experience is to take a stock randomly from the list of stocks
in the Tunis Stock Exchange.

The sample space is: Ω = {Adwya , Aetech, ⋯ , UBCI, UIB }. There are around 82 possible
outcomes: the number of stocks of all listed companies in Tunisia.

Example 1.4: Suppose our random experience is throwing a coin two times.

The sample space is: Ω = {{TT}, {TH} ,{HH} ,{HT}}

Example 1.5: Suppose our random experience is picking a student randomly.

Ω = {Boy , Girl}

How big can 𝛀 get?


2|Ω| is the set of all possible subsets of Ω

Where did we get this from?

Every subset of Ω has the possibility to be picked or not, and |Ω| denotes the cardinality4
(number of elements) of the sample space Ω which means that the possible number of subsets
are 𝟐|𝛀| .

2. Sigma-algebra (Sigma-field)

Definition: A sigma-algebra F ⊆ 2Ω 5 is a subset of events


such as: Everything is in F
i. 𝛺∈F
ii. If 𝐴 ∈ F, then 𝐴𝑐 ∈ F Closed under
Where 𝐴𝑐 is the complementary of A in Ω. complementation.
F is closed under complementation.6
iii. If 𝐴𝑖 ∈ F ∀ I ∈ I, then ⋃𝑖 𝐴𝑖 ∈ F Closed under Union
F is closed under countable union.7

There is no one sigma-algebra per sample space.

Example 2.1: Ω = {𝛼, 𝛽, 𝛾}, then the power set of Ω has 23 = 8 elements, which are:

4
Cardinality = ‘How many elements are there’? In example (1.1) cardinality is 6, in example (1.2) it’s 2.
5
Sigma algebra F is a subset of the set containing all possible subsets of the sample space 𝛺
6
‘Closed under complementation’ means F is comprehensive; it contains a thing and its opposite.
7
‘Closed under union’ means that the union (combination) of any sets that exist in F, will be found in F
too.
10
{}8, {𝛼}, {𝛽}, {𝛾}, {𝛼, 𝛽}, {𝛼, 𝛾}, {𝛽, 𝛾}, {𝛼, 𝛽, 𝛾}

A σ-algebra on Ω can contain any subset of these 8 elements, as long as it satisfies the above
properties of a σ-algebra. The 3 following sigma-algebras are all σ-algebras on Ω:

ℱ1 = {∅, Ω, {𝛼}, ℱ2 = {∅, Ω, {𝛼, ℱ3 = {∅, Ω, {𝛼}, {𝛽}, {𝛾}, {𝛼, 𝛽}, {𝛼, 𝛾}, {𝛽, 𝛾}, {𝛼,
{𝛽, 𝛾}} 𝛽}, {𝛾}} 𝛽, 𝛾}}
The smallest sigma-algebra9 and the trivial sigma-algebra

Example 2.2: What is the smallest sigma-algebra that we can get?

{∅, 𝛺} It is called the trivial sigma-algebra.

Example 2.3: What is the smallest sigma-algebra that contains A?

{∅, 𝐴, 𝐴𝑐 , 𝛺}

Example 2.4: What is the smallest sigma-algebra containing {1} ?

Example 2.5: What is the sigma-algebra of throwing a dice and getting either odd or even?

F= {∅, 𝛺, {1,3,5}, {2,4,6}}

Example 2.6: What is the sigma-algebra of throwing a dice and getting lesser or higher than 3?

F= {∅, 𝛺, {1,2,3}, {4,5,6}}

Example 2.7: What is the sigma-algebra of throwing a dice and getting a 6?

F= {∅, 𝛺, {1,2,3,4,5}, {6}}

Example 2.8: What is the sigma-algebra of throwing a dice and getting a 6 or a 1?

F= {∅, 𝛺, {1}, {2,3,4,5,6}, {1,2,3,4,5}, {6}, {1,6}, {2,3,4,5}}

Example 2.9: What is the sigma-algebra of throwing a dice and betting $4000 on 4 and $6000
on 5?

H= {∅, 𝛺, {4}, {1,2,3,5,6}, {1,2,3,4,6}, {5}, {4,5}, {1,2,3,6}}

Example 2.10: Suppose that A = {Historical Prices}, B = {Public information}, C = {Private


information} = 𝐵𝑐 . Give the sigma-algebra of the 3 different forms of market efficiency.

The sigma-algebra of the weak form efficiency: F= {∅, 𝛺, 𝐴, 𝐴𝑐 }

The sigma-algebra of the semi-strong form efficiency: F= {∅, 𝛺, 𝐵, 𝐵𝑐 }

The sigma-algebra of the strong form efficiency: F= {∅, 𝛺, 𝐵, 𝐵𝑐 , {𝐵} ∪ {𝐵𝑐 }}

Example 2.11: Show that if A, B ∈ F then 𝐴 ∩ 𝐵 ∈ F

8
The empty set
9
Usually when we ask for the sigma-algebra, we are asking for the smallest one.
11
If A, B ∈ F, then 𝐴𝑐 and 𝐵𝑐 ∈ F which means (𝐴𝑐 ∪ 𝐵𝑐 ) ∈ F, implying (𝐴𝑐 ∪ 𝐵𝑐 )𝑐 ∈ F. And finally,
this leads to: 𝐴 ∩ 𝐵 ∈ F.

3. Measurable space

Definition: A measurable space is the space defined by the couple (𝛺 , F ) where 𝛺 is the sample
space and F is the sigma-algebra defined on 𝛺.

σ-algebra is a collection of measurable subsets (we can assign probabilities to the subsets).

Example 3.1: Let 𝛺 be the sample space of all listed companies, and let F be the smallest
sigma-algebra containing all the public information of all listed leasing companies.

Let’s Recap

The sample space Ω is the set of all possible outcomes of an experiment. It contains all the
possible results that could occur when we perform the experiment.

The sigma algebra F is a collection of subsets of the sample space that we consider to be
measurable or observable. We choose the sigma algebra to be a collection of subsets that
are relevant to our analysis and satisfy the three conditions.

By defining a sigma algebra, we can narrow our focus to a smaller collection of subsets to
have efficient analysis and more control over data.

The measurable space, the combination of the sample space and the sigma-algebra, then
comes in handy to provide a foundational structure for defining probabilities by defining the
scope of events for which we can assign probabilities (from 0 to 1). On the measurable space,
we will define our Probability measure P.

4. Probability measure

Definition: Let (𝛺 , F ) be a measurable space, a probability measure P is a function


(F ⟶ [0 , 1])10 such that:

i. P(𝛺) = 1 (One of the possible outcomes must occur).


ii. 0 ≤ P(𝐴) ≤ 1 ∀ 𝐴 ∈ F
iii. ∀ 𝐴𝑖 , 𝐴𝑗 ∈ F such that 𝐴𝑖 ∩𝐴𝑗 =∅ for 𝑖, 𝑗 ∈ 𝐼, P(𝐴𝑖 ∪ 𝐴𝑗 ) = P(𝐴𝑖 ) +P(𝐴𝑗 )

For any two disjoint subsets 𝐴𝑖 and 𝐴𝑗 in the sigma-algebra F, the probability of their
union is equal to the sum of their individual probabilities.

This allows us to break down complex events into simpler, disjoint events, and then
add up their probabilities to calculate the probability of the complex event.

10
This is read as « F maps to [0,1], i.e., for any subset in sigma algebra P assigns it to a value within [0,1]
12
Example 4.1: Let rolling the dice be a random experience. If the dice is fair, every event has the
same chance of occurrence. What is it? It is 1/6.

Why is the third condition of disjoint subsets useful?

Example 4.2: Suppose we want to calculate the probability of rolling a six-sided die and getting
1, 2, or 3. We can break this event down into the disjoint events of rolling and getting 1, rolling
and getting 2, rolling and getting 3, and then we calculate the probability of their union:

P(rolling and getting 1, 2, or 3) = P(rolling and getting 1) + P(rolling and getting 2) + P(rolling and
getting 3)

= 1/6 + 1/6 + 1/6 = 3/6 = 1/2

Example 4.3: Show that for any A ∈ F, 𝑃(𝐴𝑐 )= 1 - P(𝐴)

We know that 𝐴 ∪ 𝐴𝑐 =Ω and P(𝛺) = 1 then P(𝐴 ∪ 𝐴𝑐 ) = 1. Since 𝐴∩𝐴𝑐=∅ then


𝑃(𝐴𝑐 )= 1 - P(𝐴)

Example 4.4: Show that for any events A and B ∈ F, 𝑃(𝐴 ∪ 𝐵)=P(𝐴)+P(𝐵)-P(𝐴 ∩ 𝐵).

(𝐴 ∪ 𝐵) can be written as the union of three disjoint sets:

𝐴 ∪ 𝐵=(𝐴 ∩ 𝐵𝑐 ) ∪ (𝐴𝑐 ∩ 𝐵) ∪ (𝐴 ∩ 𝐵). So that,

𝑃(𝐴 ∪ 𝐵)=P(𝐴 ∩ 𝐵𝑐 ) + P(𝐴𝑐 ∩ 𝐵) + P(𝐴 ∩ 𝐵). (**)

Moreover, one has that A and B can be written as union of the following disjoint sets:

𝐴 = (𝐴 ∩ 𝐵𝑐 ) ∪ (𝐴 ∩ 𝐵)

𝐵 = (𝐴𝑐 ∩ 𝐵) ∪ (𝐴 ∩ 𝐵) Which means that,

𝑃(𝐴) =P(𝐴 ∩ 𝐵𝑐 ) + P(𝐴 ∩ 𝐵)

𝑃(𝐵)= P(𝐴𝑐 ∩ 𝐵) + P(𝐴 ∩ 𝐵) And,

P(𝐴 ∩ 𝐵𝑐 )=𝑃(𝐴) − P(𝐴 ∩ 𝐵)

P(𝐴𝑐 ∩ 𝐵)= 𝑃(𝐵) − P(𝐴 ∩ 𝐵)

Replacing these equations in (**) concludes the proof.

5. Probability space

Definition: We call a probability space the triplet (Ω , F, P ) composed of the sample space 𝛺,
the sigma-algebra F, and the probability measure P, defined on the measurable space (𝛺 , F ).

A probability space is a mathematical construction that consists of a triplet: a sample space Ω,


a collection of events ℱ, and a probability measure ℙ.

The measurable space (Ω, ℱ) is the background structure that is needed to assign probabilities
using P function to measurable events.

13
Example 5.1: Let there be the probability space (Ω , F , P ) And G = {∅, 𝛺, {4,5}, {1,2,3,6}}

𝑃({4,5}) : The probability is not defined.

Random variables and their properties

[…] At nighttime, Investire couldn’t sleep and kept repeating to himself


the cryptic message he received. It said: “Take your navigation map and to
each book featuring on the map, close your eyes and assign a number from 0
to 1; You shall find yourself in an uncertain space that will diminish your
uncertainty and Finis’s Playground of Randomness will be less perplexing.”
“How can I do this?” He wondered aloud. “Where and to what should I assign
the numbers? It feels as if I am lost in a world within a vast universe, and I
need to be on another side of the world but couldn’t find the bridge to lead
me there!” … He paused, gazing at the ceiling, then it struck him like a lightning bolt “A bridge!
That is exactly what I need!” He exclaimed “A bridge to connect the world of books to the world
of numbers. But alas, in Capitalis, we have no bridges! Where am I supposed to find such one?”.

At the break of dawn, Investire sprang from his bed and


rushed to his library where he kept his spell book "Theoria
Pretiorum Res Mobilium Dynamica". As he opened it, he leaned
in close and whispered with great reverence “Oh dear book! Your
faithful reader found himself once more lost in the Playground of
Randomness. Will you be my guiding light, showing me the way
to the bridge that leads to the realm of numbers? I yearn to
discover this path and bring some boxes for my books.”

At first the book remained silent, its pages still unmoving. Investire’s
heart sank, but then, as if enchanted by his plea the pages came to life with
shining letters “Go to the village of Probare11”. And so Investire followed the
rules.

11
The word from which “Probabilitas” (the origin of Probability) is derived. Probare means in Latin “to
test” or “to prove”.
14
As Investire drew closer to the village of Probare, a buzzing sound filled the air around
him. It echoed in his ears “We know not your books nor your spell; Speak our language and in
magic you’ll dwell. We map your books to our dictionary’s embrace, speak our language, unlock
the secrets of this place” … And he kept moving forward.

When he finally arrived at the village’s entrance, he spotted


an elderly lady holding a book. He sensed that she too, was on a
quest akin to his own. The old lady approached him and with a
trembling sound she said:” Oh my brave boy, I
understand what has brought you to Probare_ a
quest to conquer your uncertainty. My boy, it’s a
long journey you just embarked on. Remember
my words well: Take an empty box, cross the bridge, and follow the arrow,
and don’t look back. As you walk the box will grow heavier, filling with
books. When you reach the other side, the bridge leads you to, do not
merely abandon it; Open the box and check whether the books within
match the organization of your own library. If they do not, your steps were
in error, and you have been deceived. Don’t forget my child, that even the
tiniest categorization the bridges generated in the boxes, if it matches what you have, it is
correct.”

The brave boy heeded the old lady’s sage advice. He reached the bridge, and just as she
foretold, he selected one empty box from the pile and crossed the bridge following the arrow,
and not looking back… And just like that the bridge mapped his books to the numbers
Probare’s people could understand.

With the boxes in his hands, Investire didn’t know what to do next, so he began to make his
way to the village’s exit, yearning to return to his trusty spell book. But as he approached the
exit door, it remained shut bearing a message that read “You shall not depart unless you
demonstrate your understanding of the value of these boxes gifted by our bridge.”. “What do
you want from me?” Investire shouted at the door; “Give these boxes back their veil of
uncertainty but quantify it. Show us the likelihood of your friend choosing books akin to ours.
Then upon the sandy ground illustrate your words.”.

Investire recalled the moment when his spell book had instructed him “[…] to each book
featuring on the map, assign a number from 0 to 1…”. He devised a clever plan: he took the
boxes put a veil on them and thought he fooled the door by saying “I predict that Finis will
choose a book like the one in this box, and that likelihood shall be 0.5”; Repeating this for each
box he intended to take home. Little did he know he provided the correct response; The door
had sought what was called in Probare the CDF. To illustrate his point, as asked from him, he
noticed to his right a large bell nearby, and with a stick he traced a bell-shaped curve in the
sand, confidently exclaiming, “This is what I mean!”. Regardless of how accurate Investire’s
answers were, he gave what seemed to be the correct responses. With that the door swung
open, granting Investire his freedom once more.
15
Takeaway message: The probability world doesn’t know the events or your outcomes of
interest, it doesn’t speak your language. You need to speak the language of this world _Village
of Probare_, that is speak in numbers rather than words and in the names, you gave the sets in
your sigma algebra. To do so you need to resort to the bridge _Random variables_. Random
variables are functions but serve as a bridge linking the real world to the world of mathematical
models. Let’s call our bridge X. Just like the bridge in Investire’s story, Random variables will
map elements from your sample space to the set of real numbers, as you follow the arrow (𝑋 ∶
𝛺 ⟶ R). A function, X(x), is a relevant random variable for you if and only if the books in the
box (or the set between the brackets) also exists in your sigma-algebra; that is the random
variable X is measurable on your sigma algebra F. Any bridge, or random variable, is
measurable for a certain sigma algebra, which is the generated-sigma-algebra for that random
variable; It is the categorization the bridge generated.

At this point, although the data became understandable and Investire felt less lost in the
Playground of Randomness _Probability Space_, it is still not meaningful. The veil of
uncertainty Investire put back was the Probability measure of that random variable P(X<=x)
the RV takes on a value less than or equal to a specified value x (0.5 Investire assigned). This
veil along with the box make up a function F(X) which is the Cumulative Distribution Function,
CDF12. When Investire was asked to illustrate what he said, he was asked to provide information
about the distribution of the probabilities for different values of the RV, and this curve is called
the PDF13 and is given by the function f(x) which is nothing but the derivative of the CDF.

1. Random variable

Definition: A random variable that is defined on the measurable space (𝛺 , F ) is a real


function 𝑋 ∶ 𝛺 ⟶ R 14 such that
∀ 𝑥 ∈ ℝ, {𝜛 ∈ Ω / 𝑋(𝜔) ≤ 𝑥} ∈ F 15

If 𝐶𝑎𝑟𝑑(Ω) < ∞ (finite space) then the last condition becomes


∀ 𝑥 ∈ ℝ, {𝜛 ∈ Ω / 𝑋(𝜔) = 𝑥} ∈ F

A random variable is a real function X∶ Ω⟶ R defined on a measurable space (Ω, ℱ).

X is a function that maps an event from the sample space Ω to a value and it is measurable with
respect to the sigma-algebra. X assigns a real number to each outcome ω in the sample space.

Condition: ∀ x ∈ R, {ω∈ Ω / X (ω)≤x} ∈ ℱ

12
Use the CDF to determine the probability that a random observation that is taken from the population
will be less than or equal to a certain value.
13
used to define the random variable's probability coming within a distinct range of values, as opposed to
taking on any one value.
14
You read this: X is a function that maps elements from the sample space Ω to the set of real numbers

15
You read this: For all x in the set of real numbers, the set of 𝜛 in Ω such that x(𝜛) is less than or equal
to x belongs to the sigma-algebra F
16
For any real number x, the set of outcomes in the sample space Ω for which X(ω) is less than or
equal to x is an event in the sigma-algebra ℱ. This condition is equivalent to saying that X is
measurable with respect to the sigma-algebra ℱ.

Checking for Random Variables

Example 1.1:

Consider the following experiment: flipping a fair coin twice. The sample space is Ω = {HH, HT,
TH, TT}, where HH represents two heads, HT represents a head followed by a tail, and so on.

Let F be the sigma-algebra generated by the events {HH}, {HT, TH}, and {TT}. That is, ℱ = {∅, Ω,
{HH}, {HT, TH}, {TT}, {HH, HT, TH}, {HT, TH, TT} }.

Let X be the random variable that counts the number of heads obtained when flipping the coin
twice. That is, X(HH) = 2, X(HT) = X(TH) = 1, and X(TT) = 0.

To check if X is ℱ-measurable, we need to check if {ω ∈ Ω : X(ω) ≤ x} is in ℱ for any real number


x.

If x = 0, then {ω ∈ Ω : X(ω) ≤ 0} = {TT} ∈ ℱ, since X(TT) = 0.

If x = 1, then {ω ∈ Ω : X(ω) ≤ 1} = {HT, TH, TT} ∈ ℱ, since X(HT) = X(TH) =1, X(TT) = 0.

If x = 2, then {ω ∈ Ω : X(ω) ≤ 2} = Ω ∈ ℱ, since X(HH) = 2, X(HT) = X(TH) = 1, and X(TT) = 0.

Therefore, X is ℱ-measurable, since {ω ∈ Ω : X(ω) ≤ x} ∈ ℱ for any real number x.

Example1.2: G = {∅, 𝛺, {1}, {2,3,4,5,6}}

1 𝑖𝑓 𝜔 ∈ {6}
𝑋(𝜔) = {
0 𝑖𝑓 𝜔 ∈ {1,2,3,4,5}

Is X a random variable?

{𝜔 ∈ Ω ∶ 𝑋(𝜔) = 1} = {6 } ∉ 𝐺

X is not a random variable.

Example: F= {∅, 𝛺, {5}, {1,2,3,4,6}}

1 𝑖𝑓 𝜔 ∈ {5}
𝑌(𝜔) = {
0 𝑖𝑓 𝜔 ∈ {1,2,3,4,6}

Is Y a random variable?

{𝜔 ∈ Ω ∶ 𝑌(𝜔) = 1} = {5 } ∈ 𝐹

{𝜔 ∈ Ω ∶ 𝑌(𝜔) = 0} = {1,2,3,4,6} ∈ 𝐹

Y is a random variable.

17
2. Generated sigma-algebra

Definition: Let X be a real function defined on 𝛺. The smallest sigma-algebra F that allows X
to become a random variable on the measurable space (𝛺 , F ) is called sigma-algebra
generated by X. We note it: F = 𝜎(𝑋)

Example 2.1: Let the random experience be rolling a fair dice. Let X be the function that gives
1 if the outcome is even and 0 otherwise.

1 si 𝜔 ∈ {2,4,6}
𝑋(𝜛) = {
0 si 𝜔 ∈ {1,3,5}

What is the sigma-algebra generated by X?

F = {∅, {2,4,6}, {1,3,5}, Ω}

Example 2.2: Let the random experience be rolling a fair dice. Let Y be the function that give 1
if the outcome is higher or equal than 4 and 0 otherwise.

Is Y a random variable under the measurable space (𝛺 , F ) defined in the previous example ?

Since

1 𝑠𝑖 ϖ ∈ {4,5,6} ∉ F
𝑌(𝜛) = {
0 𝑠𝑖 ϖ ∈ {1,2,3} ∉ F

Then Y is not a random variable under (𝛺 , F ).

What is the smallest sigma-algebra G such that Y is a random variable under (𝛺 , G )

G = {∅, {1,2,3}, {4,5,6}, Ω}

Example 2.3: Let the random experience be rolling a fair dice. Let Z be the function that gives
1 if the outcome is 6 or 1 and 0 otherwise.

1 𝑠𝑖 ϖ ∈ {1,6}
𝑍(𝜛) = {
0 𝑠𝑖 ϖ ∈ {2,3,4,5}

What is the sigma-algebra generated by Z ?

Z = {∅, {1,6}, {2,3,4,5}, Ω}

18
Example 2.4:

Consider the following sample space Ω and function X: Ω ⟶ ℝ.

X |X| Y
ω1 0 0 0
ω2 0 0 0
-
ω3 1 0
1
ω4 1 1 1
ω5 1 1 1
ω6 2 2 1
-
ω7 2 2
2

a) What is the smallest σ-algebra ℱ such that X is a random variable?


ℱ = σ ({1,2}, {3}, {4,5}, {6}, {7})
b) What is the smallest σ-algebra 𝒢 such that |X| is a random variable?
𝒢 = σ ({1,2}, {3,4,5}, {6,7}) = σ (∅, {ω1, ω2}, {ω3, ω4, ω5}, {ω6, ω7}, {ω3, ω4, ω5, ω6, ω7}, {ω1, ω2,
ω6, ω7}, {ω1, ω2, ω3, ω4, ω5}, Ω)
c) Is a |X| a ℱ –random variable? Justify your answer.
∀ 𝑥 ∈ ℜ, {𝜛 ∈ Ω / 𝑋(𝜔) = 𝑥} ∈ F
True, |X| is a ℱ –random variable because ℱ includes all ranges of π:

|X|(π) = {0 if π ∈ {1,2} ∈ ℱ; 1 if π ∈ {3,4,5} ∈ ℱ; 2 if π ∈ {6,7} ∈ ℱ}


d) Is a X a 𝒢–random variable? Justify your answer.
False, X is not a 𝒢–random variable because {3}, {4,5}, {6}, {7} are not included in 𝒢.
X(π) = {0 if π ∈ {1,2} ∈ 𝒢;
-1 if π ∈ {3} ∉ 𝒢;
1 if π ∈ {4,5} ∉ 𝒢;
2 if π ∈ {6} ∉ 𝒢;
-2 if π ∈ {7} ∉ 𝒢 }

3. Cumulative distribution

Definition: Let X be a random variable under the probability space (Ω , F , P ). X is


defined by the cumulative distribution as follows:
𝐹𝑋 ∶ ℜ ⟶ [0 , 1]
𝑥 ⟼ 𝐹𝑋 (𝑥) = 𝑃{𝜔 ∈ 𝛺 / X(𝜔) ≤ 𝑥}

19
4. Density function

Definition: in a finite space, the distribution of a random variable X defined under a


probability space (Ω , F , P ), is determined by its density function :
𝑓𝑋 ∶ ℜ ⟶ [0 , 1]
𝑥 ⟼ 𝑓𝑋 (𝑥) = 𝑃{𝜔 ∈ 𝛺 / X(𝜔) = 𝑥}

Example: Let X be a random variable following a Binomial distribution 𝐵(𝑛, 𝑝) where 𝑛 ∈


{0,1,2, … }

And 𝑝 ∈ (0,1). The density of X is given by:


𝑛
𝑓𝑋 (𝑘) = ( ) 𝑝𝑘 (1 − 𝑝)𝑛−𝑘 𝑘 = 0,1, … , 𝑛
𝑘

Example: The Poisson distribution 𝑃(𝜆) with 𝜆 > 0

𝜆𝑘
𝑓𝑋 (𝑘) = 𝑒 −𝜆 𝑘 = 0,1,2, …
𝑘!

Python Time !

Exploring Sample Space: Building Sigma-Algebras and Calculating


Probability Measures:
Delve into the world of probabilities with our interactive example using Python! We
aim to introduce you to the concepts of Sample Space, Sigma-Algebra (Sigma-Field),
and Probability Measures in a straightforward way. By entering your chosen outcomes,
you'll witness how we construct a Sigma-Algebra that includes your event and its
complement, and then calculate the probability of your specified event. Whether
you're new to probability or seeking a refresher, this exercise provides a hands-on
opportunity to grasp these fundamental concepts with the roll of a virtual die.

20
from sympy import FiniteSet

# Define the sample space for a single dice roll


sample_space = FiniteSet(1, 2, 3, 4, 5, 6)

# Ask the user for the event they are interested in


# For example, the user might input "2, 3" for the event {2,3}
user_input = input("Enter the outcomes of the event separated by
commas (e.g., 2, 3): ")
event_outcomes = [int(outcome.strip()) for outcome in
user_input.split(',')]
specified_event = FiniteSet(*event_outcomes)

# Calculate the complement of the specified event with respect to


the sample space
complement_event = sample_space - specified_event

# The sigma algebra for the specified event includes:


# - the empty set
# - the event itself
# - the complement of the event
# - the entire sample space
sigma_algebra = [FiniteSet(), specified_event, complement_event,
sample_space]

# Define a probability measure function


def probability_of_event(event, sample_space):
return len(event) / len(sample_space)

# Calculate the probability of the specified event


probability_specified_event = probability_of_event(specified_event,
sample_space)

# Display the sigma algebra for the specified event


print("Sigma Algebra for the specified event:", sigma_algebra)

# Display the specified event and its probability


print(f"Probability of the specified event {specified_event}:
{probability_specified_event}\n")

21
Stochastic processes, filtrations, and stopping times.

How Can I Differentiate Between Randomness and Stochasticity?


The distinction between "Random Experiment" and "Stochastic Process" boils down to a
simple question: "Is it a one-time thing?"

Think of a random experiment like a single test you take, such as your driver's license test.
It's a one-time event, and you can't predict the outcome in advance.

Now, envision a stochastic process as a series of events that evolves over time, much like
your favorite TV show. In shows like "Choufli Hal," there are many episodes, and you never
quite know what will happen in the next one (at least if you’re watching it for the first time and
didn’t obsess over it already). A stochastic process involves a collection of random variables
that change and evolve over time, creating a dynamic story.

The Thread of Knowledge

After his successful venture through the village of


Probare and the mysterious encounters with the Door and
the Bridge, Investire returned to the familiar halls of Capitalis
exhausted. When he arrived, Finis greeted him with a
cheerful smile and a book in hand; "Investire, this is today's
Tome, it’s the story of Theseus and the Minotaur" Finis
exclaimed, extending the book towards his friend. "Enjoy
your reading, and I'll see you tomorrow!".

Investire, feeling the weight of his recent explorations,


decided to take a break from unraveling the secrets of the Playground of Randomness and
predicting his next reading adventure. Instead, he chose to immerse himself in the captivating
pages of the Tome. Little did he know that his curious brain wouldn’t let him rest.

Investire opened the Tome and began to read. He quickly noticed that not only he ignored
the next book he would be reading, but he also ignored what the next chapter of the tome he
was reading would be telling him: Like the books in his library, chapters are also events in the
Tome, just like the library the book is also a sample space, and just like he organized his library
into categories of books, the author organized the chapters into sets and that represented a
sigma-algebra.

The only difference is that as he continued to read, the chapters’ outcome differed, while
the books didn’t; That is, Finis picked a book once, it’s a one-time thing, however the reading
process, evolved over time: The reading process was dynamic, picking a book was not! So, it is
not exactly a sigma-algebra.

22
Investire noticed another difference: as he discovered what each chapter hid, he
discovered a new organization of the story unveiled to him by the author, but this doesn’t mean
he forgot the previous story in the previous chapter. That is as he read each page, discovered
each event, and finished each chapter he gained more information about the story without
ever losing the past information; Investire was accumulating knowledge over time, as the
reading process continued. Just as he uncovered the plots of the story through the book’s
pages, a gradual accumulation of information about the story unfolded. Investire paused his
reading to reflect on what he had noticed and to take a break.

Takeaway message: Investire had uncovered the enchanting world of stochastic processes,
filtrations, and stopping times through the pages of the Tome. He realized that, just as reading
a book was a process that evolved over time while concealing some future information, every
process with uncertain outcomes that evolves over time (or space or any other index) was a
stochastic process.

Chapters in a book were like events in this process, and the information he gathered while
reading represented filtrations. (You can also think of Filtrations like sigma-algebras for random
experiments).

The moment when Investire paused reading his book is called a stopping time. Stopping times
are those moments or specific points in time when you pause to assess the events that have
occurred up to that moment. It’s as if you’re deciding when to reflect on the story’s progress
and what might happen next. So, what might happen next with Investire?

But before we proceed, let’s recall this piece of information: Despite its randomness, a
stochastic process can follow a specific pattern that we may notice. This pattern helps us
recognize what kind of stochastic process we are dealing with (categorize the process) and thus
approximate the future outcome. In summary, “stochastic process” serves as the broad term
under which we find specific types of stochastic processes that we will explore later.

1. Stochastic processes

Definition: A stochastic process 𝑋 = {𝑋𝑡 ∶ 𝑡 ∈ T} defined on the measurable space (Ω , F ) is a


set of random variables {𝑋𝑡 ∶ 𝑡 ∈ T} constructed on (Ω , F ) where T is a predefined index.

Example: daily temperature, stock price, inflation, interest rates

Python Time !

Python's Random Walk: A Stroll Through Stochastic Processes


The Python code simulates a random walk, a simple example of a stochastic process. It
generates a sequence of random steps (+1 or -1) for a specified number of steps and calculates
the cumulative sum, resulting in the random walk path. The matplotlib library is used to
visualize the path. The outcome demonstrates the inherent unpredictability of stochastic
processes, as each run produces a unique path, illustrating the randomness characteristic of
such processes.

23
import numpy as np
import matplotlib.pyplot as plt

def random_walk(num_steps) :
# Generate random steps (+1 or -1) for the given number of steps
steps = np.random.choice ( [-1, 1], size = num_steps )

# Calculate the cumulative sum to get the random walk path


path = np.cumsum ( steps )

return path

# Number of steps in the random walk


num_steps = 100

# Simulate a random walk


random_walk_path = random_walk ( num_steps )

# Plot the random walk


plt.plot ( random_walk_path )
plt.title ( "Random Walk Simulation" )
plt.xlabel ( "Step" )
plt.ylabel ( "Position" )
plt.show ()

2. Filtrations

Definition: We call filtration 𝔽 = {Ft ∶ t ∈ T} the set of non-decreasing sigma-algebras on the


measurable space (Ω , F ) such that :
• ∀𝑡 ∈ 𝑇, Ft ⊆ F
• ∀ 𝑡 ≤ 𝑠 ∈ 𝑇, Ft ⊆ F𝑠

Definition: The filtration 𝔽 = {Ft ∶ t ∈ T} is generated by the stochastic process 𝑋 =


{𝑋𝑡 ∶ 𝑡 ∈ T} if :
∀𝑡 ∈ 𝑇, F𝑡 = 𝜎(𝑋𝑠 ∶ 𝑠 ≤ 𝑡 ∈ T)

Example 2.1: Suppose you would like to model the WTI price through a stochastic process X.
The monthly price of WTI is given by this table:

W X0(w) X1(w) X2(w) X3(w)


w1 60 70 75 70
w2 60 70 70 70
w3 60 60 70 55
w4 60 55 60 55

24
Find the filtration 𝔽 = {Ft ∶ 𝑡 ∈ 𝑇} generated by the stochastic process 𝑋 = {𝑋𝑡 ∶ 𝑡 ∈ T} ?

F0 = {∅, Ω}

F1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 }, {𝜔4 })

F2 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

F3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

Example 2.2: Suppose you would like to model the GME price through a stochastic process Y.
The monthly price of GME is given by this table:

W Y0(w) Y1(w) Y2(w) Y3(w)


w1 130 150 160 220
w2 130 150 160 200
w3 130 150 130 200
w4 130 120 130 200

Find the filtration 𝐺 = {Gt ∶ 𝑡 ∈ 𝑇} generated by the stochastic process 𝑌 = {𝑌𝑡 ∶ 𝑡 ∈ T} ?

G 0 = {∅, Ω}

G 1 = 𝜎({𝜔1 , 𝜔2 , 𝜔3 }, 𝜔4 })

G 2 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 }, {𝜔4 })

G3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

Example 2.3: Suppose you would like to model the SFBT price through a stochastic process V.
The monthly price of GME is given by this table:

W V0(w) V1(w) V2(w) V3(w)


w1 1 2 3 3
w2 1 2 2 3
w3 1 1 2 3
w4 1 1 1 1

Find the filtration Z = {Z t ∶ 𝑡 ∈ 𝑇} generated by the stochastic process 𝑉 = {𝑉𝑡 ∶ 𝑡 ∈ T} ?

Z 0 = {∅, Ω}

Z 1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 , 𝜔4 })

25
Z = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })
2

Z3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

Python Time !

Automated Filtrations with Python: Will try to do the WTI price previously seen
example with python:

import pandas as pd
import itertools

# Define the stochastic process as a dictionary


# This dictionary would typically be generated by parsing a file or
input
stochastic_process = {
'w1' : [60, 70, 75, 70],
'w2' : [60, 70, 70, 70],
'w3' : [60, 60, 70, 55],
'w4' : [60, 55, 60, 55]}

# Convert the dictionary to a pandas DataFrame for easier manipulation


df = pd.DataFrame.from_dict ( stochastic_process, orient = 'index',
columns = ['X0', 'X1', 'X2', 'X3'] )

# Correctly implementing the filtration generation as per the


instructions
def generate_filtrations(df):
# Initialize the list of filtrations with an empty set for F0
filtrations = [set()]

# Generate the filtration for F1 based on unique values at X1


unique_values_at_X1 = df['X1'].unique()
filtration_F1 = [set(df.index[df['X1'] == val]) for val in
unique_values_at_X1]
filtrations.append(filtration_F1)

# For each subsequent time step


for t in range(2, df.shape[1]):
# Start with the previous filtration
prev_filtration = filtrations[-1]
new_filtration = []

26
# Look at the sets in the previous filtration
for prev_set in prev_filtration:
if len(prev_set) == 1:
# If the set has only one element, carry it forward as is
new_filtration.append(prev_set)
else:
# If the set has multiple elements, we need to see if they still
have
the same value
# Create a dictionary to group states with the same value at time
t
value_groups = {}
for state in prev_set:
value_at_t = df.at[state, df.columns[t]]
if value_at_t in value_groups:
value_groups[value_at_t].add(state)
else:
value_groups[value_at_t] = {state}

# Each group of states with the same value forms a new set
in
the filtration
for group in value_groups.values():
new_filtration.append(group)

# Add the new filtration to the list of filtrations


filtrations.append(new_filtration)

# Format the filtrations for display


formatted_filtrations = []
for t, filtration in enumerate(filtrations):
formatted_filtration = []
for event in filtration:
formatted_filtration.append(sorted(list(event)))
formatted_filtrations.append({f'F{t}': formatted_filtration})

return formatted_filtrations

# Generate the filtrations


filtrations = generate_filtrations(df)
for F in filtrations:
print(F)

27
Definition : A stochastic process 𝑋 = {𝑋𝑡 ∶ 𝑡 ∈ T} is said to be adapted to the
filtration 𝔽 = {Ft ∶ 𝑡 ∈ 𝑇} if :
∀𝑡 ∈ 𝑇, F𝑡 = 𝜎(𝑋𝑠 ∶ 𝑠 ≤ 𝑡 ∈ T)

Definition : A stochastic process 𝑋 = {𝑋𝑡 ∶ 𝑡 ∈ T} is said to be adapted to the


filtration 𝔽 = {Ft ∶ 𝑡 ∈ 𝑇} if :
∀𝑡 ∈ 𝑇, 𝑋𝑡 is F𝑡 − 𝑚𝑒𝑎𝑠𝑢𝑟𝑎𝑏𝑙𝑒

Example 2.4: Let us take the examples above. Is the stochastic process X of WTI adapted to
the filtration G generated by GME?

No – the counter example is X2 that is not G2 random variable.

Definition : We call the probability filtered space the quartet (Ω , F , F, P) where Ω is the sample
set, F is the sigma-algebra on Ω , 𝔽 is the filtration on (Ω , F ) and P is a probability measure
on (Ω , F )

3. Stopping time

Definition : Let (Ω , F ) be a measurable space. Let , 𝔽 be the filtration on (Ω , F ). A stopping


time 𝜏 is a (Ω , F ) random variable that takes values in {0,1,2, … } and such that:

{𝜔 ∈ Ω ∶ 𝜏(𝜔) ≤ 𝑡} ∈ 𝐹𝑡 for any t ∈ {0,1,2, … }

We can show that the above definition could be rewritten as follows in the finite space:

{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 𝑡} ∈ 𝐹𝑡 for any t ∈ {0,1,2, … }

A stopping time is a stochastic process defined by a stopping rule that indicates a certain event
or behaviour of interest.

Example 3.1: Moving houses if your income reached a certain amount. (a stopping time)

Moving houses before fighting with a roommate (not a stopping time)

Example 3.2: Accepting cryptocurrency if the GDP reached a certain level.

Example 3.4: American option exercising date

Example 3.5: Before/after ESG certification

Example 3.6: Before/after IPO

28
Example 3.7: Let us take the example of WTI prices addressed previously.

W X0(w) X1(w) X2(w) X3(w)


w1 60 70 75 70
w2 60 70 70 70
w3 60 60 70 55
w4 60 55 60 75
• Let 𝜏 a random variable defined by the first time the price of WTI is higher or equal than 70.

Is 𝜏 a stopping time with respect of the filtration F generated by X?

{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 0} = ∅ ∈ 𝐹0

{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 1} = {𝜔1 , 𝜔2 } ∈ 𝐹1

{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 2} = {𝜔3 } ∈ 𝐹2

{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 3} = {𝜔4 } ∈ 𝐹3

Then 𝜏 is a stopping time.

• Let 𝛿 a random variable modelling this situation: the first time we buy WTI with the assurance
to make money later.
{𝜔 ∈ Ω ∶ 𝛿(𝜔) = 0} = {𝜔1 , 𝜔2 } ∉ 𝐹0
• How can we make 𝛿 a stopping time? By changing the definition to “the first time we sell WTI
with the assurance to make money.

Homework: Let 𝜏1 and 𝜏2 be two stopping times under a filtration F. Show that min(𝜏1 , 𝜏2 ) and
max(𝜏1 , 𝜏2 ) are stopping times.

Example 3.8:

Step1: Step2: Step3:


W GPA GMAT Ielts
w1 3.6 720 8
w2 3.6 650 8
w3 3.2 610 7
w4 3.2 610 6

• Filtration F:

𝐹1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 , 𝜔4 })

𝐹2 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 , 𝜔4 })

𝐹3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

• Let 𝜏 a random variable defined by picking the top 3 candidates.


{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 1} = ∅ ∈ 𝐹1
{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 2} = ∅ ∈ 𝐹2
{𝜔 ∈ Ω ∶ 𝜏(𝜔) = 3} = {𝜔1 , 𝜔2 , 𝜔3 } ∈ 𝐹3

29
Exam problem

Suppose you would like to model the stock price of BIAT through the stochastic process X. You
build a scenario analysis for the process X and you come up with the following scenarios:

W Y0(w) Y1(w) Y2(w) Y3(w) Y4(w)


w1 90 90 95 96 95
w2 90 95 95 93 95
w3 90 95 97 97 93
w4 90 93 90 87 93
W5 90 93 90 85 93

Find the filtration F generated by Y.

Assuming the 5 scenarios have the same probability, find the bellow conditional expectations:

• 𝐸[𝑌2 /𝐹1 ]
• 𝐸[𝑌3 /𝐹2 ]
• 𝐸[𝑌4 /𝐹3 ]
• 𝐸[𝑌1 /𝐹2 ]

Let 𝜏 be the random variable defining the event ”The purchase of BIAT stock when the price hits
93 for the first time” . Is 𝜏 a stopping time?

Python Time !

Stopping Time Made Simple: We'll leverage the existing code for WTI price and aim to
determine the stopping time using Python.

def find_stopping_times_auto(df):
# Initialize stopping times for each w
stopping_times = {w: None for w in df.index}
# Initialize a dictionary to hold the stopping times by time index
stopping_times_by_t = {t: [] for t in range(len(df.columns))}
# Iterate over the dataframe to find the stopping times
for w in df.index:
for t in range(0, len(df.columns)):
# Check if the price is greater than or equal to 70 and stopping
time is not already set
if df.at[w, f'X{t}'] >= 70 and not stopping_times[w]:
# Set the stopping time for path w
stopping_times[w] = t
# Add the path to the stopping time list for time t
stopping_times_by_t[t].append(w)
break # No need to check further times for this path

30
# Convert the dictionary to a list of dictionaries for each time t
formatted_stopping_times = [{f'T{t}': stopping_times_by_t[t]} for t
in stopping_times_by_t]

return formatted_stopping_times

# Apply the function to our dataframe


stopping_times = find_stopping_times_auto(df)
print(stopping_times)

# Now, let's define a function that checks whether each stopping time is
included in the corresponding filtration.

def check_stopping_times(filtrations, stopping_times) :


# Each stopping time should be a subset of the corresponding
filtration
is_stopping_time = True

# Check each stopping time against the corresponding filtration


for t in range ( len ( stopping_times ) ) :
stopping_time_set = set ( stopping_times[t][f'T{t}'] )
filtration_set = set ().union ( *[set ( group ) for group in
filtrations[t][f'F{t}']] )

# If the stopping time set is not a subset of the filtration set,


then it's not a stopping time
if not stopping_time_set.issubset ( filtration_set ) :
is_stopping_time = False
break

return is_stopping_time

# Check if the stopping times are included in the corresponding


filtrations
is_stopping_time = check_stopping_times ( filtrations, stopping_times )

print(is_stopping_time)

Discover the captivating world of finance through Python programming. Run the code
and witness the enchantment of what programming can unfold!

31
II. Conditional Expectation

Why Do You Need to Add a Condition When You Are Making a

Prediction?
It’s all about whether you are makig a guess or a smart guess. When it comes to making
predictions, accuracy is our goal. While luck plays a role, knowledge is equally crucial. In this
context, "condition" means what you already know, and with knowledge factored in, your
guess becomes a smart guess.

The Thread of Knowledge

[…] Investire finished reading the tome; it recounted the tale of Theseus,
punished by the King of Crete for a crime. Theseus faced a deadly choice: to
kill the Minotaur or be killed by it. With the aid of the king’s daughter,
Ariadne, who had fallen deeply in love with him, Theseus was equipped with
a sword and a ball of thread. Using the thread, Theseus retraced his steps
through the labyrinth, to escape the monstrous Minotaur.

Our little bookworm continued contemplating the moral explicitly


written on the last page: “In the labyrinth of life, knowledge is the
thread that leads us through uncertainty, just as Ariadne's thread
guided Theseus safely out of the Minotaur's maze.” Investire thought
to himself, "If only I possessed a thread of knowledge, would I become
more powerful and less uncertain? Could I escape this uncertainty? But
what crucial information am I lacking?”

In the story of Investire, as he crafted his probability space to


predict Finis's book choice, he overlooked the discussions Finis had
with their friends, Finis’s habit of heading south in the library, and the
fact that Finis is right-handed. Had he considered these factors while
assigning probabilities between 0 and 1 to the book choices, his guess would have been far
more accurate. Yet, he pondered the certainty and importance of this information for his quest.
Deep in contemplation, the young boy turned to his favorite book, seeking guidance and clarity.

Investire rushed to his spell-book. Upon opening it, a voice echoed, “It is not about the
length or strength of your thread; first and foremost, ask yourself if this is the right thread to
help you escape.” Investire turned the page and read, “Maximize your knowledge, refine your
categorization, and let it accumulate over the sands of time. With that, you will draw closer
to the accuracy you crave, step by step.” The young boy attempted to turn the next page, but
the book suddenly closed, leaving him in thoughtful silence.

Investire pondered, "In the next 100 days, I want to predict the chance of Finis randomly
selecting a fiction book for me. Maybe with the knowledge I possess, I can make a wiser guess.
The length of my thread doesn't matter, so what does?" Inspired by Finis when he tested the

32
accuracy of the spell book in finding the future value of the apple, Investire decided to analyze
Finis's past choices and observe his habits to enhance his understanding of his selection
process, each passing day. Soon, a pattern emerged: Finis often gifted him a fiction book every
Saturday and Wednesday. Excitedly, Investire exclaimed, "By considering the day of the week,
I can make an informed estimate about the likelihood of receiving a fiction book! That's my
thread – the days of the week." As he pronounced these words, the book unveiled the next
page to him with a list of instructions.

Since the outcome is likely to vary with time, Investire needed a bigger tool kit of random
variables. Returning to Probare, he gathered various boxes and veils as instructed by his spell
book. Standing before three tables, he declared, "I want to predict the likelihood of Finis
choosing a fiction book similar to this one in the box, tomorrow, based on what I know up until
Friday (Filtration till t= Friday)."

On the first table, there was a switch and a box. Investire placed a fiction book inside,
creating a random variable. If the box held a fiction book, he flicked the switch on (=1),
signifying its genre is indeed fiction. Otherwise, he left it off (=0). Considering what he knew,
he assigned the probability that Finis might select that book.

On the second table, Investire placed the value of him receiving a fiction book for a specific
outcome in particular day. He adjusted it according to the probability of that specific day being
chosen.

Magically, a number appeared on the third table, 𝐸[𝑋/G ] indicating his more informed
prediction.

Amazed, Investire observed the results. As he gazed at the number that appeared, the spell
book opened once again and said, “From village to village, the art of minimizing uncertainty
with the thread of knowledge remains the same at its core, though it bears different names in
different places.”

Takeaway message:

When Investire considered the record of book selections and observed Finis’ choices in the
following days, he expanded his filtration. In fact, if you compute the same expectation under
different filtrations (that is, your expectation is conditional on more information each time),
the results will differ. The more knowledge you accumulate, the more your expectation varies
and tends towards accuracy.

The pattern Investire noticed regarding Finis’ book selections formed a stochastic process,
where each day’s choice represented a random variable. Investire needed to know what
information to factor in, as the spell-book warned him that many before him computed
conditional expectations erroneously by overestimating the relevance of their information. In
his case, the day of the week was relevant.

33
The instructions given by the book, are as follows:

Table (1) Table (2)

The switch (indicator function) The probability table.

If I am there, switch it on How much I get if I am there.


𝑛
𝐼𝐴𝑖 (𝜔) ∑ 𝑋(𝜃)𝑃(𝜃)

𝑃(𝐴𝑖 ) 𝜃∈𝐴𝑖
𝑖=1

Table (3)

The result

𝐸[𝑋/G ]

The book's statement about conditional expectation changing names from one village to
another refers to how it is used in various disciplines: in geometry, it is projection; in
econometrics, it is regression; in industrial engineering, it is the solution to a partial
differential equation; and it also pertains to simulation.

1. Conditional Probability

Definition: Let (Ω , F , P) be a finite probability space. For all 𝐵 ∈ F with a positive probability,
the conditional probability given B is defined as:

𝑃(𝐴 ∩ 𝐵)
𝑃(𝐴/𝐵) =
𝑃(𝐵)

For any 𝐴 ∈ F

Example: Let us take the random experiment of rolling a dice. Suppose the dice is well balanced.

1. What is the probability to obtain more than 3 points? Answer: ½


2. Suppose after rolling the dice, I tell you that the number that I got is even. What is the
probability to obtain more than 3 points? Answer: P({4,6})/ P({2,4,6}) = 2/3

Example 1.1:

34
W X0(w) X1(w) X2(w) X3(w) P
w1 60 70 75 80 1/8
w2 60 70 70 80 2/8
w3 60 60 75 70 3/8
w4 60 60 60 65 2/8

What is the probability of X2 = 75 knowing that X1 = 70?


P(X2 = 75 / X1 =70) = 1/3

2. Conditional Expectation

Intuitively we can think of the conditional expectation as given by:


𝐸(𝑋/𝑌) = ∑ 𝑥𝑘 𝑃(𝑋 = 𝑥𝑘 /𝑌)


𝑘=1

Definition: Let X and Y two discrete random variables defined on the probability space
(Ω , F , P) . Let G ⊆F the sigma-algebra generated by Y with finite partition
{𝐴1 , ⋯ , 𝐴𝑛 }. The conditional expectation of X knowing G is given by:
𝑛
𝐼𝐴 (𝜔)
𝐸[𝑋/G ] = ∑ 𝑖 ∑ 𝑋(𝜃)𝑃(𝜃)
𝑃(𝐴𝑖 )
𝑖=1 𝜃∈𝐴𝑖
1 𝑖𝑓 𝜔 ∈ 𝐴
Where I is an indicator function, i.e. 𝐼𝐴 = {
0 𝑖𝑓 𝜔 ∉ 𝐴

Example 2.1:

W X0(w) X1(w) X2(w) X3(w) P


w1 60 70 75 80 1/8
w2 60 70 75 75 2/8
w3 60 60 70 70 3/8
w4 60 60 60 65 2/8

• Find the filtration 𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by X.

F 0 = {∅, Ω}

F 1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 , 𝜔4 })

F 2 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 }, {𝜔4 })

F 3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

• Compute the following conditional expectations:

o 𝐸[𝑋3 /F 2 ]

35
1
𝑖𝑓𝜔 𝜖 𝐴1 , × [𝑋3 (𝜔1 )𝑃1 + 𝑋3 (𝜔2 )𝑃2 ] 𝐴1 ∈ { 𝜔1 , 𝜔2 }
𝑃(𝐴1 )
𝐸[𝑋3 /F 2 ] = , 𝑤𝑖𝑡ℎ {𝐴2 ∈ { 𝜔3 }
𝑖𝑓𝜔 𝜖 𝐴2 , 𝑋3 (𝜔3 )
𝐴3 ∈ { 𝜔4 }
{ 𝑖𝑓𝜔 𝜖 𝐴3 , 𝑋3 (𝜔4 )
1 1 2
3⁄ × [80 × ⁄8 + 75 × ⁄8] , 𝑖𝑓𝜔 𝜖 𝐴1
8 𝟕𝟔, 𝟔𝟔 , 𝒊𝒇𝝎 𝝐 𝑨𝟏
1 3
= 3⁄ × 70 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴2 = { 𝟕𝟎, 𝒊𝒇𝝎 𝝐 𝑨𝟐
8
1 2 𝟔𝟓 , 𝒊𝒇𝝎 𝝐 𝑨𝟑
{ 2⁄ × 65 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴3
8

o 𝐸[𝑋3 /F 1 ]

1
𝑖𝑓𝜔 𝜖 𝐴1 , × [𝑋3 (𝜔1 )𝑃1 + 𝑋3 (𝜔2 )𝑃2 ]
𝑃(𝐴1 ) 𝐴 ∈ { 𝜔1 , 𝜔2 }
𝐸[𝑋3 /F 1 ] = , 𝑤𝑖𝑡ℎ { 1
1 𝐴2 ∈ {𝜔3 , 𝜔4 }
𝑖𝑓𝜔 𝜖 𝐴2 , × [𝑋3 (𝜔3 )𝑃1 + 𝑋3 (𝜔4 )𝑃4 ]
{ 𝑃(𝐴2 )
1 1 2
3⁄ × [80 × ⁄8 + 75 × ⁄8] , 𝑖𝑓𝜔 𝜖 𝐴1
𝟕𝟔, 𝟔𝟔 , 𝒊𝒇𝝎 𝝐 𝑨𝟏
8
={ 1 = {
3 2 𝟔𝟖, 𝒊𝒇𝝎 𝝐 𝑨𝟐
5⁄ × [70 × ⁄8 + 65 × ⁄8] , 𝑖𝑓𝜔 𝜖 𝐴2
8

o 𝐸[𝑋2 /F 1 ]

1
𝑖𝑓𝜔 𝜖 𝐴1 , × [𝑋2 (𝜔1 )𝑃1 + 𝑋2 (𝜔2 )𝑃2 ]
𝑃(𝐴1 ) 𝐴 ∈ { 𝜔1 , 𝜔2 }
]
𝐸[𝑋2 /F 1 = , 𝑤𝑖𝑡ℎ { 1
1 𝐴2 ∈ {𝜔3 , 𝜔4 }
𝑖𝑓𝜔 𝜖 𝐴2 , × [𝑋2 (𝜔3 )𝑃1 + 𝑋2 (𝜔4 )𝑃4 ]
{ 𝑃(𝐴2 )
1 1 2
3⁄ × [75 × ⁄8 + 75 × ⁄8] , 𝑖𝑓𝜔 𝜖 𝐴1
𝟕𝟓, 𝒊𝒇𝝎 𝝐 𝑨𝟏
8
={ 1 = {
3 2 𝟔𝟔, 𝒊𝒇𝝎 𝝐 𝑨𝟐
5⁄ × [70 × ⁄8 + 60 × ⁄8] , 𝑖𝑓𝜔 𝜖 𝐴2
8

o 𝐸[𝑋2 /F 3 ]

𝑖𝑓𝜔 𝜖 𝐴1 , 𝑋2 (𝜔1 ) 𝐴1 ∈ {𝜔1 }


𝑖𝑓𝜔 𝜖 𝐴3 , 𝑋2 (𝜔2 ) 𝐴 ∈ {𝜔2 }
𝐸[𝑋2 /F 3 ] = , 𝑤𝑖𝑡ℎ { 2
𝑖𝑓𝜔 𝜖 𝐴3 , 𝑋2 (𝜔3 ) 𝐴3 ∈ {𝜔3 }
{ 𝑖𝑓𝜔 𝜖 𝐴4 , 𝑋2 (𝜔4 ) 𝐴4 ∈ {𝜔4 }

36
1 1
1⁄ × 75 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴1
8
1 2 𝟕𝟓, 𝒊𝒇𝝎 𝝐 𝑨𝟏
2⁄ × 75 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴2
𝟕𝟓, 𝒊𝒇𝝎 𝝐 𝑨𝟐
8
= 1 = { = 𝑿𝟐 (𝝎)
3 𝟕𝟎, 𝒊𝒇𝝎 𝝐 𝑨𝟑
3⁄ × 70 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴3
8 𝟔𝟎, 𝒊𝒇𝝎 𝝐 𝑨𝟒
1 2
{ 2⁄ × 60 × ⁄8 , 𝑖𝑓𝜔 𝜖 𝐴4
8

o 𝐸[𝑋3 /F 0 ] = 𝑬(𝑿𝟑 )
o 𝐸[𝑋3 /F 3 ] = 𝑿3 (Same proof as 𝐸[𝑋2 /F 3 ] )

Example 2.2:

W X0(w) X1(w) X2(w) P


w1 60 64 66 1/4
w2 60 62 64 1/4
w3 60 62 63 1/4
w4 60 60 62 1/4

• Find the filtration 𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by X.

F 0 = {∅, Ω}

F 1 = 𝜎({𝜔1 }, {𝜔2 , 𝜔3 }, {𝜔4 })

F 2 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 }, {𝜔4 })

• Compute the following conditional expectations:

o 𝐸[𝑋2 /F 1 ]

1
𝑖𝑓𝜔 𝜖 𝐴1 , × [𝑋2 (𝜔1 )𝑃1 ]
𝑃(𝐴1 )
𝐴1 ∈ { 𝜔1 }
1
𝐸[𝑋2 /F 1 ] = 𝑖𝑓𝜔 𝜖 𝐴2 , × [+𝑋2 (𝜔2 )𝑃2 + 𝑋2 (𝜔3 )𝑃3 ] , 𝑤𝑖𝑡ℎ {𝐴2 ∈ {𝜔2 , 𝜔4 }
𝑃(𝐴2 )
𝐴2 ∈ {𝜔4 }
1
𝑖𝑓𝜔 𝜖 𝐴3 , × [𝑋2 (𝜔4 )𝑃4 ]
{ 𝑃(𝐴3 )
1
1⁄ × [66 × 1⁄4] , 𝑖𝑓𝜔 𝜖 𝐴1
4 𝟔𝟔, 𝒊𝒇𝝎 𝝐 𝑨𝟏
1
= 2⁄ × [64 × 1⁄4 + 63 × 1⁄4] , 𝑖𝑓𝜔 𝜖 𝐴2 = { 𝟔𝟑. 𝟓, 𝒊𝒇𝝎 𝝐 𝑨𝟐
4
1 𝟔𝟐, 𝒊𝒇𝝎 𝝐 𝑨𝟑
1⁄ × [62 × 1⁄4] , 𝑖𝑓𝜔 𝜖 𝐴3
{ 4

o 𝐸[𝑋2 /F 2 ]

37
𝑖𝑓𝜔 𝜖 𝐴1 , 𝑋2 (𝜔1 ) 𝐴1 ∈ {𝜔1 }
𝑖𝑓𝜔 𝜖 𝐴3 , 𝑋2 (𝜔2 ) 𝐴2 ∈ {𝜔2 }
𝐸[𝑋2 /F 2 ] = , 𝑤𝑖𝑡ℎ {
𝑖𝑓𝜔 𝜖 𝐴3 , 𝑋2 (𝜔3 ) 𝐴3 ∈ {𝜔3 }
{ 𝑖𝑓𝜔 𝜖 𝐴4 , 𝑋2 (𝜔4 ) 𝐴4 ∈ {𝜔4 }
1 1
1⁄ × 66 × ⁄4 , 𝑖𝑓𝜔 𝜖 𝐴1
4
1 1 𝟔𝟔, 𝒊𝒇𝝎 𝝐 𝑨𝟏
1⁄ × 64 × ⁄4 , 𝑖𝑓𝜔 𝜖 𝐴2
𝟔𝟒, 𝒊𝒇𝝎 𝝐 𝑨𝟐
4
= 1 = { = 𝑿𝟐 (𝝎)
1 𝟔𝟑, 𝒊𝒇𝝎 𝝐 𝑨𝟑
1⁄ × 63 × ⁄4 , 𝑖𝑓𝜔 𝜖 𝐴3
4 𝟔𝟐, 𝒊𝒇𝝎 𝝐 𝑨𝟒
1 1
{ 1⁄ × 62 × ⁄4 , 𝑖𝑓𝜔 𝜖 𝐴4
4

Takeaway message: Based on the available information (filtration), our expectations can vary
significantly. For instance, the insights accessible to a broker, asset manager, or individual
investor differ greatly. A broker has in-depth knowledge of who is buying and selling, which is
considerably more substantial than the information an individual investor possesses. This
broader understanding allows a broker to form a distinct perspective on the expected
conditional return, contrasting markedly from that of a typical investor.

3. Properties of Conditional Expectation

• P1: If X is F -measurable, then 𝐸[𝑋/F ] = 𝑋


• P2: If G ⊆F then 𝐸[𝐸[𝑋/G ]/F ] = 𝐸[𝑋/G ]
Proof: 𝐸[𝑋/G ] is a random variable that is G -measurable. Since G ⊆F then 𝐸[𝑋/G ] is F -
measurable. By P1 then we get the result.
• P3: If G ⊆F then 𝐸[𝐸[𝑋/ F ]/G ] = 𝐸[𝑋/G ]
• P4: 𝐸[X/ {∅, 𝛺} ] = 𝐸[𝑋]
• P5: 𝐸[𝐸[𝑋/F ]] = 𝐸[𝑋]
• P6: Let Y be an F -measurable random variable then 𝐸[𝑋𝑌/F ] = 𝑌𝐸[𝑋/F ]
• P7: Let X and Y be two independent random variables then 𝐸[X/σ(Y) ] = 𝐸[𝑋 ]

4. Conditional Expectation and orthogonal projection.

From a geometric point of view, the conditional expectation of a random variable X defined on
(Ω , F ) can be interpreted as the projection of X in the Hilbert space 𝐿2 (F ).

The Hilbert space 𝐿2 (F ) consists of square-integrable random variables with respect to the
probability measure on the sigma-algebra F.

It provides a natural framework for studying random variables, their conditional expectations,
and defining orthogonal projection.

The conditional expectation E(X│ F ) is an element of 𝐿2 (F ) and represents the "average"


behavior of X given the information contained in F .

The expected value 𝔼[(X - 𝔼(X| F ))] provides the average distance between X and its
conditional expectation over all possible outcomes.

38
The squared average distance 𝐸[𝑋 − 𝐸(𝑋|F )]2 between X and its conditional expectation in
𝐿2 (F) quantifies the discrepancy between the two.

Squaring the difference ensures that the distance is always positive, which is a desirable
property when measuring distances. It also penalizes larger deviations more heavily, which is
often useful in statistical applications and it is consistent with the properties of the Hilbert
space 𝐿2 (F).

The conditional expectation could be written as :

𝐸[𝑋 − 𝐸(𝑋|F )]2 = 𝑚𝑖𝑛𝑍∈𝐿2 (F ) {𝐸(𝑋 − 𝑍)2 }

X
X -
𝐸(𝑋|F )

𝐿2 (F)
𝐸(𝑋|F )

39
III. Martingales
Investire, Mart, Gale, and the Wise Man

[…] Investire eagerly left his library and hurried to


Finis’ house, driven by the desire to confirm the
validity of his conditional expectation for the
upcoming book. Along the way, he encountered
Mr. Ville16, to whom he always looked up, basking
in the warm sun of Capitalis. Investire
approached the old man with reverence and
admiration.

"Oh, sir," Investire exclaimed, his eyes filled with awe, "your wisdom is truly inspiring! I dream
of becoming like you, immersing myself in books, and striving to create the most magnificent
library ever known. But I often question if I'm following the right path." The old man said, "In
life," he began, "you accumulate knowledge, devour the words of countless authors, and
absorb the wisdom of those who visited before us. This vast reservoir of experiences expands
your sigma algebra. When your predictions align with reality, people may call it wisdom,
expertise, or even a well-functioning model. The labels matter not; what's important is the
understanding you gain. However, my dear son, remember this: Sometimes, life rewards
intelligence and knowledge; at other times, it upholds its most equitable trait. Life, my boy, is
a martingale, but it possesses a twist, nevertheless." Investire's curiosity piqued, he asked,
"Mart and Gale? Who are they?" The elderly man smiled mysteriously. "Son, you must depart
now and return with the fairest game from the village of Probare. Only then shall I unveil the
secrets of Mart, Gale, and the twist that life holds." Investire nodded and headed to Probare.

[…] Entering Probare this time was easier for Investire, for
he was by then familiar with the door and the bridge. He
approached the door seeking guidance and whispered,
"Would you please tell me where to find your fairest game,
to play with Mart and Gale?" The door answered, " Ah, it
has been a while since you last graced us with your
presence,” The voice murmured “Yes, Mart and Gale are
over there, playing and waiting for a new one to join.” Investire said “How can I join their
mysterious game?", the door answered “To partake in their game, you must gather apples,
sweet red ones. Look beside me, and you shall find what you seek. But heed my words, dear
traveler, for Mart and Gale possess riddles as deep as a black hole and as sweet as the apples
you will play with. Approach with caution and let not their playful jests diminish your resolve”.

Investire collected the apples, and approached Mart and Gale, two funny old men who were
arm-wrestling. Taking a deep breath, he decided to join in, and they welcomed him
immediately. At first it was Mart and Gale who were arm-wrestling and then Investire knew it
will be his turn. During the arm-wrestling rounds, Investire closely watched Gale's every move,

16 The concept of martingale in probability theory was introduced by Paul Lévy in 1934, though he did
not name it. The term "martingale" was introduced later by Ville (1939), who also extended the definition
to continuous martingales. Much of the original development of the theory was done by Joseph Leo Doob
among others.
40
trying to discern a pattern or a clue that would
give him an edge. After several rounds, it was
his turn and Mart was supposed to help him
and to update the score. Mart said, “Young one,
your moment has arrived. Speak of what you
know, unveil the number of apples you dare to
risk, and I shall inscribe the score of our game,
as you play. Know this: I stand as your ally, yet
the true adversary you face is Gale, not me.” So
Investire approached Mart and shared his
observations and how sometimes Gale decides to simply let the other win. Investire hoped by
sharing this knowledge with Mart he will predict who was going to win and get an insight about
how much apples to risk. However, every time, Investire shared his observations Mart says
“Noted” and burst into laughs. And the outcome was never revealed, not via Investire’s keen
eyes, nor Mart’s estimations and help; Investire won some, and lost a lot of apples. And the
game became a cycle of occasional hope, and increasing disappointment, so Investire decided
to stop and leave Probare.

Returning to the village of Capitalis, Investire went to Mr. Ville. As he recounted his
adventures in Probare, Mr. Ville listened intently then he said "Mart is indeed a funny guy. No
matter the secrets you share, no matter the depth of your knowledge, he shrouds himself in a
veil of forgetfulness. Why, you ask? For in this game you played, the current value of each
round should be equal to and only to itself so that knowledge of yesterday or the uncertainties
of tomorrow have no do in who wins and who loses; and that is the essence of Fairness. This
doesn’t mean knowledge is of no value; the trivial record he meticulously maintains was
expanding your knowledge, your Filtration over time. I know, you may feel deceived because
although there were only two possible outcomes, either you win or Gale wins, and despite
these very small and finite possibilities you couldn’t predict what shall happen until it
happens. This, my child is a Martingale game.” Investire looked at him and added “But Mr. Ville
this loss costed me not only feeling fool and naive, but also the precious apples I was given by
the door of Probare!” The wise man said “What I admire about Mart and Gale is that they test
your patience. You should’ve known that if you were patient enough, and risk averse enough,
that is regardless of how many apples you lose, you risk the double of it in the next round, at a
certain point in time you would undoubtedly win a huge sum and offset all the previous
losses. My son, Mart and Gale teach you to never give up!” Investire stopped speechless then
asked, “And what’s the twist about life and Martingales?” “Life can be a martingale, a fair game
where we all beg for luck because nothing else matters, so you simply embrace the now
without the burden of the past or the uncertainty of the future: You cross your fingers, and you
never give up. But don’t let that make you unsure of the importance of your thread of
knowledge for that life has a multitude of stochastic processes and each process is specific,
sometimes yesterday matters, sometimes it doesn’t, sometimes a pattern will repeat itself
sometimes it won’t… Go by the Botanical Lake of Capitalis, observe it closely, my child, for
within its ripples lies another secret of embracing life's unpredictable journey.”

Takeaway message

In this journey Investire learned about Martingales, a specific type of stochastic processes. In
this game, Mart represented the guard of fairness while Gale embodied the randomness of
41
stochastic processes. When Mr. Ville said, “the current value of each round should be equal to
and only to itself” and explained how the thread of knowledge (conditional expectation) won’t
make your predictions more precise, he meant that 𝑬[𝑴𝒕 /F𝐬 ] = 𝑴𝒔 ; and when he
acknowledged that the possible events were small and finite he meant that 𝑬[|𝑴𝒕 |] <
∞ ∀ 𝒕 ≥ 𝟎, and when he said that he shouldn’t underestimate the value of knowledge, he
insisted on the importance of expanding your filtration for that your martingale is adapted to
F. And those are the properties of a Martingale process. So, to check whether you are playing
with Mart and Gale or not, check whether these properties are satisfied or not.

1. Introduction

Martingales are a concept that comes from the world of games and gambling. Imagine
you're playing a game with money, and at different points in time, you have a certain amount
of cash (let's call it 𝑀𝑛 ). You also have some information about the game up to that point 𝐹𝑛 .

Now, here's the cool part: If the way your money changes over time follows a simple rule,
where, on average, the money you'll have in the next round is just what you have now, given
the information you know, then we call this sequence of money a martingale. This rule makes
the game seem fair.

For instance, think of flipping a fair coin. Each time you flip, if you win, you get some money
added, and if you lose, you lose some money. If the coin is fair, your total money over time will
behave like a martingale.

However, if the game isn't fair – maybe the coin is more likely to land on one side – then your
money might not follow this rule anymore. It gets a bit trickier.

Mathematically, martingales are sequences that have some neat properties, especially when it
comes to how they change over time. In this course, we're going to explore these properties
and look at different examples to see how they can be used to understand things better using
math.

2. Martingale Properties

Definition: Let (Ω , F , F, P) be a filtered probability space, the stochastic process M =


{Mt : t ∈ T} is a discrete-time martingale if :

i. 𝐸[|𝑀𝑡 |] < ∞ ∀ 𝑡 ≥ 0
ii. M is adapted to the filtration F, meaning that 𝑀𝑡 is F𝑡 - measurable ∀ 𝑡 ≥ 0
iii. 𝐸[𝑀𝑡 /Fs ] = 𝑀𝑠 ∀ 0 ≤ 𝑠 ≤ 𝑡

The Gambler's Journey at Martingale Casino:

Property 1: The expected value of |𝑀𝑡 | is finite for all t ≥ 0.

This property implies that the expected value of the random variable 𝑀𝑡 (the value of the
martingale at time t) is finite for all time periods t. It means that, on average, the martingale

42
does not exhibit extreme swings or reach infinite values, ensuring that the gambler's expected
gain or loss remains bounded over time.

Property 2: 𝑀 is adapted to the filtration 𝐹, meaning that 𝑀𝑡 is 𝐹𝑡 -measurable for all t ≥ 0.

This means that the value of the martingale at any time t only depends on the information that
was available up to time t. In other words, the martingale does not take into account any future
information.

In gambling, this means that you cannot use the martingale betting strategy to predict the
outcome of a future bet. The martingale betting strategy only takes into account the past bets,
and it cannot predict what will happen in the future.

Property 3: E[𝑀𝑡 /𝐹𝑠 ] = 𝑀𝑠 for all 0 ≤ s ≤ t.

In the context of gambling, this property represents the core principle of a martingale strategy.
It states that the conditional expectation of the martingale's future value 𝑀𝑡 given all available
information up to a prior time 𝐹𝑠 is equal to its current value at that prior time 𝑀𝑠 . This property
implies that the martingale strategy is fair and unbiased, as the expected future value is the
same as the current value, given the available information.

Lemma: Let M = {Mt : t ∈ T} be a martingale on the filtered probability space (Ω , F , F, P)


then :

𝐸[𝑀𝑡 ] = 𝐸[𝑀0 ] ∀ 𝑡 ≥ 0

i.e. martingales have constant expectations.

Proof : 𝐸[𝑀𝑡 ] = 𝐸[𝐸[𝑀𝑡 /F0 ]] = 𝐸[𝑀0 ]

Example 2.1: Flip a coin: you get 10 dinars if head, you get nothing if tail.

Example 2.2: Let X be a finite random variable on the filtered probability space (Ω , F , F, P).
Let M be the stochastic process such as:

𝑀𝑡 = 𝐸(𝑋/F 𝑡 )

Is M a martingale? If yes prove it, if no give a counter example.

To prove that 𝑀 is a martingale we need to check that all the three properties stand, otherwise
we provide a counter example to prove that is not a martingale.

i. 𝐸[|𝑀𝑡 |] < ∞ ?

𝑀𝑡 = 𝐸[𝑋/F 𝑡 ] so 𝐸[𝑀𝑡 ] = 𝐸[𝐸[𝑋/F 𝑡 ]]

→ 𝐸[|𝐸[𝑋/F 𝑡 ]|] ≤ 𝐸[𝐸[|𝑋|/F 𝑡 ] And 𝐸[𝐸[|𝑋|/F 𝑡 ] = 𝐸[|𝑋|] ≤ ∞

→ So 𝐸[|𝐸[𝑋/F 𝑡 ]|] ≤ ∞

ii. 𝑀𝑡 = 𝐸[𝑋/F 𝑡 ] which is F 𝑡 -measurable for ∀ 𝑡 ≥ 0 then 𝑀 is adapted.


iii. 𝐸[𝑀𝑡 /F 𝑠 ] = 𝑀𝑠 ?

𝐸[𝐸[𝑋/F 𝑡 ]/F 𝑠 ] , 𝑓𝑜𝑟 𝑠 < 𝑡

43
= 𝐸[𝑋/F 𝑠 ] = 𝑀𝑠 ∀ 𝑠, 𝑡 ≥ 0 𝑤𝑖𝑡ℎ 𝑡 > 𝑠

 So 𝑀 is a Martingale.

Example 2.3:

W X0(w) X1(w) X2(w) X3(w) P


w1 50 60 70 70 ¼
w2 50 60 50 70 ¼
w3 50 40 50 50 ¼
w4 50 40 30 30 ¼
• Is X a Martingale?

Counter example to prove that X is not a martingale:

70 , 𝑖𝑓𝜔 𝜖 𝐴1 𝐴1 ∈ { 𝜔1 }
70, 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ { 𝜔2 }
𝐸[𝑋3 /F 2 ] = , 𝑤𝑖𝑡ℎ
50 , 𝑖𝑓𝜔 𝜖 𝐴3 𝐴3 ∈ { 𝜔3 }
{ 30 , 𝑖𝑓𝜔 𝜖 𝐴4 { 𝐴4 ∈ { 𝜔4 }

So 𝐸[𝑋3 /F 2 ] = 𝑋3 ≠ 𝑋2

 Then X is not a martingale because if it were then 𝐸[𝑋3 /F 2 ] must be equal to 𝑋2

• What changes need to be made to make X a martingale?

W X0(w) X1(w) X2(w) X3(w) P


w1 50 60 70 70 ¼
w2 50 60 50 50 ¼
w3 50 40 50 50 ¼
w4 50 40 30 30 ¼

To prove that X is a martingale we need to go case by case for each one of three properties:

i. 𝑬[|𝑿𝒕 |] < ∞ , ∀ 𝒕 ≥ 𝟎

1 1 1 1
✓ 𝐸(𝑋0 ) = 4 × 50 + 4 × 50 + 4 × 50 + 4 × 50 = 50 < ∞

1 1 1 1
✓ 𝐸(𝑋1 ) = × 60 + × 60 + × 40 + × 40 = 50 < ∞
4 4 4 4

✓ 𝐸(𝑋2 ) = 50 < ∞

✓ 𝐸(𝑋3 ) = 50 < ∞

 The 1st property is checked.

ii. 𝑿 is adapted to the filtration 𝔽, meaning that 𝑿𝒕 is F 𝒕 -measurable , ∀ 𝒕 ≥ 𝟎

44
F0 = {∅, Ω}
F1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 , 𝜔4 })
✓ 𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by X:
F2 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })
{F 3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

 We defined 𝔽 as generated by X so by definition X is adapted (The 2sd property is


checked).

iii. 𝑬[𝑿𝒕 /F 𝒔 ] = 𝑿𝒔 , ∀ 𝟎 ≤ 𝒔 ≤ 𝒕

✓ 𝐸[𝑋0 /F 0 ] = 𝐸(𝑋0 ) = 50 = 𝑋0

✓ 𝐸[𝑋1 /F 0 ] = 𝐸(𝑋1 ) = 50, 𝑖𝑓 𝜔 𝜖 𝐴, 𝑤𝑖𝑡ℎ 𝐴 ∈ {𝜔1 , 𝜔2 , 𝜔3 , 𝜔4 } so 𝐸[𝑋1 /F 0 ] = 𝑋0

1 1 1
(1/(2) ) × [60 × 4 + 60 × 4], 𝑖𝑓𝜔 𝜖 𝐴1 𝐴 ∈ {𝜔1 , 𝜔2 }
✓ 𝐸[𝑋1 /F 1 ] = { , 𝑤𝑖𝑡ℎ { 1
1 1
(1/(2) ) × [40 × 4 + 40 ×
1
], 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ {𝜔3 , 𝜔4 }
4

60, 𝑖𝑓𝜔 𝜖 𝐴1
={ = 𝑋1
40, 𝑖𝑓𝜔 𝜖 𝐴2

✓ 𝐸[𝑋2 /F 0 ] = 𝑋0 (Same proof as 𝐸[𝑋1 /F 0 ])

1 1 1
(1/(2) ) × [70 × 4 + 50 × 4], 𝑖𝑓𝜔 𝜖 𝐴1 𝐴 ∈ {𝜔1 , 𝜔2 }
✓ 𝐸[𝑋2 /F 1 ] = { , 𝑤𝑖𝑡ℎ { 1
1
(1/( ) ) × [50 ×
1
+ 30 ×
1
], 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ {𝜔3 , 𝜔4 }
2 4 4

60, 𝑖𝑓𝜔 𝜖 𝐴1
={ = 𝑋1
40, 𝑖𝑓𝜔 𝜖 𝐴2

70, 𝑖𝑓𝜔 𝜖 𝐴1 𝐴1 ∈ {𝜔1 }


50, 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ {𝜔2 }
✓ 𝐸[𝑋2 /F 2 ] = { , 𝑤𝑖𝑡ℎ = 𝑋2
50, 𝑖𝑓𝜔 𝜖 𝐴3 𝐴3 ∈ {𝜔3 }
30, 𝑖𝑓𝜔 𝜖 𝐴4 {𝐴4 ∈ {𝜔4 }

✓ 𝐸[𝑋3 /F 0 ] = 𝑋0 (Same proof as 𝐸[𝑋1 /F 0 ])

1 1 1
(1/(2) ) × [70 × 4 + 50 × 4], 𝑖𝑓𝜔 𝜖 𝐴1 𝐴 ∈ {𝜔1 , 𝜔2 }
✓ 𝐸[𝑋3 /F 1 ] = { , 𝑤𝑖𝑡ℎ { 1
1
(1/( ) ) ×
1
[50 × + 30 ×
1
], 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ {𝜔3 , 𝜔4 }
2 4 4

60, 𝑖𝑓𝜔 𝜖 𝐴1
={ = 𝑋1
40, 𝑖𝑓𝜔 𝜖 𝐴2

45
70, 𝑖𝑓𝜔 𝜖 𝐴1 𝐴1 ∈ {𝜔1 }
50, 𝑖𝑓𝜔 𝜖 𝐴2 𝐴2 ∈ {𝜔2 }
✓ 𝐸[𝑋3 /F 2 ] = { , 𝑤𝑖𝑡ℎ = 𝑋2
50, 𝑖𝑓𝜔 𝜖 𝐴3 𝐴3 ∈ {𝜔3 }
30, 𝑖𝑓𝜔 𝜖 𝐴4 {𝐴4 ∈ {𝜔4 }

✓ 𝐸[𝑋3 /F 3 ] = 𝑋3

 The 3rd property checks for every one of the cases above.

Example 2.4:

Let X be a finite random variable on the filtered probability space (Ω , F , F, P)

W X0(w) X1(w) X2(w) X3(w) P


w1 75 80 85 85 1

4
w2 75 80 75 85 1

8
w3 75 60 75 75 1

8
w4 75 60 55 55 2

4

• Is X a Martingale ?

Counter example to prove that X is not a martingale:

85, 𝑖𝑓 𝜔 ∈ 𝐴1 𝐴1 ∈ {𝜔1 }
85, 𝑖𝑓 𝜔 ∈ 𝐴2 𝐴 ∈ {𝜔2 }
𝐸[𝑋3 / 𝐹2 ] = { , 𝑤𝑖𝑡ℎ { 2
75, 𝑖𝑓 𝜔 ∈ 𝐴3 𝐴3 ∈ {𝜔3 }
55, 𝑖𝑓 𝜔 ∈ 𝐴4 𝐴4 ∈ {𝜔4 }

So 𝐸[𝑋3/F 2] = 𝑋3 ≠ 𝑋2

 Then X is not a martingale because if it were then 𝐸[𝑋3/F 2] must be equal to 𝑋2

• So if we made 𝐸[𝑋3/F 2] = 𝑋2 will it make X a martingale?

W X0(w) X1(w) X2(w) X3(w) P


w1 75 80 85 85 1

4
w2 75 80 75 75 1

8
w3 75 60 75 75 1

8
w4 75 60 55 55 2

4

46
To prove that X is a martingale we need to go case by case for each one of three properties:

i. 𝑬[|𝑿𝒕 |] < ∞ , ∀ 𝒕 ≥ 𝟎

1 1 1 2
✓ 𝐸(𝑋0 ) = 4 × 75 + 8 × 75 + 8 × 75 + 4 × 75 = 75 < ∞

1 1 1 2
✓ 𝐸(𝑋1 ) = 4 × 80 + 8 × 80 + 8 × 60 + 4 × 60 = 67.5 < ∞

1 1 1 2
✓ 𝐸(𝑋2 ) = × 85 + × 75 + × 75 + × 55 = 67.5 < ∞
4 8 8 4

✓ 𝐸(𝑋3 ) = 67.5 < ∞

 The 1st property is checked.

ii. 𝑿 is adapted to the filtration 𝔽, meaning that 𝑿𝒕 is F 𝒕 -measurable , ∀ 𝒕 ≥ 𝟎

F0 = {∅, Ω}
F1 = 𝜎({𝜔1 , 𝜔2 }, {𝜔3 , 𝜔4 })
✓ 𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by X:
F2 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })
{F 3 = 𝜎({𝜔1 }, {𝜔2 }, {𝜔3 }, {𝜔4 })

 We defined 𝔽 as generated by X so by definition X is adapted (The 2sd property is


checked).

iii. 𝑬[𝑿𝒕 /F 𝒔 ] = 𝑿𝒔 , ∀ 𝟎 ≤ 𝒔 ≤ 𝒕

𝐸[𝑋0 /F 0 ] = 𝐸(𝑋0 ) = 75 = 𝑋0

𝐸[𝑋1 /F 0 ] = 𝐸(𝑋1 ) = 67.5 ≠ 𝑋0

 The 3rd property did not hold.

 Then X is not a martingale because if it were then 𝐸[𝑋1/F 0] must be equal to 𝑋0

3. Additional Exercises

1) Show that a sum of martingales is a martingale.

Solution:

47
2) Let 𝑋𝑖 be a sequence of identically distributed random variables with common distribution
𝑎 𝑤𝑖𝑡ℎ 𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑦 𝑝1
𝑋𝑖 = {
−𝑏 𝑤𝑖𝑡ℎ 𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑦 𝑝2 = 1 − 𝑝1
where 0 ≤ a,b. Let 𝑆𝑛 = ∑𝑛𝑖=1 𝑋𝑖

Under what conditions on a, b, 𝑝1, , 𝑝2 𝑆𝑛 𝑖𝑠 𝑎 𝑚𝑎𝑟𝑡𝑖𝑛𝑔𝑎𝑙𝑒?

Solution:

Property 1:

We need to ensure that the expected value of the sum of 𝑆𝑛 is finite for any time t≥0.

Since each 𝑋𝑖 takes values a or -b, and 𝑝1 and 𝑝2 are probabilities, |a| and |b| must be finite.

Property 2: Adaptation to Filtration 𝑭𝒕

𝑋𝑖 is 𝐹𝑡 −measurable since it is directly observed at time i and independent of future events.


Hence the sum of 𝑋𝑖 is 𝐹𝑡 -mesurable.

Property 3:

𝐸[𝑆𝑡 | 𝐹𝑠 ] = 𝐸[∑𝑠𝑖=1 𝑋𝑖 + ∑𝑡𝑖=𝑠+1 𝑋𝑖 |𝐹𝑠 ]


= 𝐸[∑𝑠𝑖=1 𝑋𝑖 |𝐹𝑠 ] + 𝐸[∑𝑡𝑖=𝑠+1 𝑋𝑖 |𝐹𝑠 ]
= 𝑆𝑠 + ∑𝑡𝑖=𝑠+1 𝑋𝑖
= 𝑆𝑠 + (𝑡 − 𝑠)( 𝑝1 𝑎 − 𝑝2 𝑏)
Now, equating this to 𝑆𝑠 :
𝑆𝑠 = 𝑆𝑠 + (𝑡 − 𝑠)( 𝑝1 𝑎 − 𝑝2 𝑏)
Thus 𝑡 − 𝑠 = 0 (𝑤ℎ𝑖𝑐ℎ 𝑖𝑠 𝑛𝑜𝑡 𝑚𝑒𝑎𝑛𝑖𝑛𝑔𝑓𝑢𝑙 𝑖𝑛 𝑡ℎ𝑖𝑠 𝑐𝑜𝑛𝑡𝑒𝑥𝑡)
Or ( 𝑝1 𝑎 − 𝑝2 𝑏) = 0
Therefore 𝑆𝑛 is a martingale if:
• |a| and |b| are finite.
𝑝2 𝑏 (1−𝑝1) 𝑏 𝑏
• 𝑝1 𝑎 − 𝑝2 𝑏 = 0 thus 𝑎 = 𝑝1
= 𝑝1
=𝑝 −𝑏
1

48
Python Time !

Flipping Expectations: A Visual Journey Through Fairness and Chance in


Martingale Theory:
Let’s simulate a classic martingale process through a coin flip game, where a player's wealth
changes by winning or losing 1 unit with each flip. The initial wealth was set to 10 units. To test
the martingale property, we ran 100 simulations of the game, each consisting of 100 coin flips.
The results were plotted to visualize the wealth trajectory over time for a subset of these
simulations. The key martingale property — that the expected value of a player's wealth at any
step equals their current wealth given all previous information — was examined by computing
the average conditional expectations across all simulations. The plot displayed the wealth
histories, which fluctuated around the initial wealth, and the average conditional expectations
remained close to the initial wealth line. The average ending wealth across all simulations was
10.6 units, indicating that the game is fair and supports the martingale property, as it did not
significantly deviate from the initial wealth. This outcome demonstrates that despite the short-
term fluctuations in wealth, the game, when averaged over many plays, neither systematically
profits nor loses, which is characteristic of a fair game.

import numpy as np
import matplotlib.pyplot as plt

def coin_flip() :
return np.random.choice ( ['heads', 'tails'] )

# Simulate a martingale - a fair coin flip game


def simulate_martingale(wealth, n_flips) :
wealth_history = [wealth]
for _ in range ( n_flips ) :
flip_result = coin_flip ()
if flip_result == 'heads' :
wealth += 1 # Win 1 unit
else :
wealth -= 1 # Lose 1 unit
wealth_history.append ( wealth )
return wealth_history

# Function to test if a game is fair


def test_martingale(wealth_history) :
# Calculate conditional expectations
conditional_expectations = [np.mean ( wealth_history[:i + 1] ) for i
in range ( len ( wealth_history ) )]
return conditional_expectations

49
# Initial wealth and number of flips
initial_wealth = 10
num_flips = 100
num_simulations = 100

# Simulate the game multiple times


all_wealth_histories = [simulate_martingale ( initial_wealth, num_flips
) for _ in range ( num_simulations )]

# Calculate the average ending wealth across all simulations


average_ending_wealth = np.mean ( [history[-1] for history in
all_wealth_histories] )

# Test for martingale property


all_conditional_expectations = [test_martingale ( history ) for history
in all_wealth_histories]
average_conditional_expectations = np.mean (
all_conditional_expectations, axis = 0 )

# Plotting
plt.figure ( figsize = (14, 7) )

# Plot wealth history of first few simulations


for history in all_wealth_histories[:10] :
plt.plot ( history, alpha = 0.6 )

plt.plot ( average_conditional_expectations, color = 'black', linewidth


= 2,
label = 'Average Conditional Expectations' )
plt.axhline ( y = initial_wealth, color = 'red', linestyle = '--', label
= 'Initial Wealth' )
plt.title ( 'Wealth Histories for Multiple Simulations of the Coin Flip
Game' )
plt.xlabel ( 'Number of Flips' )
plt.ylabel ( 'Wealth' )
plt.legend ()
plt.show ()

print("the average ending wealth:",average_ending_wealth, "the initial


wealth:",initial_wealth)

Discover the captivating world of finance through Python programming. Run the code
and witness the enchantment of what programming can unfold!

50
IV. Brownian Motion
Investire by the Botanical Lake

Investire waved to Mr. Ville and wandered


until he arrived at the Botanical17 Lake of
Capitalis. It was incredibly serene and calm;
the perfect spot to contemplate one's
reflection. He gazed at the surface of the
water and heard a mysterious voice say,
"This is your origin." Startled, Investire
inquired, "Who is speaking?" No reply
came, so he leaned closer to the water,
peered deeply into his reflection, and
gently tapped the surface with his finger hoping he would find someone. A ripple formed on
the water. Suddenly, the same voice commanded, "Do it again." Investire obeyed, and with
each touch, a new unique ripple emerged, forming intricate patterns. As Investire observed
how the ripples he created varied significantly from one another, yet their sizes mostly seemed
similar, he decided to mark the size of the ripples on the ground. To his amazement, the pattern
resembled the shape he had shown the door of Probare to escape - a bell shape!

While Investire marveled at his creation, the ripples transformed, shaping into an arrow on the
water's surface, as if guiding him somewhere. Hesitant, Investire stood up and followed the
direction indicated by the arrow. It led him to a massive apple tree near the lake. Investire
exclaimed, "Were you the one guiding me to touch the water?" In response, an apple fell from
the tree and landed on his head. Investire, perplexed, muttered, "Oh, Capitalis must be driving
me mad, talking to doors and trees."

To his astonishment, the apple spoke, "You're the one who determines the value of apples! Tell
me my worth, and I'll reveal why you're here." Investire, surprised, replied, "It was Finis, not
me, and I don't have my book to answer your question." The apple retorted, "But you can read
what was written on the water's surface, and I cannot. Drop me into the lake, and Iet me sink
in despair." Investire released the apple into the water, creating a larger ripple. This time, no
arrows appeared; instead, a number emerged. He hurried back to the apple tree and inquired,
"What does this number signify?" Another apple fell, hitting his head, and replied, "That
represents part of our future value, but not all of it."

Investire grabbed a handful of apples before any more could fall on his head and made his way
back to his library. He felt that he had taken yet another step toward unraveling the mysteries
of uncertainty.

Takeaway message

When Investire reached the lake, it was very serene, and just as the surface of water starts at
a calm place so does the Brownian Motion (𝑾𝟎 = 𝟎) and that is your origin too! The ripples
change over time, in a random way, just like random variables in a stochastic process. As
Investire was ordered to touch the surface of the water, he was creating new ripples, yet they

17
Remember that the Brownian motion, before it was explained formally by A. Einstein, was first
observed by Robert Brown the Botanist.
51
weren’t perfectly harmonious, in fact they differed and were independent of each other and
that is the independence of increments (the random variables 𝑊𝑡 − 𝑊𝑠 and 𝑊𝑙 − 𝑊𝑘 are
independent (independence of increments). Yet most ripples seemed to hover around a similar
size, echoing the principles of a normal distribution.

Exactly like the ripples Investire created with his fingers on the surface of the water,
randomness creates future values in the realm of Finance and in our fate as well. This pattern
we observe is still uncertain yet more tamable than absolute uncertainty and we can use it to
minimize doubt, that is the case of this specific stochastic process, the Brownian Motion.

The number that was shown on the water every time Investire drops the apple, is indeed part
of the future value of the apple. Why “part”, you ask? The result of the Brownian Motion is
incorporated into a pricing model to understand the market behavior of the asset_ we meant
apple; a pricing model like the one you are familiar with, the one and only: Black-Scholes-
Merton model.

Introduction

Brownian motion was introduced by the botanist Robert Brown. Its mathematics was
developed primarily by Norbert Wiener. That is why many times we symbolize the Brownian
process by the letter W.

Illustration : Brownian Motion - Definition, Example, Experiment, Applications

Definition Let (Ω , F , F , P) be a filtered probability space. The process 𝑊 = {𝑊𝑡 : 𝑡 ∈ 𝑇} is a


standard Brownian motion if:
i. 𝑊0 = 0
ii. ∀ 0 < 𝑘 < 𝑙 < 𝑠 < 𝑡 the random variables 𝑊𝑡 − 𝑊𝑠 and 𝑊𝑙 − 𝑊𝑘 are independent
(independence of increments)
iii. ∀ 0 < 𝑠 < 𝑡 𝑊𝑡 − 𝑊𝑠 ~𝑁(0, 𝑡 − 𝑠) (Normality of increments)
iv. ∀𝜔 ∈ Ω t ↦ Wt (ω) is continuous.

Illustration : Brownian Motion - Basic properties

Example 1.1: Let {𝑊𝑡 : 𝑡 ≥ 0} a standard Brownian motion. Is {𝑊𝑡+𝑠 − 𝑊𝑠 : 𝑡 ≥ 0} a Brownian


motion for any s > 0 ?

Let 𝑋𝑡 = 𝑊𝑡+𝑠 − 𝑊𝑠

i. Initial condition:

𝑋0 = 𝑊0+𝑠 − 𝑊𝑠 = 0 → 𝑿𝟎 = 𝟎

ii. Independence of increments:

For ∀ 0 < 𝑙 < 𝑘 < 𝑧 < 𝑡,

𝐶𝑜𝑣(𝑋𝑡 − 𝑋𝑧 ; 𝑋𝑘 − 𝑋𝑙 )

= 𝐶𝑜𝑣[(𝑊𝑡+𝑠 − 𝑊𝑠 ) − (𝑊.𝑧+𝑠 − 𝑊𝑠 ) ; (𝑊𝑘+𝑠 − 𝑊𝑠 ) − (𝑊𝑙+𝑠 − 𝑊𝑠 )]


52
= 𝐶𝑜𝑣[(𝑊𝑡+𝑠 −𝑊𝑧+𝑠 ) ; (𝑊𝑘+𝑠 − 𝑊𝑙+𝑠 )] let 𝑡 + 𝑠 = 𝑇, 𝑧 + 𝑠 = 𝑍, 𝑘 + 𝑠 = 𝐾 𝑎𝑛𝑑 𝑙 + 𝑠 = 𝐿

= 𝐶𝑜𝑣[(𝑊𝑇 −𝑊𝑍 ) ; (𝑊𝐾 − 𝑊𝐿 )] = 0, W is a Brownian motion so 𝑊𝑇 − 𝑊𝑍 and 𝑊𝐾 − 𝑊𝐿 are


independent.

→ 𝑿𝒕 − 𝑿𝒛 ; 𝑿𝒌 − 𝑿𝒍 are independent.

iii. Normality of increments:

For ∀ 0 < 𝑧 < 𝑡

W is a Brownian motion so 𝑊𝑡+𝑠 ~𝑁(0, 𝑡 + 𝑠) and 𝑊𝑧+𝑠 ~𝑁(0, 𝑧 + 𝑠)

𝐸(𝑋𝑡 − 𝑋𝑧 ) = 𝐸(𝑊𝑡+𝑠 − 𝑊𝑠 − 𝑊𝑧+𝑠 + 𝑊𝑠 ) )] = 𝐸(𝑊𝑡+𝑠 ) − 𝐸(𝑊𝑧+𝑠 ) = 0

𝑉𝑎𝑟(𝑋𝑡 − 𝑋𝑧 ) = 𝑉𝑎𝑟(𝑊𝑡+𝑠 − 𝑊𝑠 − 𝑊𝑧+𝑠 + 𝑊𝑠 ) )] let 𝑡 + 𝑠 = 𝑇, 𝑧 + 𝑠 = 𝑍 and

= 𝑉𝑎𝑟(𝑊𝑇 − 𝑊𝑍 ) = 𝑇 − 𝑍 = 𝑡 + 𝑠 − 𝑧 − 𝑠 = 𝑡 − 𝑧

→ 𝑿𝒕 − 𝑿𝒛 ~ 𝑵(𝟎, 𝒕 − 𝒛)

iv. Continuity

𝑋𝑡 = 𝑊𝑡+𝑠 − 𝑊𝑠 it is the sum of 2 continuous functions (𝑊 is Brownian motion) so 𝑋𝑡 (𝜔) is


continuous ∀𝜔 ∈ Ω 𝑡.

So {𝑾𝒕+𝒔 − 𝑾𝒔 : 𝒕 ≥ 𝟎} for any s > 0 is a Brownian Motion

Example 1.2 : Is a Brownian motion a martingale ?

𝑬[|𝑾𝒕 |] < ∞ , ∀ 𝒕 ∈ 𝑻 ?

i. 𝑬[|𝑾𝒕 |] < ∞ ?

We know that 𝑊 is a Brownian Motion so 𝑊𝑡 − 𝑊0 ~ 𝑁(0, 𝑡) and 𝑊0 = 0 so 𝑊𝑡 ~𝑁(0, 𝑡)

We need to compute 𝐸[|𝑊𝑡 |]

+∞ +∞ 1 1 𝑧2 +∞ 1 1 𝑧2
𝐸[|𝑊𝑡 |] = ∫ |𝑧|𝑓(𝑧)𝑑𝑧 = ∫ |𝑧| 𝑒−2 𝑡 𝑑𝑧 = 2 ∫ 𝑧 𝑒−2 𝑡 𝑑𝑧
−∞ −∞ √2𝜋𝑡 0 √2𝜋𝑡
1 𝑧2
+∞
√𝑡 − √2𝑡 √2𝑡
= [− 2𝑒 2 𝑡 ] =0+ = <∞
√2𝜋 0 √𝜋 √𝜋

 The 1st property of a Martingale is checked.

ii. By construction, W is F 𝒕 -measurable , ∀ 𝒕 ≥ 𝟎

𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by W, it means that W is F 𝑡 -measurable , ∀ 𝑡 ≥ 0.

 The 2nd property of a Martingale is checked.

53
iii. 𝑬[𝑾𝒕 /F 𝒔 ] = 𝑾𝒔 , ∀ 𝟎 ≤ 𝒔 ≤ 𝒕 ?

𝐸[𝑊𝑡 /F 𝑠 ] = 𝐸[𝑊𝑡 + 𝑊𝑠 − 𝑊𝑠 /F 𝑠 ]

= 𝐸[𝑊𝑡 − 𝑊𝑠 /F 𝑠 ) + 𝐸[𝑊𝑠 /F 𝑠 ] = [𝑊𝑡 − 𝑊𝑠 ] + 𝑊𝑠 and 𝐸[𝑊𝑡 − 𝑊𝑠 ] = 0

= 𝑊𝑠 = 𝑊𝑠
 The 3rd property of a Martingale is checked.

Example 1.3 : Let Z be a random variable that follows a standard normal distribution (0,1). Let
the stochastic process X defined by:

𝑋𝑡 = √𝑡𝑍 ∀ 𝑡 ≥ 0

Is X a Brownian motion?

Counter example to prove that X is not a Brownian Motion:

𝑋𝑡 − 𝑋𝑠 ~ 𝑁(0, 𝑡 − 𝑠) ?

𝑋𝑡 = √𝑡𝑍~ 𝑁(0, 𝑡)

𝑋𝑠 = √𝑠𝑍~ 𝑁(0, 𝑠)

Then 𝑋𝑡 − 𝑋𝑠 ~ 𝑁

▪ 𝐸[𝑋𝑡 − 𝑋𝑠 ] = 𝐸[𝑋𝑡 ] − 𝐸[𝑋𝑠 ] = 0


▪ 𝑉(𝑋𝑡 − 𝑋𝑠 ) = 𝑉(𝑋𝑡 ) + 𝑉(𝑋𝑠 ) − 2𝐶𝑜𝑣(𝑋𝑡 − 𝑋𝑠 ) = 𝑡 + 𝑠 − 2𝐶𝑜𝑣(√𝑡𝑍, √𝑠𝑍)
= 𝑡 + 𝑠 − 2 √𝑡 √𝑠 𝐶𝑜𝑣(𝑍, 𝑍) = 𝑡 + 𝑠 − 2 √𝑡 √𝑠
→ 𝑋𝑡 − 𝑋𝑠 ~ 𝑁(0, (𝑡 + 𝑠 − 2 √𝑡 √𝑠))

→ So X is not a Brownian motion because if it were then 𝑋𝑡 − 𝑋𝑠 ~ 𝑁(0, 𝑡 − 𝑠)

Example 1.4: Let X be the stochastic process that model the Brent price. X is a set of random
variables defined by:

𝑋𝑡 = 𝜎𝑊𝑡 ∀𝑡 ∈ 𝑇

Where W is a standard Brownian motion and 𝜎 is a fixed parameter.

Compute the expectation and the variance of 𝑿𝒕

o 𝐸[𝑋𝑡 ] = 𝐸[𝜎𝑊𝑡 ] = 𝜎𝐸[𝑊𝑡 ] = 0


o 𝑉(𝑋𝑡 ) = 𝑉(𝜎𝑊𝑡 ) = 𝜎 2 𝑉(𝑊𝑡 ) = 𝜎 2 𝑡

Is X a martingale?

To prove that X is a martingale we need to go case by case for each one of three properties of
a martingale:

54
i. 𝑬[|𝑿𝒕 |] < ∞ , ∀ 𝒕 ∈ 𝑻 ?

𝐸[|𝑋𝑡 |] = 𝐸[|𝜎𝑊𝑡 |] = |𝜎| 𝐸[|𝑊𝑡 |] < ∞ ?


We know that 𝑊 is a Brownian Motion so 𝑊𝑡 − 𝑊0 ~ 𝑁(0, 𝑡) and 𝑊0 = 0 so 𝑊𝑡 ~𝑁(0, 𝑡)
𝐸[|𝑊𝑡 |] < ∞? We need to compute 𝐸[|𝑊𝑡 |]
+∞ +∞ 1 1 𝑧2 +∞ 1 1 𝑧2
𝐸[|𝑊𝑡 |] = ∫ |𝑧|𝑓(𝑧)𝑑𝑧 = ∫ |𝑧| 𝑒−2 𝑡 𝑑𝑧 = 2 ∫ 𝑧 𝑒−2 𝑡 𝑑𝑧
−∞ −∞ √2𝜋𝑡 0 √2𝜋𝑡
1 𝑧2
+∞
√𝑡 √2𝑡 √2𝑡
= [− 2 𝑒 −2 𝑡 ] =0+ = <∞
√2𝜋 0 √𝜋 √𝜋

 The 1st property of a Martingale is checked.

ii. 𝑿 is adapted to the filtration 𝔽, meaning that 𝑿𝒕 is F 𝒕 -measurable , ∀ 𝒕 ≥ 𝟎 ?

𝔽 = {Ft ∶ 𝒕 ∈ 𝑻} generated by W, it means that 𝑋𝑡 is F 𝑡 -measurable , ∀ 𝑡 ≥ 0 because 𝑋𝑡 =


𝜎𝑊𝑡 ∀𝑡 ∈ 𝑇, so by construction X is adapted to the filtration 𝔽.

 The 2nd property is checked.

iii. 𝑬[𝑿𝒕 /F 𝒔 ] = 𝑿𝒔 , ∀ 𝟎 ≤ 𝒔 ≤ 𝒕 ?

𝐸[𝑋𝑡 /F 𝑠 ] = 𝐸[𝜎𝑊𝑡 /F 𝑠 ] = 𝜎𝐸[𝑊𝑡 /F 𝑠 ] = 𝜎(𝐸[𝑊𝑡 + 𝑊𝑠 − 𝑊𝑠 /F 𝑠 ])

= 𝜎(𝐸[𝑊𝑡 − 𝑊𝑠 /F 𝑠 ) + 𝐸[𝑊𝑠 /F 𝑠 ]) = 𝜎(𝐸[𝑊𝑡 − 𝑊𝑠 ] + 𝑊𝑠 ) and 𝐸[𝑊𝑡 − 𝑊𝑠 ] = 0

= 𝜎𝑊𝑠 = 𝑋𝑠
 The 3rd property of a Martingale is checked.

Homework: Let {𝑊𝑡 : 𝑡 ≥ 0} a standard Brownian motion. Are the following examples Brownian
motions ? Provide a proof or a counter example.

{−𝑊𝑡 : 𝑡 ≥ 0}

{𝑐𝑊 𝑡 : 𝑡 ≥ 0} c being a scalar.


𝑐2

Solution:

{−𝑊𝑡 : 𝑡 ≥ 0}

Answer:

i. −𝑊0 = 𝑾𝟎 = 𝟎 the first property of a Brownian motion holds.


ii. ∀, 0 < 𝑘 < 𝑙 < 𝑠 < 𝑡, we need to check that −𝑊𝑡 − (−𝑊𝑠 ) and −𝑊𝑙 − (−𝑊𝑘 ) are
independent
𝐶𝑜𝑣[(−𝑊𝑡 − (−𝑊𝑠 )); ( −𝑊𝑙 − (−𝑊𝑘 ))] = 𝐶𝑜𝑣[−(𝑊𝑡 − 𝑊𝑠 ); −(𝑊𝑙 − 𝑊𝑘 ) ]
= 𝐶𝑜𝑣[(𝑊𝑡 − 𝑊𝑠 ); (𝑊𝑙 − 𝑊𝑘 ) ] = 0 Because W is a Brownian motion so 𝑊𝑡 − 𝑊𝑠 and 𝑊𝑙 −
𝑊𝑘 are independent.
→ So −𝑾𝒕 − (−𝑾𝒔 ) and −𝑾𝒍 − (−𝑾𝒌 ) are independent
iii. 𝐹𝑜𝑟 𝑡 > 𝑠 > 0,

55
−𝑊𝑡 − (−𝑊𝑠 ) = −(𝑊𝑡 −𝑊𝑠 )
W is a Brownian motion so (𝑊𝑡 −𝑊𝑠 )~𝑁(0, 𝑡 − 𝑠) , 𝑊𝑡 ~𝑁(0, 𝑡) and 𝑊𝑠 ~𝑁(0, 𝑠)
𝐸(−(𝑊𝑡 −𝑊𝑠 )) = 𝐸(−𝑊𝑡 ) + 𝐸(𝑊𝑠 ) = −𝐸(𝑊𝑡 )+𝐸(𝑊𝑠 ) = 0
𝑉𝑎𝑟(−(𝑊𝑡 −𝑊𝑠 )) = (−1)2 𝑉𝑎𝑟(𝑊𝑡 −𝑊𝑠 ) = 𝑉𝑎𝑟(𝑊𝑡 −𝑊𝑠 ) = 𝑡 − 𝑠
→ −𝑾𝒕 − (−𝑾𝒔 ) = −(𝑾𝒕 −𝑾𝒔 ) ~𝑵(𝟎, 𝒕 − 𝒔)
iv. ∀𝜔 ∈ Ω 𝑡 ⟼ 𝑊𝑡 (𝜔) is continuous −𝑊𝑡 = −(1) × 𝑊𝑡 so ∀𝜔 ∈ Ω 𝑡 ⟼ −𝑊𝑡 (𝜔) is
continuous.

So {−𝑾𝒕 : 𝒕 ≥ 𝟎} is a Brownian motion.

{𝑐𝑊 𝑡 : 𝑡 ≥ 0} c being a scalar.


𝑐2

Answer:

Let 𝑋𝑡 = 𝑐𝑊 𝑡 , 𝑡 ≥ 0 and c a scalar.


𝑐2

• 𝑋0 = 𝑐𝑊 0 = 𝑐𝑊0 = 0 → 𝑋0 = 0
𝑐2

• For ∀ 0 < 𝑙 < 𝑘 < 𝑠 < 𝑡,


𝐶𝑜𝑣(𝑋𝑡 − 𝑋𝑠 ; 𝑋𝑘 − 𝑋𝑙 )

= 𝐶𝑜𝑣[(𝑐𝑊 𝑡 − 𝑐𝑊 𝑠 ) ; (𝑐𝑊 𝑘 − 𝑐𝑊 𝑙 )]
𝑐2 𝑐2 𝑐2 𝑐2

𝑡 𝑠 𝑘 𝑙
= 𝑐 2 . 𝐶𝑜𝑣[(𝑊 𝑡 − 𝑊 𝑠 ) ; (𝑊 𝑘 − 𝑊 𝑙 )] let = 𝑇, = 𝑆, = 𝐾 𝑎𝑛𝑑 =𝐿
𝑐2 𝑐2 𝑐2 𝑐2
𝑐2 𝑐2 𝑐2 𝑐2

= 𝑐 2 . 𝐶𝑜𝑣[(𝑊𝑇 −𝑊𝑆 ) ; (𝑊𝐾 − 𝑊𝐿 )] = 0 (W is Brownian motion so its increments are independent)

→ 𝑋𝑡 − 𝑋𝑠 ; 𝑋𝑘 − 𝑋𝑙 are independent.

• For ∀ 0 < 𝑠 < 𝑡


𝑡 𝑠
𝐸(𝑋𝑡 − 𝑋𝑠 ) = 𝐸(𝑐𝑊 𝑡 − 𝑐𝑊 𝑠 ) )] let 𝑐2
= 𝑇, 𝑐 2 = 𝑆 and W is a Brownian Motion.
𝑐2 𝑐2

= 𝑐𝐸(𝑊𝑇 − 𝑊𝑆 ) = 0

𝑡 𝑠
𝑉𝑎𝑟(𝑋𝑡 − 𝑋𝑠 ) = 𝑉𝑎𝑟(𝑐𝑊 𝑡 − 𝑐𝑊 𝑠 ) )] , W is a Brownian Motion so 𝑊 𝑡 − 𝑊 𝑠 ~𝑁(0, − )
𝑐2 𝑐2 𝑐2 𝑐2 𝑐2 𝑐2

𝑡 𝑠
= 𝑉𝑎𝑟 (𝑐(𝑊 𝑡 − 𝑊 𝑠 )) = 𝑐 2 𝑉𝑎𝑟 (𝑊 𝑡 − 𝑊 𝑠 ) = 𝑐 2 (𝑐 2 − 𝑐 2 ) = 𝑡 − 𝑠
𝑐2 𝑐2 𝑐2 𝑐2

→ 𝑋𝑡 − 𝑋𝑠 ~ 𝑁(0, 𝑡 − 𝑠)

56
• 𝑋𝑡 = 𝑐𝑊 𝑡 and c a scalar, the product of a continuous function with a constant is also
𝑐2

continuous so 𝑋𝑡 is continuous .

→∀𝜔 ∈ Ω 𝑡 ⟼ 𝑋𝑡 (𝜔) is continuous.

So {𝒄𝑾 𝒕 : 𝒕 ≥ 𝟎} c being a scalar is a Brownian Motion.


𝒄𝟐

̃ be two independent Brownian Motions and 𝜌 a constant contained


Example 1.5: Let 𝑊 and 𝑊
̃ . The stochastic process 𝑋 =
in the unit interval. For all 𝑡 ≥ 0, let 𝑋𝑡 = 𝜌𝑊𝑡 + √1 − 𝜌2 𝑊
{𝑋𝑡 : 𝑡 ≥ 0} has a continuous path and ∀𝑡 ≥ 0, 𝑋𝑡 ~𝑁(0, 𝑡). Is 𝑋 a Brownian Motion? Justify.

Answer: X is Brownian Motion, justification:

𝑊0 =0 & ̃
𝑊0 =0
i. ̃0 →
𝑋0 = 𝜌𝑊0 + √1 − 𝜌2 𝑊 𝑿𝟎 = 𝟎.
ii. ∀ 0 < 𝑘 < 𝑙 < 𝑠 < 𝑡, we need to show that 𝑋𝑡 − 𝑋𝑠 and 𝑋𝑙 − 𝑋𝑘 are independent:
𝐶𝑜𝑣[𝑋𝑡 − 𝑋𝑠 ; 𝑋𝑙 − 𝑋𝑘 ]
̃𝑡 − 𝜌𝑊𝑠 − √1 − 𝜌2 𝑊
= 𝐶𝑜𝑣[(𝜌𝑊𝑡 + √1 − 𝜌2 𝑊 ̃𝑠 ); (𝜌𝑊𝑙 + √1 − 𝜌2 𝑊
̃𝑙 − 𝜌𝑊𝑘 −

̃𝑘 )]
√1 − 𝜌2 𝑊
̃𝑡 − 𝑊
= 𝐶𝑜𝑣[ 𝜌(𝑊𝑡 − 𝑊𝑠 ) + √1 − 𝜌2 (𝑊 ̃𝑠 ) ; 𝜌(𝑊𝑙 − 𝑊𝑘 ) + √1 − 𝜌2 (𝑊
̃𝑙 − 𝑊
̃𝑘 )]

̃𝑙 − 𝑊
= 𝜌2 𝐶𝑜𝑣[𝑊𝑡 − 𝑊𝑠 ; 𝑊𝑙 − 𝑊𝑘 ] + 𝜌√1 − 𝜌2 𝐶𝑜𝑣[𝑊𝑡 − 𝑊𝑠 ; 𝑊 ̃𝑘 ]

̃𝑡 − 𝑊
+𝜌√1 − 𝜌2 𝐶𝑜𝑣[𝑊 ̃𝑠 ; 𝑊𝑙 − 𝑊𝑘 ] + (1 − 𝜌2 )𝐶𝑜𝑣[𝑊
̃𝑡 − 𝑊
̃𝑠 ; 𝑊
̃𝑙 − 𝑊
̃𝑘 ]

=0

→ So the increment 𝑿𝒕 − 𝑿𝒔 and 𝑿𝒍 − 𝑿𝒌 are independent,


Because:
̃ are independent so 𝐶𝑜𝑣[𝑊𝑡 − 𝑊𝑠 ; 𝑊
𝑊 and 𝑊 ̃𝑙 − 𝑊
̃𝑘 ] & 𝐶𝑜𝑣[𝑊
̃𝑡 − 𝑊
̃𝑠 ; 𝑊𝑙 − 𝑊𝑘 ] are

equal to 0.
𝑊 is a Brownian motion so 𝑊𝑡 − 𝑊𝑠 ; 𝑊𝑙 − 𝑊𝑘 are independent so 𝐶𝑜𝑣[𝑊𝑡 − 𝑊𝑠 ; 𝑊𝑙 −
𝑊𝑘 ] = 0
̃ is a Brownian motion so 𝑊
𝑊 ̃𝑡 − 𝑊
̃𝑠 ; 𝑊
̃𝑙 − 𝑊
̃𝑘 are independent so 𝐶𝑜𝑣[𝑊
̃𝑡 − 𝑊
̃𝑠 ; 𝑊
̃𝑙 −
̃𝑘 ] = 0
𝑊

iii. We need to check that ∀ 0 < 𝑠 < 𝑡, 𝑋𝑡 − 𝑋𝑠 ~𝑁(0, 𝑡 − 𝑠)

̃𝑡 − 𝑊
We have, 𝑋𝑡 − 𝑋𝑠 = 𝜌(𝑊𝑡 − 𝑊𝑠 ) + √1 − 𝜌2 (𝑊 ̃𝑠 )

𝑊 is a Brownian motion so 𝑊𝑡 − 𝑊𝑠 ~𝑁(0, 𝑡 − 𝑠) → 𝜌(𝑊𝑡 − 𝑊𝑠 ) ~ 𝑁(0, 𝜌2 (𝑡 − 𝑠))


̃ is a Brownian motion so 𝑊
𝑊 ̃𝑡 − 𝑊
̃𝑠 ~𝑁(0, 𝑡 − 𝑠) → √1 − 𝜌2 (𝑊
̃𝑡 − 𝑊
̃𝑠 ) ~ 𝑁(0, (1 −

𝜌2 )(𝑡 − 𝑠))

57
→ So 𝑋𝑡 − 𝑋𝑠 ~ 𝑁
o Var[𝑋𝑡 − 𝑋𝑠 ] = 𝑡 − 𝑠 ?
̃𝑡 − 𝑊
= 𝑉𝑎𝑟[ 𝜌(𝑊𝑡 − 𝑊𝑠 ) + √1 − 𝜌2 (𝑊 ̃𝑠 )]

̃𝑡 − 𝑊
= 𝑉𝑎𝑟[ 𝜌(𝑊𝑡 − 𝑊𝑠 )] + 𝑉𝑎𝑟[√1 − 𝜌2 (𝑊 ̃𝑠 )] + 2. 𝐶𝑜𝑣[[ 𝜌(𝑊𝑡 − 𝑊𝑠 ); √1 − 𝜌2 (𝑊
̃𝑡 − 𝑊
̃𝑠 )]

̃𝑡 − 𝑊
= 𝜌2 𝑉𝑎𝑟( 𝑊𝑡 − 𝑊𝑠 ) + (1 − 𝜌2 )𝑉𝑎𝑟(𝑊 ̃𝑠 ) + 2. 𝜌. √1 − 𝜌2 . 𝐶𝑜𝑣[ (𝑊𝑡 − 𝑊𝑠 ); (𝑊
̃𝑡 − 𝑊
̃𝑠 )]

= 𝜌2 (𝑡 − 𝑠) + (1 − 𝜌2 )(𝑡 − 𝑠) − 0 = 𝑡 − 𝑠
→ 𝑉𝑎𝑟[𝑋𝑡 − 𝑋𝑠 ] = 𝑡 − 𝑠
̃𝑡 − 𝑊
NB: 𝐶𝑜𝑣[ (𝑊𝑡 − 𝑊𝑠 ); (𝑊 ̃𝑠 ) = 𝐶𝑜𝑣(𝑊𝑡 ; 𝑊
̃𝑡 ) − 𝐶𝑜𝑣(𝑊𝑡 ; 𝑊
̃𝑠 ) − 𝐶𝑜𝑣(𝑊𝑠 ; 𝑊
̃𝑡 ) + 𝐶𝑜𝑣(𝑊𝑠 ; 𝑊
̃𝑠 ) = 0
̃ are two independent Brownian motions.
because 𝑊 and 𝑊
o 𝐸[𝑋𝑡 − 𝑋𝑠 ] = 0?
̃𝑡 − 𝑊
𝐸[𝑋𝑡 − 𝑋𝑠 ] = 𝜌𝐸[𝑊𝑡 − 𝑊𝑠 ] + √1 − 𝜌2 𝐸[𝑊 ̃𝑠 ] = 0
→ So 𝑿𝒕 − 𝑿𝒔 ~ 𝑵(𝟎, 𝒕 − 𝒔)
𝜌 𝑖𝑠 𝑎 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡
iv. ̃𝑡 (𝜔) are continuous →
∀𝜔 ∈ Ω 𝑡 ⟼ 𝑊𝑡 (𝜔) and 𝑊 so 𝑋𝑡 = 𝜌𝑊𝑡 +
̃𝑡 is continuous.
√1 − 𝜌2 𝑊
→ ∀𝝎 ∈ 𝛀 𝒕 ⟼ 𝑿𝒕 (𝝎) is continuous.

Example 1.6 : Let W be a Brownian motion. Show that 𝐶𝑜𝑣 [𝑊𝑡 ; 𝑊𝑠 ] = min(s; t)
Solution:
Without lost of generality, let 0 < s < t
𝐶𝑜𝑣 [𝑊𝑡 ; 𝑊𝑠 ]
=𝐶𝑜𝑣 [𝑊𝑡 − 𝑊𝑠 + 𝑊𝑠 ; 𝑊𝑠 ]
=𝐶𝑜𝑣 [𝑊𝑡 − 𝑊𝑠 ; 𝑊𝑠 ] + 𝐶𝑜𝑣 [𝑊𝑠 ; 𝑊𝑠 ]
=𝐶𝑜𝑣 [𝑊𝑡 − 𝑊𝑠 ; 𝑊𝑠 − 𝑊0 ] + 𝑉𝑎𝑟[𝑊𝑠 ]
=0+s (the increment of W are independent)
= min(s,t) since s < t

Python Time !

Stock's Journey Through Brownian Motion: A Python Tale:


Our Python code models a stock's price over time using Geometric Brownian Motion. By
simulating random daily price changes, we created a series of potential paths for a stock that
starts at $100. Each simulation is like peering into a crystal ball with a probabilistic gaze, offering
a glimpse into one of the myriad paths a stock's price could take, all guided by the invisible
hand of market sentiment and global events, distilled into the parameters of drift and volatility.

58
import numpy as np
import matplotlib.pyplot as plt
# Set the parameters for the simulation
mu = 0.05 # drift coefficient
sigma = 0.2 # diffusion coefficient
S0 = 100 # initial stock value
T = 1.0 # time horizon
N = 252 # number of steps (trading days in a year)
dt = T/N # time step
t = np.linspace(0, T, N) # time array
# Function to simulate one path of Geometric Brownian Motion
def simulate_gbm(S0, mu, sigma, dt, N):
S = np.zeros(N)
S[0] = S0
for i in range(1, N):
Z = np.random.standard_normal()
S[i] = S[i-1] * np.exp((mu - 0.5 * sigma**2) * dt + sigma *
np.sqrt(dt) * Z)
return S

# Generate and plot multiple paths


num_paths = 5
plt.figure(figsize=(12, 6))

for _ in range(num_paths):
S = simulate_gbm(S0, mu, sigma, dt, N)
plt.plot(t, S)

plt.title('Simulated Geometric Brownian Motion Paths for Stock Prices')


plt.xlabel('Time (Years)')
plt.ylabel('Stock Price')
plt.grid(True)
plt.show()
# Calculate the expected end price and its standard deviation
end_prices = [simulate_gbm(S0, mu, sigma, dt, N)[-1] for _ in
range(10000)]
expected_end_price = np.mean(end_prices)
std_dev_end_price = np.std(end_prices)
print(expected_end_price, std_dev_end_price)
Unleash your curiosity and step into the realm of imagination! Experience the awe
inspiring visualization of a Brownian motion "wild animal" by running the Python
code!

59
V. Stochastic Calculus

Investire’s Library Became a Ballroom

[…] On his way back to his library,


Investire heard the villagers whispering, “This is
the boy who managed to create the greatest
library in Capitalis”. He felt very proud because
finally, his library was officially recognized by all
the villagers to be the Greatest Library of all
time.

To celebrate his dream coming true, the


bookworm decided to hold a party in his library to which he would invite the whole village to
eat, dance and share this huge celebration. On the invitation letters, Investire wrote “When the
Sun rises come to the Sun’s Origin18 and Dance freely for there the next step need not be known.”

When the dawn broke, the library turned into a ballroom, crowded with people, and
filled with music. Investire stood on the first floor, contemplating his empire of books, and
admiring how people are moving harmoniously and dancing on the floor. The more he
observed the dancers, the more puzzled he got and once again Investire found himself
wandering in the Playground of Randomness:

As the dancers moved from one place to another, Investire didn’t know the direction they were
heading in. He quickly realized he was in front of a stochastic process that reminded him of the
time he read the tome and how you can escape randomness with a thread of knowledge.

However, this process felt different because more dancers were joining the rest and
Investire knew for sure they were doing the Valse dance at that time; so, the moves were
expected to a certain extent. The young boy said “I know where they are, what they’re doing
but I don’t know where they are going. This has an element of certainty and chaos at the same
time”. Investire raised his head to the ceiling thinking about this puzzle. And, when he looked
back at the dancers, they were all over the place, and under no circumstances was he able to
guess what he saw. Investire thought, “I raised my head, and when I looked back down, I was
lost. I would've never guessed the next change that was about to happen because, again, at the
core of the puzzle lies fluctuations and randomness, of where the dancers were heading to.”

As he was trying to find what certainty mixed with chaos resulted in, the musicians
changed the melody, and the dancers started to move vigorously as if they were jumping. A
very vibrant and energetic atmosphere reigned in the library. The dance was still the same
process, but somehow more intense. Investire found himself focused on where they were
heading more than the overall dance. In other words, when the dancers were almost jumping,
the moves of the Valse were almost insignificant compared to where they were dancing. It was

18
“The Origin of the Sun”, or “Nippon” is the name that was given to Japan in the medieval times that
reflects its location to the east of China. Here we want you to always relate dancing, as a stochastic process,
to the Japanese mathematician Kiyoshi Ito.
60
as if the regular elements no longer mattered as much as chaos because what Investire cared
about then were the jumps.

Investire almost completely disregarded the fact that the dancers were doing the Valse
and observed them in their chaotic nature. Yet even then, within chaos lay order; some dancers
jumping in ecstasy seemed to do so smoothly and harmoniously, as if they danced together
and their chaos also "co-varied together."

Investire pondered, "What about the dancers who aren't as skilled or struggle to move
smoothly together? How important are they in the dance?" So, he observed the overall scene
and quickly understood that regardless of whether they coordinated or not, every dancer and
every dance influenced one another. If one dancer saw another heading in a particular
direction, they would adjust their own moves to avoid collisions.

As much as Investire enjoyed the performance of the guests he despised, as always,


the feeling of uncertainty that never stopped from getting bigger and bigger. He left his guests
dancing and checked his spell book...

Takeaway Message:

The dance was indeed a stochastic process, but more specifically an Ito process. This process
_or dance or (𝑿𝒕 )_ was defined on the same initial probability filtered space ((Ω , F , F, P))
Investire came up with in his library. And Investire wasn’t mistaken with his observation;
predicting where the dance will lead in the upcoming moments included and required knowing
where they are now (𝑿𝟎 ), along with the regular change suggested by the usual movements
𝒕
of the Valse dance (∫𝟎 𝑲𝒔 𝒅𝒔 ), and with the random surprises of where the dancers would
𝒕
decide to go (∫𝟎 𝑯𝒔 𝒅𝑾𝒔 ). The fact that just upon turning his head and then looking back again,
the outcome of the dance (this Ito process) was very unpredictable, captures the complexities
of the randomness of this process. To deal with it we have to (1) consider it over an
infinitesimally small-time interval and (2) to admit that we cannot predict the rate of change
because this process is inherently influenced by random fluctuations. Once (1) and (2) are
understood, we can solve this problem using the differential form of the process 𝒅𝑿𝒕 =
𝒅𝒇
𝑲𝒕 𝒅𝒕 + 𝑯𝒕 𝒅𝑾𝒕 re-differentiating it again gives us Ito’s Lemma: 𝒅𝒇(𝑿𝒕 , 𝒕) = 𝒅𝒙 (𝑿𝒕 , 𝒕)𝒅𝑿𝒕 +
𝒅𝒇 𝟏 𝝏𝟐 𝒇
(𝑿𝒕 , 𝒕)𝒅𝒕 + (𝑿𝒕 , 𝒕)𝒅〈𝑿〉𝒕 . When the music changed, the dancers were still dancing, so
𝒅𝒕 𝟐 𝝏𝒙𝟐
we were still in front of an Ito process. But Investire cared less about the regular element of
𝒕
the process (∫𝟎 𝑲𝒔 𝒅𝒔 ), and focused on the chaotic element of it that seemed to varied
significantly. And that’s how the Ito Process became a quadratic variation 〈𝑋〉𝑡 =
𝑡
∫0 𝐻𝑠 2 𝑑𝑠 ∀ 𝑡 ∈ 𝑇 that can also be written in its differential form for the same reasons.

When Investire felt that within all that jumping and chaos there was a taste of synchronization
between the dances, he noticed that two Ito processes, taken into consideration at the same
time can display smoothness and that covariation in chaos is exactly the Quadratic Covariation:
𝑡
〈𝑋, 𝑌〉𝑡 = ∫0 𝜌𝐻𝑡 𝐿𝑡 𝑑𝑠 ∀𝑡 ∈ 𝑇 which again can be written in its differential form. But what
about the other dancers and the other dances? In fact the idea of how one dancer heading to
one location influenced the reluctance of another to go to the same place depicts how dancers

61
or random variables affect one another and the Multiplication Theorem translates this
relationship between random variables.

1. Ito Process

Definition: Let 𝑋 = {𝑋𝑡 ∶ 𝑡 ∈ T} be a stochastic process on the probability filtered


space (Ω , F , F, P). X is an Itô process if we can write it as:
𝑡 𝑡
𝑋𝑡 = 𝑋0 + ∫ 𝐾𝑠 𝑑𝑠 + ∫ 𝐻𝑠 𝑑𝑊𝑠
0 0
Where 𝐾 = {𝐾𝑡 ∶ 𝑡 ∈ T} and 𝐻 = {𝐻𝑡 ∶ 𝑡 ∈ T} satisfy the following properties:
𝑡 𝑡
𝑃 [∫0 |𝐾𝑠 | 𝑑𝑠 < ∝] = 1 and 𝑃 [∫0 |𝐻𝑠 |2 𝑑𝑠 < ∝] = 1
When we computed in a differential form, we get:
𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡

Example 1.1: Geometric Brownian Motion:

𝑑𝑋𝑡 = 𝐾𝑡 𝑋𝑡 𝑑𝑡 + 𝐻𝑡 𝑋𝑡 𝑑𝑊𝑡

Example 1.2: Vasicek Model (1977)

𝑑𝑋𝑡 = 𝜅(𝜃 − 𝑟𝑡 )𝑑𝑡 + 𝜎𝑑𝑊𝑡

Example 1.3: Cox–Ingersoll–Ross model

𝑑𝑋𝑡 = 𝜅(𝜃 − 𝑟𝑡 )𝑑𝑡 + 𝜎√𝑟𝑡 𝑑𝑊𝑡

2. Quadratic variation

Definition: Let X be an Itô process, i.e.


𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡
The quadratic variation process is the process 〈𝑋〉 = {〈𝑋〉𝑡 ∶ 𝑡 ∈ T} such that:
𝑡
〈𝑋〉𝑡 = ∫ 𝐻𝑠 2 𝑑𝑠 ∀ 𝑡 ∈ 𝑇
0
We can also write it in its differentiate form:
𝑑〈𝑋〉𝑡 = 𝐻𝑡 2 𝑑𝑡 ∀ 𝑡 ∈ 𝑇

Example 2.1: Vasicek model:

𝑑𝑋𝑡 = 𝜅(𝜃 − 𝑟𝑡 )𝑑𝑡 + 𝜎𝑑𝑊𝑡

𝑑〈𝑋〉𝑡 = 𝜎2 𝑑𝑡 ∀ 𝑡 ∈ 𝑇

Example 2.2: Geometric Brownian Motion

𝑑𝑋𝑡 = 𝐾𝑡 𝑋𝑡 𝑑𝑡 + 𝐻𝑡 𝑋𝑡 𝑑𝑊𝑡
2
𝑑〈𝑋〉𝑡 = (𝐻𝑡 𝑋𝑡 ) 𝑑𝑡 ∀ 𝑡 ∈ 𝑇

62
Example 2.3: Cox–Ingersoll–Ross model:

𝑑𝑋𝑡 = 𝜅(𝜃 − 𝑟𝑡 )𝑑𝑡 + 𝜎√𝑟𝑡 𝑑𝑊𝑡

𝑑〈𝑋〉𝑡 = 𝜎2 𝑟𝑡 𝑑𝑡 ∀ 𝑡 ∈ 𝑇

3. Itô’s Lemma

Lemma: Let X be an Itô process, i.e.


𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡
Let f be a function that has continuous first and second derivatives then ∀ 𝑡 ∈ 𝑇 we
have:
𝑡 𝑡
𝜕𝑓 𝜕𝑓 1 𝑡 𝜕2𝑓
𝑓(𝑋𝑡 , 𝑡) − 𝑓(𝑋0 , 0) = ∫ (𝑋𝑠 , 𝑠)𝑑𝑋𝑠 + ∫ (𝑋𝑠 , 𝑠)𝑑𝑠 + ∫ (𝑋 , 𝑠)𝑑〈𝑋〉𝑠
0 𝜕𝑥 0 𝜕𝑡 2 0 𝜕𝑥 2 𝑠
In a differential form, we get:
𝑑𝑓 𝑑𝑓 1 𝜕2𝑓
𝑑𝑓(𝑋𝑡 , 𝑡) = (𝑋𝑡 , 𝑡)𝑑𝑋𝑡 + (𝑋𝑡 , 𝑡)𝑑𝑡 + (𝑋 , 𝑡)𝑑〈𝑋〉𝑡
𝑑𝑥 𝑑𝑡 2 𝜕𝑥 2 𝑡

Example 3.1: Let the stock price of Tesla be following a geometric Brownian motion:

𝑑𝑆𝑡 = 𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡

Let f be the following function:

𝑓(𝑥) = 𝐿𝑜𝑔 (𝑥)

Compute 𝑑𝑓(𝑆𝑡 , 𝑡)

𝑑𝑓 𝑑𝑓 1 𝜕2𝑓
𝑑𝑓(𝑆𝑡 , 𝑡) = (𝑆𝑡 , 𝑡)𝑑𝑆𝑡 + (𝑆𝑡 , 𝑡)𝑑𝑡 + (𝑆 , 𝑡)𝑑〈𝑆〉𝑡
𝑑𝑥 𝑑𝑡 2 𝜕𝑥 2 𝑡

1 1 1
𝑑𝑓(𝑆𝑡 , 𝑡) = 𝑑𝑆 + 0 + (− 2 ) 𝑑〈𝑆〉𝑡
𝑆𝑡 𝑡 2 𝑆𝑡

1 1 1
𝑑𝑓(𝑆𝑡 , 𝑡) = (𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡 ) + (− 2 ) (𝜎²𝑆𝑡2 𝑑𝑡)
𝑆𝑡 2 𝑆𝑡

1
𝑑𝑓(𝑆𝑡 , 𝑡) = (𝜇𝑑𝑡 + 𝜎𝑑𝑊𝑡 ) − 𝜎 2 𝑑𝑡
2
1
𝑑𝑓(𝑆𝑡 , 𝑡) = ( 𝜇 − 𝜎 2 )𝑑𝑡 + 𝜎𝑑𝑊𝑡
2

Using the result above, can you solve for 𝑆𝑡

1
𝑑𝑙𝑜𝑔(𝑆𝑡 ) = ( 𝜇 − 𝜎 2 )𝑑𝑡 + 𝜎𝑑𝑊𝑡
2
𝑡 𝑡
1
∫ 𝑑𝑙𝑜𝑔(𝑆𝑡 ) = ∫ ( 𝜇 − 𝜎 2 )𝑑𝑡 + 𝜎𝑑𝑊𝑡
0 0 2
𝑡
1
𝑙𝑜𝑔(𝑆𝑡 ) − 𝑙𝑜𝑔(𝑆0 ) = ∫ ( 𝜇 − 𝜎 2 )𝑑𝑡 + 𝜎𝑑𝑊𝑡
0 2
63
1
𝑙𝑜𝑔(𝑆𝑡 ) − 𝑙𝑜𝑔(𝑆0 ) = ( 𝜇 − 𝜎 2 )𝑡 + 𝜎𝑊𝑡
2
1
𝑆𝑡 = 𝑆0 exp (( 𝜇 − 𝜎 2 )𝑡 + 𝜎𝑊𝑡 )
2

Now you can compute the value of a call option that has a payoff:

𝐶𝑡 = max (𝑆𝑡 − K, 0)

The value of the call option at time 0 is:

𝐶0 = 𝐸[exp (−𝑟𝑡)𝐶𝑡 /F 0 ]

Homework: Compute the value of 𝐶0

Hint: the answer is Black and Scholes (1973)

Answer:

We are looking to compute 𝐶0 = 𝐸[𝑒 −𝑟𝑇 𝐶𝑇 ] with 𝐶𝑇 = max (𝑆𝑇 − K, 0)

𝜎2
And we know 𝑆𝑇 = 𝑆0 𝑒 (( 𝜇− 2 )𝑇+𝜎𝑊𝑇 )

So
𝐶0 = 𝑒 −𝑟𝑇 𝐸[max(𝑆𝑇 − K, 0)] = 𝑒 −𝑟𝑇 𝐸[(𝑆𝑇 − K)1{𝑆𝑇 >𝐾} ]

So this will be divided into two parts

𝚰, 𝐶0 = 𝑒 −𝑟𝑇 𝐸[(𝑆𝑇 )1{𝑆𝑇 >𝐾} ]

And 𝚰𝚰, 𝐶0 = −𝑒 −𝑟𝑇 𝐸[(𝐾)1{𝑆𝑇 >𝐾} ]

Part 𝚰𝚰:

𝚰𝚰 = −𝑒 −𝑟𝑇 𝐾. 𝐸[1{𝑆𝑇 >𝐾} ] = −𝑒 −𝑟𝑇 𝐾. 𝑃[𝑆𝑇 > 𝐾]

𝜎2
(( 𝜇− 2 )𝑇+𝜎𝑊𝑇 )
𝑃[𝑆𝑇 > 𝐾] = 𝑃 [𝑆0 𝑒 > 𝐾]

1
= 𝑃 [ ( 𝜇 − 𝜎 2 )𝑇 + 𝜎𝑊𝑇 > ln(𝐾/𝑆0 )]
2
1
ln(𝐾/𝑆0 ) − (𝜇 − 2 𝜎 2 ) 𝑇 𝑊𝑇
= 𝑃 [ (𝑊𝑇 ≥ ] we know that 𝑊𝑇 ~𝑁(0, 𝑇) 𝑠𝑜 ~𝑁(0,1)
𝜎 √𝑇

1 1
ln(𝐾/𝑆0 ) − (𝜇 − 2 𝜎 2 ) 𝑇 ln(𝐾/𝑆0 ) − (𝜇 − 2 𝜎 2 ) 𝑇
= 𝑃 [ (𝑍 ≥ ] let α =
𝜎√𝑇 𝜎√𝑇

= 𝑃[ (𝑍 ≥ α] = 1 − 𝑃[ (𝑍 < α] = 𝑃[ (𝑍 < −α]

64
So
1
ln(𝑆0 /𝐾)+(𝜇− 𝜎 2 )𝑇
−𝑟𝑇 2
𝚰𝚰 = −𝑒 𝐾.𝑃[ (𝑍 < −α] with −α = 𝜎 √𝑇

Part 𝚰

𝚰 = 𝑒 −𝑟𝑇 𝐸[(𝑆𝑇 )1{𝑆𝑇 >𝐾} ]

𝜎2
So we need to find out when 𝑆𝑇 = 𝑆0 𝑒 (( 𝜇− 2 )𝑇+𝜎𝑊𝑇 ) > 𝐾 ?

𝜎2 1
𝑆0 𝑒 (( 𝜇− 2 )𝑇+𝜎𝑊𝑇 ) ≥ 𝐾 → (𝜇 − 𝜎 2 ) 𝑇 + 𝜎𝑊𝑇 ≥ ln(𝐾/𝑆0 ) → 𝑊𝑇
2
1
ln(𝐾/𝑆0 ) − (𝜇 − 2 𝜎 2 ) 𝑇

𝜎
𝜎2
−𝑟𝑇 +∞ ( 𝜇− 2 )𝑇+𝜎𝑤
𝚰=𝑒 𝑆0 ∫−∞ 𝑒 𝑓(𝑤) 1{𝑊>α√𝑇} 𝑑𝑤 → 𝚰=
1
+∞ − 𝜎 2 𝑇+𝜎𝑊
𝑒 −(𝑟−𝜇)𝑇 𝑆0 ∫α 𝑒 2 𝑓(𝑤)𝑑𝑤

1 1 𝑤2
with 𝑓(𝑤) = 𝑒−2 𝑇
√2𝜋𝑇
+∞ 2 +∞
1 1 2 𝑇+𝜎𝑊−1 𝑊 1 1 2 𝑇 2 −2𝜎𝑇𝑊+ 𝑊 2 )
∫ 𝑒 − 2𝜎 2 𝑇 𝑑𝑤 = ∫ 𝑒 − 2𝑇(𝜎 𝑑𝑤
α√𝑇 √2𝜋𝑇 α√𝑇 √2𝜋𝑇
+∞
1 1 2
=∫ 𝑒 − 2𝑇(𝑊−𝜎𝑇) 𝑑𝑤
α√𝑇 √2𝜋𝑇

Let 𝑊 ′ = (𝑊 − 𝜎𝑇)/ √𝑇

And α′ = (α√𝑇 − 𝜎𝑇)/ √𝑇= α − 𝜎√𝑇

So
+∞
1 − 1(𝑊′)2
∫ 𝑒 2 𝑑𝑊 ′ = 𝑃[ (𝑍 ≥ α′ ] = 𝑃[ (𝑍 < −α′ ]
α′ √2𝜋

So 𝚰 = 𝑒 −(𝑟−𝜇)𝑇 𝑆0 . 𝑃[ 𝑍 < −α′ ]


𝑆 1 𝑆 1
ln( 0 )+(𝜇− 𝜎 2 )𝑇 ln( 0 )+(𝜇+ 𝜎 2 )𝑇
with −α′ = − α + 𝜎√𝑇 = 𝐾
𝜎 √𝑇
2
+ 𝜎√𝑇 = 𝐾
𝜎 √𝑇
2

In the case of Black-Scholes 𝝁 = 𝒓


1
ln(𝑆0 /𝐾)+(𝑟− 𝜎 2 )𝑇
Part 𝚰𝚰 becomes 𝚰𝚰 = −𝑒 −𝑟𝑇 𝐾.𝑃[ (𝑍 < −α] with −α = 𝜎 √𝑇
2
=𝑑2

65
𝑆 1
ln( 0 )+(𝑟+ 𝜎 2 )𝑇
Part 𝚰 becomes 𝚰 = 𝑒 −(𝑟−𝑟)𝑇 𝑆0 . 𝑃[ (𝑍 < −α′ ] = 𝑆0 . 𝑃[ (𝑍 < −α′ ] with −α′ = 𝐾
𝜎 √𝑇
2
=
𝑑1

Note that 𝑑2 = 𝑑1 − 𝜎√𝑇

And the general BS formula is 𝐶 = 𝑆. 𝑁(𝑑1 )−𝑒 −𝑟𝑇 𝐾. 𝑁(𝑑2 )

Example 3.2: Given the geometric Brownian motion:

𝑑𝑆𝑡 = 𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡

Let f be the following function:

𝑓(𝑥) = 𝑥 2

Compute 𝑑𝑓(𝑆𝑡 , 𝑡)

𝑑𝑓 𝑑𝑓 1 𝜕2𝑓
𝑑𝑓(𝑆𝑡 , 𝑡) = (𝑆𝑡 , 𝑡)𝑑𝑆𝑡 + (𝑆𝑡 , 𝑡)𝑑𝑡 + (𝑆 , 𝑡)𝑑〈𝑆〉𝑡
𝑑𝑥 𝑑𝑡 2 𝜕𝑥 2 𝑡
1
𝑑𝑓(𝑆𝑡 , 𝑡) = 2𝑆𝑡 𝑑𝑆𝑡 + 0 + (2)𝑑〈𝑆〉𝑡
2

𝑑𝑓(𝑆𝑡 , 𝑡) = 2𝑆𝑡 (𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡 ) + 𝜎²𝑆𝑡2 𝑑𝑡

𝑑𝑓(𝑆𝑡 , 𝑡) = 2𝜇𝑆𝑡 2 𝑑𝑡 + 2𝜎𝑆𝑡 2 𝑑𝑊𝑡 + 𝜎²𝑆𝑡2 𝑑𝑡


2
𝑑𝑓(𝑆𝑡 , 𝑡) = (2𝜇 + 𝜎 2 )𝑆𝑡 𝑑𝑡 + 2𝜎𝑆𝑡 2 𝑑𝑊𝑡

Example 3.3:

Let f be the following function:

𝑓(𝑥) = 𝑥 2

Apply Itô’s lemma on f(𝑊𝑡 )

1
𝑑𝑓(𝑊𝑡 ) = 2 𝑊𝑡 𝑑𝑊𝑡 + × 2𝑑𝑡 = 2 𝑊𝑡 𝑑𝑊𝑡 + 𝑑𝑡
2
𝑡 𝑡
∫ 𝑑𝑊𝑡2 = ∫ 2 𝑊𝑡 𝑑𝑊𝑡 + 𝑑𝑡
0 0

𝑡 𝑡
𝑊𝑡2 − 𝑊02 = 2 ∫ 2 𝑊𝑡 𝑑𝑊𝑡 + ∫ 𝑑𝑡
0 0

𝑡
𝑊𝑡2 = 2 ∫ 2 𝑊𝑡 𝑑𝑊𝑡 + 𝑡
0

66
𝑡
1
∫ 𝑊𝑡 𝑑𝑊𝑡 = (𝑊𝑡2 − 𝑡)
0 2

4. Quadratic covariation

Definition: Let X and Y two Itô processes such that:


𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡 , 𝑑𝑌𝑡 = 𝐽𝑡 𝑑𝑡 + 𝐿𝑡 𝑑𝑊 ̃𝑡 and 𝜌(𝑊𝑡 , 𝑊
̃𝑡 ) = 𝜌
𝑑𝑌𝑡 can be rewritten as:
𝑑𝑌𝑡 = 𝐽𝑡 𝑑𝑡 + 𝐿𝑡 [𝜌𝑑𝑊𝑡 + √1 − 𝜌2 𝑑𝑍𝑡 ]
The quadratic covariation is the stochastic process 〈𝑋, 𝑌〉 defined by:
𝑡
〈𝑋, 𝑌〉𝑡 = ∫ 𝜌𝐻𝑡 𝐿𝑡 𝑑𝑠 ∀𝑡 ∈ 𝑇
0
̃𝑡 , then 𝜌 = 1, and the quadratic covariation 〈𝑋, 𝑌〉 is:
Special Case: When 𝑊𝑡 = 𝑊
𝑡
〈𝑋, 𝑌〉𝑡 = ∫ 𝐻𝑡 𝐿𝑡 𝑑𝑠 ∀𝑡 ∈ 𝑇
0

5. Multiplication theorem

Theorem: Let X and Y two Itô processes such that:


𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡 and 𝑑𝑌𝑡 = 𝐽𝑡 𝑑𝑡 + 𝐿𝑡 𝑑𝑊𝑡
Then

𝒅𝑿𝒕 𝒀𝒕 = 𝑿𝒕 𝒅𝒀𝒕 + 𝒀𝒕 𝒅𝑿𝒕 + 𝒅〈𝑿, 𝒀〉𝒕

Example 5.1: Let S be the stock price of Microsoft (MSFT) in US dollars. S is given by:

𝑑𝑆𝑡 = 𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡

Let X be the exchange rate USD/EUR. X is given by:

𝑑𝑋𝑡 = 𝛼𝑋𝑡 𝑑𝑡 + 𝛽𝑋𝑡 𝑑𝑊𝑡

Write the Stochastic Differential Equation (SDE) of the process Y that gives the stock price of
MSFT in EUR.

𝑌𝑡 = 𝑋𝑡 × 𝑆𝑡

𝑑𝑌𝑡 = 𝑋𝑡 𝑑𝑆𝑡 + 𝑆𝑡 𝑑𝑋𝑡 + 𝑑〈𝑆, 𝑋〉𝑡

𝑑𝑌𝑡 = 𝑋𝑡 (𝜇𝑆𝑡 𝑑𝑡 + 𝜎𝑆𝑡 𝑑𝑊𝑡 ) + 𝑆𝑡 (𝛼𝑋𝑡 𝑑𝑡 + 𝛽𝑋𝑡 𝑑𝑊𝑡 ) + 𝛽𝜎𝑋𝑡 𝑆𝑡 𝑑𝑡

𝑑𝑌𝑡 = 𝜇𝑌𝑡 𝑑𝑡 + 𝜎𝑌𝑡 𝑑𝑊𝑡 + 𝛼𝑌𝑡 𝑑𝑡 + 𝛽𝑌𝑡 𝑑𝑊𝑡 + 𝛽𝜎𝑌𝑡 𝑑𝑡

𝑑𝑌𝑡 = (𝜇+𝛼 + 𝛽𝜎)𝑌𝑡 𝑑𝑡 + (𝛽 + 𝜎)𝑌𝑡 𝑑𝑊𝑡

Let 𝑎 = (𝜇 + 𝛼 + 𝛽𝜎) and 𝑏 = (𝛽 + 𝜎) Then

𝑑𝑌𝑡 = 𝑎𝑌𝑡 𝑑𝑡 + 𝑏𝑌𝑡 𝑑𝑊𝑡 which can be solved as geometric Brownian Motion

Example 5.2:
67
Let the oil price given by:

𝑋 = {𝑋𝑡 , 𝑡 ≥ 0} such that 𝑑𝑋𝑡 = 𝜇𝑋𝑡 𝑑𝑡 + 𝜎𝑋𝑡 𝑑𝑊𝑡

and let the discounting factor:

𝛽 = {𝛽𝑡 , 𝑡 ≥ 0} such that 𝛽𝑡 = 𝑒 −𝑟𝑡

Write the SDE of the process Y that gives the discounted value of the oil price.

𝑌𝑡 = 𝛽𝑡 𝑋𝑡

𝑑𝑌𝑡 = 𝑑𝛽𝑡 𝑋𝑡

𝑑𝑌𝑡 = 𝛽𝑡 𝑑𝑋𝑡 + 𝑋𝑡 𝑑𝛽𝑡 + 𝑑〈𝛽, 𝑋〉𝑡

𝑑𝑌𝑡 = 𝛽𝑡 (𝜇𝑋𝑡 𝑑𝑡 + 𝜎𝑋𝑡 𝑑𝑊𝑡 ) + 𝑋𝑡 𝑑𝛽𝑡 + 𝑑〈𝛽, 𝑋〉𝑡

We have:

𝑑𝛽𝑡
o 𝛽𝑡 = 𝑒 −𝑟𝑡 so = −𝑟𝑒 −𝑟𝑡 = −𝑟𝛽𝑡
𝑑𝑡
o 𝑑〈𝛽, 𝑋〉𝑡 = 0 × 𝜎𝑋𝑡 𝑑𝑡 = 0 because there is no Brownian motion with respect to 𝛽 (it is not
stochastic it is just a function of time).

So

𝑑𝑌𝑡 = 𝛽𝑡 (𝜇𝑋𝑡 𝑑𝑡 + 𝜎𝑋𝑡 𝑑𝑊𝑡 ) + 𝑋𝑡 (−𝑟𝛽𝑡 ) + 0

𝑑𝑌𝑡 = (𝜇 − 𝑟)𝑌𝑡 𝑑𝑡 + 𝜎𝑌𝑡 𝑑𝑊𝑡

6. Itô Isometry

Itô Isometry: Let X be an Itô processes such that:


𝑑𝑋𝑡 = 𝐾𝑡 𝑑𝑡 + 𝐻𝑡 𝑑𝑊𝑡
Then

𝑻 𝟐 𝑻
𝑬 [(∫ 𝑯𝒔 𝒅𝑾𝒔 ) ] = 𝑬 [∫ 𝑯𝒔 𝟐 𝒅𝒔]
𝟎 𝟎

Exam Problem:

Use your stochastic calculus skills to price a chooser option. A chooser option is an option
contract that allows the holder to decide whether it is a call or put prior to the expiration
date. The payoff of a chooser option is the following:

𝑃𝐶𝑡 = max (𝐾 − 𝑋𝑡 , 𝑋𝑡 − 𝐾)

Assuming X follows the following Stock Differential Equation:

dX 𝑡 = rX 𝑡 dt + σdW𝑡

68
Find the value of the chooser option at time 0. Show the details of your calculations.

Exam problem:

You are providing consultancy to a client about exotic derivatives. The client has expressed
discomfort with the unpredictability of returns associated with European call options and
would prefer a predetermined payout if their prediction were correct.

In response, you propose a cash-or- nothing binary call option, which offers the buyer a
predetermined payout if the stock price exceeds the strike price at the end of the contract.

Let K be the strike price and L the amount will be paid by the binary option. In other words, if
the stock price exceeds K at maturity, the payoff of the call is L.

Assuming the stock price follows the following Stock Differential Equation (SDE)

𝑑𝑋𝑡 = 𝑟𝑋𝑡 𝑑𝑡 + 𝜎𝑋𝑡 𝑑𝑊𝑡

Where r is the risk-free rate and W is a standard Brownian motion.

v. Solve the SDE above and find the distribution of the stochastic process of 𝑋𝑇
vi. Write the cash-or-nothing European binary call option payoff equation.
vii. Find the value of the European binary call option at time 0 that is maturity at time T
with a strike k and binary cash L. Show the details of your calculations.
viii. Use the payoff table to find the put call parity in the case of cash-or- nothing options.
Draw the graph of both payoffs (call and put).
ix. Use the put call parity to find the value of cash-or-nothing binary put option at time 0.

69
The Spell book summarizes Processes

Takeaway message

[…] As he opened the spell book it said loud and clearly: "Investire, you've embarked on a busy
and adventurous journey. Remember this: whether it's the twist in the next chapter of the book,
the ripples on the surface of the lake, or the dancers gracefully moving in the Valse, you've been
equipped with various tools to foresee the future value of your books. The next book you read
will help you navigate the uncertain terrain of randomness. Don't confine yourself to applying
knowledge only to its source; don't limit Brownian motion to ripples or martingales solely to the
game. Think beyond boundaries, and remember, you possess tools, not rules. Your creativity
knows no bounds; these are instruments, not constraints. Before you close me, share some of
the books in your library with the guests.” Investire said smiling “I didn’t know that my spell
book will admit that sharing is caring!”; the book replied “It's not just sharing; lending reveals
the true worth of people. It shows you whose friendship is reliable and whose is not. Also even
lending can be monetized and risky".

70
VI. Credit Risk Modeling

Credit risk modeling stands as a pivotal aspect of modern financial analysis, offering tools to
assess the likelihood of a borrower defaulting on a debt obligation. It encompasses a range of
methodologies, with structural models and reduced form models being two principal
approaches.

Structural models, rooted in the principles of corporate finance and options pricing theory,
approach credit risk by analyzing a company's capital structure. They posit that default occurs
when a firm's liabilities exceed its assets. These models view a company's equity as a call option
on its assets, thereby integrating the volatility of the assets and the level of debt into the
assessment. This approach allows for a dynamic evaluation of default risk, considering both
current financial states and potential future scenarios. The Merton model is a classic example
of this approach, offering insights into how market value of equity and debt levels interplay in
determining credit risk.

Reduced form models, on the other hand, take an empirical approach. Rather than focusing on
the balance sheet dynamics, these models assess default risk based on observable market data
and historical default rates. They treat default as a random process, often independent of the
firm's economic fundamentals, and focus on modeling the intensity of default. This method
allows for the incorporation of various market-driven factors and credit spreads, thus providing
a different perspective on credit risk.

Both structural and reduced form models offer valuable insights and are used extensively in
financial institutions for risk assessment, portfolio management, pricing of credit-sensitive
instruments, and for regulatory compliance purposes. Their integration offers a comprehensive
understanding of credit risk, addressing different aspects and scenarios of default risk in the
complex financial landscape.

While structured credit models are essentially used for trend predictions and forecasting,
reduced form models are more used in calibration and asset pricing.

1. Structural models

Structural credit models in finance represent a crucial component in understanding credit risk.
These models are built on the foundation of analyzing the financial structure and health of a
company to assess its creditworthiness. At the heart of structural credit models lies the concept
that a firm's likelihood of default is intrinsically linked to its assets' value compared to its
liabilities. When a company's liabilities surpass its assets, the risk of default becomes
significantly higher.

These models draw heavily from the principles of corporate finance and option pricing theory,
viewing a company's equity as a call option on its assets. This perspective allows for a more
nuanced assessment of default risk, factoring in the volatility of the company's assets and the
level of its debt obligations. By incorporating these elements, structural credit models provide
a dynamic framework for analyzing the default risk, considering both the firm's current financial
state and potential future scenarios.

71
In practice, these models are instrumental for investors, risk managers, and financial analysts.
They offer vital insights into the health of various debt instruments, guide investment decisions,
shape risk management strategies, and support regulatory compliance. As financial markets
evolve, the importance and complexity of structural credit models continue to grow, making
them an essential tool in the arsenal of modern finance professionals.

a. Merton (1974)
The Merton model, introduced in 1974 by economist Robert C. Merton, is a seminal framework
in the field of structured credit models. This pioneering approach revolutionized the
understanding of credit risk by applying concepts from option pricing theory to corporate debt
analysis. At its core, the Merton model posits that a company's equity can be treated as a call
option on its assets, with the strike price equivalent to the debt's face value that must be repaid
at maturity.

In the Merton model, default risk is linked to the financial health of a company. It occurs when
the value of a firm's assets falls below the repayment threshold of its liabilities at the time of
debt maturity. This approach incorporates the volatility of the company's assets and the level
of its debt, providing a dynamic method to assess the probability of default. The model's
strength lies in its ability to translate market information, such as stock prices and their
volatility, into an estimate of credit risk.

As a pioneering structural model, the Merton model has had a profound impact on both
theoretical and practical aspects of finance. It laid the groundwork for the development of
more sophisticated credit risk models and remains a cornerstone in the analysis of corporate
default risk. Its principles are extensively used by financial institutions, investors, and analysts
for risk assessment, pricing of credit-sensitive securities, and for strategic corporate finance
decisions.

Let:

𝑺: a firm’s stock price

𝑩: bond price

𝑉: a firm’s value

𝑫: a firm’s debt

𝑉−𝐷 𝑖𝑓 𝑉 > 𝐷
𝑆={ |
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝐷 𝑖𝑓 𝑉 > 𝐷
𝐵={ |
𝑉 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

𝑆𝑡 = 𝑚𝑎𝑥(𝑉𝑡 − 𝐷, 0)

𝐵𝑡 = 𝑉𝑡 − 𝑚𝑎𝑥(𝑉𝑡 − 𝐷, 0) = 𝐷 − 𝑚𝑎𝑥(𝐷 − 𝑉𝑡 , 0)

72
Let’s Assume 𝑉 = {𝑉𝑡 ∶ 𝑡 ∈ T} the stochastic process that defines the value of the firm and
defined on the filtered space (Ω , F , 𝔽) where 𝔽 = {Ft ∶ 𝑡 ∈ 𝑇} the information coming from
the public market. We assume that 𝑉 follows the stochastic differential equation:

𝑑𝑉𝑡 = 𝜇𝑉𝑡 𝑑𝑡 + 𝜎𝑉𝑡 𝑑𝑊𝑡

Let 𝑓(𝑥) = log(𝑥), apply Itô’s Lemma to get 𝑉𝑡 :

1
𝑉𝑡 = 𝑉0 exp (( 𝜇 − 𝜎 2 )𝑡 + 𝜎𝑊𝑡 )
2

Default Probability:

1
𝐷𝑃 = 𝑃𝑡 (𝑉𝑇 < 𝐷) = 𝑃𝑡 (𝑉0 exp (( 𝜇 − 𝜎 2 )(𝑇 − 𝑡) + 𝜎(𝑊𝑇 − 𝑊𝑡 ) < 𝐷)
2

Let 𝑡 = 0

1
𝐷𝑃 = 𝑃0 (𝑉0 exp (( 𝜇 − 𝜎 2 )𝑇 + 𝜎𝑊𝑇 < 𝐷)
2
1
ln(𝐷/𝑉0 )−(𝜇− 𝜎 2 )𝑇 𝑊𝑇
2
𝐷𝑃 = 𝑃0 (𝑊𝑇 < ) we know that 𝑊𝑇 ~𝑁(0, 𝑇) 𝑠𝑜 ~𝑁(0,1)
𝜎 √𝑇

1
ln(𝐷/𝑉0 ) − (𝜇 − 2 𝜎 2 ) 𝑇
let α =
𝜎√𝑇

𝐷𝑃 = 𝑃0 (𝑍 < α) = Φ(α)

b. Black and Cox (1976)


The Black and Cox model, introduced in 1976 by Fischer Black and John C. Cox, is a significant
advancement in the field of credit risk modeling, building upon the foundational work of the
Merton (1974) model. This model is particularly notable for its introduction of a more realistic
feature into the assessment of default risk: the concept of early default or strategic default.

In contrast to the Merton model, where default can only occur at debt maturity, the Black and
Cox model allows for the possibility of default occurring at any time prior to maturity if the
value of the firm's assets falls below a certain threshold. This threshold is typically set at a level
where the firm's assets are just sufficient to cover the promised debt payments, taking into
account both interest and principal. This approach introduces a more dynamic and realistic
view of default, acknowledging that firms may choose to default strategically when it's
financially beneficial or unavoidable, rather than solely due to an inability to pay at maturity.

The Black and Cox model extends the application of option pricing theory to corporate debt,
considering both the timing and probability of default. This model has been influential in
shaping the understanding of credit risk, especially in high-yield debt markets. It provides a
more nuanced framework for evaluating the risk and pricing of corporate bonds, loans, and
other credit instruments. Its influence is seen in both academic research and practical
applications, particularly in the realm of risk management and structured finance.

73
Let’s Assume 𝑉 = {𝑉𝑡 ∶ 𝑡 ∈ T} the stochastic process that defines the value of the firm and
defined on the filtered space (Ω , F , 𝔽) where 𝔽 = {Ft ∶ 𝑡 ∈ 𝑇} the information coming from
the public market. We assume that 𝑉 follows the stochastic differential equation:

𝑑𝑉𝑡 = 𝜇𝑉𝑡 𝑑𝑡 + 𝜎𝑉𝑡 𝑑𝑊𝑡

Default Probability:

𝐷𝑃 = 𝑃[min(𝑉𝜏 < 𝐷)]


𝜏≤𝑇

2. Reduced form models

Reduced form models represent a fundamental approach in the realm of credit risk modeling,
contrasting with the balance-sheet-oriented structural models. These models, emerging in the
late 20th century, offer a distinct perspective by focusing on the empirical aspects of default
risk, rather than deriving risk from a firm's financial structure.

Central to reduced form models is the treatment of default as an exogenously driven, random
process, rather than as a deterministic outcome based on a company's asset and liability
structure. This approach considers default to be an unexpected event, influenced by a variety
of market factors and economic conditions, rather than solely by the firm's financial health. As
such, reduced form models incorporate a wide array of market-driven data, including credit
spreads, interest rates, and macroeconomic indicators, to assess the likelihood of default.

One of the key strengths of reduced form models is their flexibility and adaptability in capturing
the complexities and nuances of real-world credit markets. These models are particularly adept
at modeling the default risk of instruments where detailed balance sheet information is not
readily available or where market sentiment and external factors play a significant role.

In practice, reduced form models are extensively used in the pricing and risk assessment of
fixed-income securities, credit derivatives, and other credit-sensitive financial instruments.
Their empirical nature allows for the calibration of models to current market conditions,
making them invaluable tools for financial analysts, portfolio managers, and risk management
professionals in navigating the ever-evolving landscape of credit risk.

a. Poisson
𝑁 ~ 𝑃(𝜆) is a random variable said to have a Poisson distribution, with parameter 𝜆 > 0 , if it
has a probability mass function given by:

𝑒 −𝜆 𝜆𝑛
𝑃(𝑁 = 𝑛) =
𝑛!

Survival Probability: let 𝑛 = 0:

𝑆𝑃 = 𝑃(𝑁 = 0) = 𝑒 −𝜆

Default Probability:

𝐷𝑃 = 1 − 𝑆𝑃 = 1 − 𝑒 −𝜆

b. Time dependent Poisson


i. Constant 𝝀
74
𝑁 ~ 𝑃(𝜆𝑡) is a random variable said to be time dependent Poisson, with parameter
𝜆 > 0 , if it has a probability mass function given by:

𝑒 −𝜆𝑡 𝜆𝑡 𝑛
𝑃(𝑁 = 𝑛) =
𝑛!

Survival Probability: let 𝑛 = 0:

𝑆𝑃 = 𝑃(𝑁 = 0) = 𝑒 −𝜆𝑡

Default Probability:

𝐷𝑃 = 1 − 𝑆𝑃 = 1 − 𝑒 −𝜆𝑡

Let 𝐵(0, 𝑇) be the present value of zero-coupon bond such that:

𝐵(0, 𝑇) = 𝑁𝑒 −𝑟𝑇

And let SP and DP be the survival and default probabilities respectively

𝑖𝑓 𝑛𝑜 𝑑𝑒𝑓𝑎𝑢𝑙𝑡
𝐵̃(0, 𝑇) = {𝐵(0, 𝑇) |
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

𝐵̃(0, 𝑇) = 𝐵(0, 𝑇) ∗ 𝑆𝑃 + 0 ∗ 𝐷𝑃 = 𝐵(0, 𝑇) ∗ 𝑆𝑃

= 𝑁𝑒 −𝑟𝑇 ∗ 𝑒 −𝜆𝑡 = 𝑁𝑒 −(𝑟+𝜆)𝑇

ii. Function of time


𝑇
𝑁 ~ 𝑃(∫0 𝜆𝑠 𝑑𝑠)

Example 1:

Let 𝜆𝑠 = 𝑠
𝑇 𝑇
∫ 𝜆𝑠 𝑑𝑠 = ∫ 𝑠 𝑑𝑠 = 1⁄2 𝑡 2
0 0

Example 2:

Let:

𝑑𝜆𝑡 = 𝜅(𝜆̅ − 𝜆𝑡 )𝑑𝑡

Find 𝜆 𝑇

𝑒 𝜅𝑡 (𝑑𝜆𝑡 + 𝜅𝜆𝑡 𝑑𝑡) = 𝑒 𝜅𝑡 (𝜅𝜆̅ 𝑑𝑡)

𝑑(𝑒 𝜅𝑡 𝜆𝑡 ) = 𝑒 𝜅𝑡 (𝜅𝜆̅ 𝑑𝑡)


𝑇 𝑇
∫0 𝑑(𝑒 𝜅𝑡 𝜆𝑡 ) = ∫0 𝑒 𝜅𝑡 (𝜅𝜆̅ 𝑑𝑡)

𝑇 𝑇
∫0 𝑑(𝑒 𝜅𝑡 𝜆𝑡 ) = ∫0 𝑒 𝜅𝑡 (𝜅𝜆̅ 𝑑𝑡)

75
𝑒 𝜅𝑡 𝜆 𝑇 − 𝜆0 = [𝜆̅ 𝑒 𝜅𝑡 ]𝑇0

𝑒 𝜅𝑡 𝜆 𝑇 − 𝜆0 = 𝜆̅ 𝑒 𝜅𝑇 − 𝜆̅

𝜆 𝑇 = (𝜆0 − 𝜆̅ )𝑒 −𝜅𝑇 + 𝜆̅

c. 𝝀 is stochastic
N is a counting process that is doubly stochastic (Cox process).

𝑁 ~ 𝑃(𝜆𝑡 ) with 𝜆 = {𝜆𝑡 ∶ 𝑡 ∈ 𝑇}.

Example:

Vasicek:

𝑑𝑦𝑡 = 𝜅(𝜆̅ − 𝜆𝑡 )𝑑𝑡 + 𝜎𝑑𝑊𝑡

Python Time !

Automate Your Gains: Python-Powered Option Pricing with Black-


Scholes:
Let’s calculate the prices of European call and put options using the Black-Scholes formula.
Given the current stock price ($100), strike price ($100), time to expiration (1 year), risk-free
interest rate (5%), and stock volatility (20%), it outputs the price of a call option at
approximately $10.45 and a put option at approximately $5.57. This model assumes that the
stock price follows a certain type of random process and uses statistical probabilities to
determine the option prices.

76
import numpy as np
from scipy.stats import norm

# Define the Black-Scholes option pricing formula


def black_scholes(S, K, T, r, sigma, option_type="call"):
# Calculate the d1 and d2 parameters
d1 = (np.log(S / K) + (r + 0.5 * sigma**2) * T) / (sigma *
np.sqrt(T))
d2 = d1 - sigma * np.sqrt(T)

# Calculate the price of the option based on its type


if option_type == "call":
option_price = S * norm.cdf(d1) - K * np.exp(-r * T) *
norm.cdf(d2)
elif option_type == "put":
option_price = K * np.exp(-r * T) * norm.cdf(-d2) - S *
norm.cdf(-d1)
else:
raise ValueError("Invalid option type. Use 'call' or 'put'.")

return option_price

# Example parameters for an option


S = 100 # Current stock price ($)
K = 100 # Strike price ($)
T = 1 # Time to expiration (1 year)
r = 0.05 # Risk-free interest rate (5%)
sigma = 0.2 # Volatility (20%)

# Calculate call and put option prices


call_price = black_scholes(S, K, T, r, sigma, option_type="call")
put_price = black_scholes(S, K, T, r, sigma, option_type="put")

(call_price, put_price)

77
VII. Interest rate Modeling

Interest rate modeling is a critical aspect of financial mathematics, playing a vital role in the
pricing and risk management of fixed-income securities, derivatives, and various other financial
instruments. At its core, interest rate modeling involves developing mathematical frameworks
to understand, predict, and simulate the movements of interest rates over time. These models
are essential for accurately valuing financial products, managing interest rate risk, and
formulating effective investment strategies.

The complexity of interest rate modeling arises from the dynamic nature of interest rates,
which are influenced by a multitude of economic factors, including monetary policy, inflation
expectations, and market sentiment. Models must capture not only the current level of rates
but also their volatility and the structure of rate changes across different maturities, known as
the term structure of interest rates.

Historically, several foundational models have been developed, each with its own approach to
addressing these complexities. These include the Vasicek model, the Cox-Ingersoll-Ross (CIR)
model, and the Heath-Jarrow-Morton (HJM) framework, among others. Each model offers
unique insights and tools for dissecting the behavior of interest rates, catering to different
aspects of financial markets and instruments.

Interest rate models are indispensable in the modern financial landscape. They are employed
by banks, investment firms, and insurance companies for tasks such as pricing bonds and
interest rate derivatives, managing asset and liability portfolios, and assessing the overall
interest rate exposure of financial institutions. As financial markets evolve and interest rate
environments change, the development and refinement of these models continue to be a
significant area of research and innovation in financial engineering and risk management.

Short rate models

Short rate models hold a prominent position in the field of financial mathematics, specifically
in the realm of interest rate modeling. These models focus on the dynamic behavior of the
short-term interest rate, a key financial variable that influences a wide array of economic
activities and financial instruments. The 'short rate' refers to the instantaneous interest rate at
which financial institutions can borrow or lend funds for a very short duration, typically
overnight. Understanding and modeling this rate is crucial for valuing various financial
products, particularly those in the fixed-income and derivatives markets.

Short rate models aim to describe the future evolution of interest rates using stochastic
processes, which capture the random nature of interest rate movements. These models are
characterized by their simplicity and tractability, making them a popular choice for pricing
interest rate derivatives, such as bond options, interest rate swaps, and caps and floors.

Key models in this category include the Vasicek model, the Cox-Ingersoll-Ross (CIR) model, and
the Hull-White model, each differing in how they capture the volatility and mean-reversion

78
characteristics of interest rates. The Vasicek model, for example, is known for its mean-
reverting feature, where interest rates tend to move towards a long-term average over time.
The CIR model extends this by incorporating a volatility component that varies with the level
of the short rate, while the Hull-White model offers further flexibility in fitting the current term
structure of interest rates.

Short rate models are essential tools in the arsenal of financial analysts and risk managers. They
provide a framework for assessing the impact of interest rate changes on portfolios, pricing
complex financial instruments, and managing interest rate risk in an uncertain and ever-
evolving financial landscape.

Vasicek
The Vasicek model, introduced in 1977 by economist Oldrich Vasicek, is a pioneering short rate
model in the field of financial mathematics and interest rate modeling. It represents a
foundational approach to modeling the dynamics of interest rates, particularly focusing on the
short-term interest rate, which is a crucial component in the valuation of fixed-income
securities and interest rate derivatives.

At its core, the Vasicek model is characterized by its simplicity and elegance. It describes the
evolution of interest rates using a stochastic process known as mean reversion. This concept
suggests that interest rates tend to revert towards a long-term average level over time, a
behavior observed in many financial markets. The model is mathematically expressed through
a mean-reverting Ornstein-Uhlenbeck process, which combines elements of randomness with
a tendency to move towards an equilibrium level.

One of the key features of the Vasicek model is its ability to capture the risk structure of interest
rates and predict future movements based on current levels. It incorporates parameters that
represent the long-term mean interest rate, the speed of mean reversion, and the volatility of
interest rate movements. These parameters can be calibrated to fit market data, making the
model adaptable to different market conditions.

Despite its relative simplicity, the Vasicek model has had a profound impact on the field of
finance. It provides a framework for pricing various interest rate-sensitive financial
instruments, including bonds, caps, floors, and swaptions. Its influence extends beyond
theoretical finance, as it is widely used by banks, investment firms, and risk managers for
practical applications such as risk assessment, portfolio optimization, and strategic financial
planning. Over time, while more complex models have been developed, the Vasicek model
remains a cornerstone in the study and application of interest rate modeling.

𝑑𝑟𝑡 = 𝜅(𝜃 − 𝑟𝑡 )𝑑𝑡 + 𝜎𝑑𝑊𝑡

Find 𝑟𝑡 , 𝐸[𝑟𝑡 ], 𝑎𝑛𝑑 𝑉[𝑟𝑡 ]

i. 𝑟𝑡 :
𝑒 𝜅𝑡 (𝑑𝑟𝑡 + 𝜅𝑟𝑡 𝑑𝑡) = 𝑒 𝜅𝑡 (𝜅𝜃𝑑𝑡 + 𝜎𝑑𝑊𝑡 )

𝑑(𝑒 𝜅𝑡 𝑟𝑡 ) = 𝑒 𝜅𝑡 (𝜅𝜃𝑑𝑡 + 𝜎𝑑𝑊𝑡 )

79
𝑇 𝑇
∫ 𝑑(𝑒 𝑟𝑡 ) = ∫ 𝑒 𝜅𝑡 (𝜅𝜃𝑑𝑡 + 𝜎𝑑𝑊𝑡 )
𝜅𝑡
0 0
𝑇
𝑒 −𝜅𝑡 (𝑒 𝜅𝑡 𝑟𝑡 − 𝑟0 ) = 𝑒 −𝜅𝑡 (𝜃𝑒 𝜅𝑡 − 𝜃 + ∫ 𝑒 𝜅𝑡 𝜎𝑑𝑊𝑡 )
0
𝑇
𝑟𝑡 = (𝑟0 − 𝜃)𝑒 −𝜅𝑡 + 𝜃 + ∫ 𝑒 −𝜅(𝑇−𝑡) 𝜎𝑑𝑊𝑡 )
0
ii. 𝐸[𝑟𝑡 ]:
𝑇
𝐸[𝑟𝑡 ] = (𝑟0 − 𝜃)𝑒−𝜅𝑡 + 𝜃 + 𝐸 [∫ 𝑒−𝜅(𝑇−𝑡) 𝜎𝑑𝑊𝑠 )]
⏟0
0
iii. 𝑉[𝑟𝑡 ]:
𝑇
𝑉[𝑟𝑡 ] = ∫ 𝑒−𝜅(𝑇−𝑡) 𝜎𝑑𝑊𝑠 )
0
𝑇 2 𝑇 2
𝑉[𝑟𝑡 ] = 𝐸 [(∫ 𝑒−𝜅(𝑇−𝑡) 𝜎𝑑𝑊 𝑠 )) ] − 𝐸 [∫ 𝑒−𝜅(𝑇−𝑡) 𝜎𝑑𝑊 𝑠 )]
0 ⏟ 0
0
𝑢𝑠𝑖𝑛𝑔 𝐼𝑡ô 𝐼𝑠𝑜𝑚𝑒𝑡𝑟𝑦 :
𝑇
𝑉[𝑟𝑡 ] = 𝐸 [∫ 𝑒−2𝜅(𝑇−𝑡) 𝜎2 𝑑𝑠]
0

𝑇
𝑉[𝑟𝑡 ] = ∫ 𝑒−2𝜅(𝑇−𝑡) 𝜎2 𝑑𝑡
0

𝑇
−2𝜅𝑇
𝑉[𝑟𝑡 ] = 𝜎2 𝑒 ∫ 𝑒2𝜅𝑡 𝑑𝑡
0

−2𝜅𝑇
𝜎2 𝑒
𝑉[𝑟𝑡 ] = [𝑒2𝜅𝑇 − 1]
2𝜅
𝜎2
𝑉[𝑟𝑡 ] = [1 − 𝑒−2𝜅𝑇 ]
2𝜅

80
Takeaway Message from DAPT: Dynamic Asset Pricing Theory is More than a Subject.

If you are breathing and living, you are destined to be dynamic. This dynamism,
coupled with the concept of time, implies uncertainties in life. Understand that every
aspect of your life is influenced by probability and stochastic processes: from having a
friend choosing you a book like Investire, to picking a major like a TBSer, to dancing like
a Party freak, to selecting a life partner like a desperate romantic, everything has an
inherent element of uncertainty within it that is influenced by the rules you've learned
from this book.

sSo, don't view Dynamic Asset Pricing Theory (DAPT) as a subject you will be tested on.
DAPT does teach you how to navigate the uncertainties in your financial journey, that’s
for sure. But most of all it is a mindset.

When it comes to making money, you will be confronted with uncertainty as well, and
you have been given magical and effective tools to minimize this uncertainty as much
as possible, whether you are unsure about interest rates, credit risk, stock
fluctuations…

Minimizing uncertainty and risk is a must and you must do that because we don’t play
with finances and money, you need it for survival and self-actualization and many other
incentives you will choose for yourself. But once you gain the money and survive,
remember to return to your life, take it easy, be comfortable with uncertainty, feel your
way through it, live with it, and remember life’s surprises are inevitable and “the
highest probability amounts not to certainty” and that is alright.

As this course concludes, prepare yourself for challenges that Finance might throw your
way; rest assured, we've prepared you well for this battle. Be adventurous, go make
money, and face life's surprises with an open mind and an open heart. Stay resilient,
stay adaptable, and embrace the unpredictability that makes life exciting.

Yours,

Nour Coussaini

81
References
Aldrich, J., 1997. R. A. Fisher And The Making Of Maximum Likelihood 1912 – 1922. Statistical
Science, 12(3), p. 162]176.

Artus, 1987. Structure Par Terme Des Taux D'interet:Théorie Et Estimation Dans Le cas Français.
s.l.:Cahiers Economiques Et Monétaires, Banque De France, n°27.

Bekdache & Baum, 1994. Comparing Alternative Models of The Term Structure Interest Rates.
Boston College, Issue 271.

Black, F., 1976. The pricing of commodity contracts. Journal of Financial Economics, Volume 3,
pp. 167-179.

Black, F. & Cox, J., 1976. Valuing Corporate Securities : Some Effects of Bond Identure
Provisions. Journal of Finance, 31(2), pp. 351-367.

Black, F., Derman, E. & Toy, W., 1990. A One-Factor Model of Interest Rates and Its Application
to Treasury Bond Options. Financial Analysts Journal, pp. 24-32.

Black, F. & Scholes, M., 1973. The Pricing of Options and Corporate Liabilities. Journal of
Political Economy, 81(3), pp. 637-654.

Bollerslev, T., 1986. Generalized autoregressive conditional heteroskedasticity. Journal of


econometrics, p. 307–327.

Bollerslev, T., 1990. Modelling the coherence in short-run nominal exchange rates: a
multivariate generalized arch model. The Review of Economics and Statistics, p. 498–505.

Box, G. & Jenskins, G., 1970. Time Series Analysis : Forecasting and Control. s.l.:Holden-Day.

Brace, A., Gatarek, D. & Musiela, M., 1997. The Market Model of Interest Rate Dynamics..
Mathematical Finance, Volume 7, pp. 127-155.

Choudhry, M., 2004. An Introduction to Credit Derivatives. s.l.:Elsevier.

Christophe Lunven, T. K. D. G. K. A. I., 29 février 2012. Estimation D'une Structure Par Terme
Des Taux D'intérêt Sur Données Françaises, s.l.: Banque De France.

Cox, J., Ingersoll, J. & Ross, S., 1981. A Re-examination of Traditional Hypotheses about the Term
Structure of Interest Rates. s.l.:The Journal of Finance.

Cox, J., Ingersoll, J. & Ross, S., 1985. A Theory of the Term Structure of Interest Rates.
Econometrica, 53(2), pp. 385-408.

Cox, J. J. I. A. S. R., 1981. A Re-examination Of Traditional Hypotheses About The Term Structure
Of Interest Rates. s.l.:The Journal Of Finance.

Culbertson.J.M., 1957. The Term Structure Of Interest Rate. s.l.:The Quarterly Journal Of
Economics (1963) 77 (1): 166-174.

Demange.G, R., 1992. Méthode Mathématique De La Finance. s.l.:Economica.

82
Dickey, D. & Fuller, W., 1979. Distribution of the Estimators for Autoregressive Time Series with
a Unit Root. Journal of the American Statistical Association, Issue 74, pp. 427-431.

Engle, R. F., 1982. Autoregressive conditional heteroscedasticity with estimates of the variance
of United Kingdom inflation. Econometrica: Journal of the Econometric Society, p. 987–1007.

Fisher.I, 1896. the rate of interest. s.l.:banque de france.

Fisher.R, 1922. “On the Mathematical Foundations Of Theoretical Statistics, s.l.: Philosophica
lTransactions Of The Royal Society.

Heath, D., Jarrow, R. & Morton, A., 1992. Bond Pricing and the Term Structure of Interest Rates
: a new Methodology for Contingent Claims Valuation. Volume 60, pp. 77-105.

Herrala, N., 2004. Vasicek Interest Rate : Parameter Estimation,Evolution of the Short-term
Interest Rate, s.l.: Banque Mondiale.

Heston, S., 1993. Closed-Form Solution of Options with Stochastic Volatility, with Application
to Bond and Currency Options. Review of Financial Studies, Volume 6, pp. 327-343.

Hicks, J., 1939. Value and capital: An Inquiry Into Some Fundamental Principles of Economic
Theory. s.l.:Clarendon Press,Oxford.

Hull, J. & White, A., 1987. The Pricing of Options with Stochastic Volatility. Journal of Finance,
42(2), pp. 281-300.

Hull, J. & White, A., 1990. Pricing Interest Rate Derivative Securities. The Review of Financial
Studies, pp. 573-592.

James, J. & Webber, N., 2004. Interest Rate Modelling. s.l.:Financial Engineering.

Jeanblanc, M., 2003. Financial Markets in Continuous Time. s.l.:Economica.

Jeanblanc, M., 2005. Elements de calcul stochastique. s.l.:Springer-Verlag.

Keynes, J., 1936. The General Theory of Employment, Interest and Money. Royaume-Uni: Edited
in 1949 by Macmillan, London.

Keynes, J., 1936. The General Theory Of Employment, Interest And Money. Royaume-Uni:
Edited In 1949 By Macmillan, London.

Langetieg.C, 1980. A Multivariate Model Of The Term Structure. The Journal Of Finance,
Volume 35, pp. 71-97.

Langetieg, C., 1980. A Multivariate Model of the Term Structure. The Journal of Finance,
Volume 35, pp. 71-97.

Lutz, F., 1940. The structure of interest rate. s.l.:Quarterly Journal of Economics.

Merton, R., 1974. On the Pricing of Corporate Debt : The Risk Structure of Interest Rates.
Journal of Finance, Issue 29, pp. 449-470.

Miskin, F., 2004. Monnaie, Banque Et Marchés Financiers. 10 ed. s.l.:Person Education France.

83
Modigliani, F., 1966. Innovations in Interest Rate Policy. s.l.:The American Economic Review.

Modigliani, F. A. S., 1966. Innovations In Interest Rate Policy. s.l.:The American Economic
Review.

O'Kane, D., 2008. Modelling Single-Name and Multi-Name Credit Derivatives. s.l.:Wiley & Sons.

Piazzesi, M., 2003. A no-arbitrage vector autoregression of term structure dynamics with
macroeconomic and latent variables. Journal of Monetary Economics, Volume 50, p. 745–787.

Piazzesi, M., 2003. A No-Arbitrage Vector Autoregression Of Term Structure Dynamics With
Macroeconomic And Latent Variables. Journal Of Monetary Economics, Volume 50, p. 745–787.

Priaulet, P., 2003. Modèles De La courbe Des Taux D'intérêt,Cours De l'ENSAE, s.l.: MASE
Université Paris IX Dauphine.

Richard, N., 1978. A Continuous Time Equilibrium Model Of Forward Prices And Futures Prices
In A Multigood Economy. s.l.:Journal Of Financial Economics.

Ross, S., 1977. Theory Of Rates. Journal Of Finance, pp. 50-67.

Uctum, G. P. E. R., 2001. Anticipations,Primes De Risque Et Stucture Par Terme Des Taux
D’intérêtt:Une Analyse Des Comprtements D'experts. s.l.:Banque De France.

Vasicek, O., 1977. An Equilibrium Characterization of the Term Structure. Journal of Financial
Economics, Volume 5, p. 177–188.

Veral R.J., E. P., 1999. Analytic And Bootstrap Estimates Of Prediction Errors In Claim Reserving.
Insurance : Mathematics And Economics.

Webber, J. J. A. N., 2004. Interest Rate Modelling. s.l.:Financial Engineering.

Zekri Mounir, B. S. Y., 2005-2006. Cours Marchés Financiers Et Evaluations Des Actifs;A Theory
Of Term Structure Of Interset Rate. s.l.:Institution Supérieur De Gestion De Tunis.

Zeytum.S, G., 2007. A Comparative Study Of The Vasicek And The CIR Model Of The Short Rate.
Berichte Des Fraunhofer ITWM, Nr. 124, p. 2.

84
Appendix

I. Math Review
Derivatives :
𝑑 𝑥𝑛
• = 𝑛𝑥 𝑛−1 (Power Rule)
𝑑𝑥
𝑑 𝑒𝑥
• = 𝑒𝑥
𝑑𝑥
𝑑 ln (𝑥) 1
• =𝑥
𝑑𝑥
𝑑 sin 𝑥
• = cos 𝑥
𝑑𝑥
𝑑 cos 𝑥
• = − sin 𝑥
𝑑𝑥
𝑑 𝑓 𝑓 ′ .𝑔−𝑓.𝑔′
• =
𝑑𝑥 𝑔 𝑔²
𝑑
• (𝑓. 𝑔) = 𝑓 ′ . 𝑔 + 𝑓. 𝑔′
𝑑𝑥
𝑑
• 𝑓(𝑔(𝑥)) = 𝑓 ′ (𝑔(𝑥)). 𝑔′(𝑥)
𝑑𝑥

Integration:

• ∫ 𝑘 𝑑𝑥 = 𝑘𝑥 + 𝐶 where k is a constant
𝑥 𝑛+1
• ∫ 𝑥 𝑛 𝑑𝑥 = +𝐶 if n ≠ -1
𝑛+1
𝑑𝑢 𝑢𝑛+1
• ∫ 𝑢𝑛 𝑑𝑥 = ∫ 𝑢𝑛 𝑑𝑢 = ∫ +𝐶
𝑑𝑥 𝑛+1
1
• ∫ 𝑥 𝑑𝑥 = ln(𝑥) + 𝐶
𝑑𝑢/𝑑𝑥 1
• ∫ 𝑑𝑥 = ∫ 𝑢 𝑑𝑢 = ln(𝑢) + 𝐶
𝑢
• ∫ 𝑘 𝑓(𝑥) 𝑑𝑥 = 𝑘 ∫ 𝑓(𝑥)𝑑𝑥
• ∫(𝑓(𝑥) ± 𝑔(𝑥)) 𝑑𝑥 = ∫ 𝑓(𝑥) 𝑑𝑥 ± ∫ 𝑔(𝑥)𝑑𝑥
• ∫ 𝑒 𝑥 𝑑𝑥 = 𝑒 𝑥 + 𝐶

Integration by substitution:

85
Probability and Statistics:

• A ⊆ B ⟹ P(A) ≤ P(B).
• P(A ∩ B) ≤ min (P(A) , P(B)).
• P(A ∪ B) ≤ P(A) + P(B).
• P(Ω – A) = 1 − P(A) = P(Ā)
• Law of Total Probability: If 𝐴1 , 𝐴2 , … . , 𝐴𝑘 are a set of disjoint events such that
⋃𝑘𝑖=1 𝐴𝑖 = Ω then ∑𝑘𝑖=1 𝑃(𝐴𝑖 ) = 1

• Chain Rule:
• Let 𝐴1 , 𝐴2 , … . , 𝐴𝑘 be events, 𝑃(𝐴𝑖 ) > 0. Then the chain rule states that:
• 𝑃(𝐴1 ∩ 𝐴2 ∩ 𝐴3 ∩ 𝐴4 ) = 𝑃(𝐴1 ∩ 𝐴2 ∩ 𝐴3 ) 𝑃(𝐴4 | 𝐴1 ∩ 𝐴2 ∩ 𝐴3 )
= 𝑃(𝐴1 ∩ 𝐴2 ) 𝑃(𝐴3 | 𝐴1 ∩ 𝐴2 ) 𝑃(𝐴4 | 𝐴1 ∩ 𝐴2 ∩ 𝐴3 )
= 𝑃(𝐴1 ) 𝑃(𝐴2 |𝐴1 ) 𝑃 𝑃(𝐴3 | 𝐴1 ∩ 𝐴2 ) 𝑃(𝐴4 | 𝐴1 ∩ 𝐴2 ∩ 𝐴3 )
• Independence: Two events are called independent if:
𝑃(𝐴 ∩ 𝐵) = 𝑃(𝐴)𝑃(𝐵) or equivalently,
𝑃(𝐴|𝐵) = 𝑃(𝐴)

Cumulative distribution functions:

A cumulative distribution function (CDF) is a function 𝐹𝑥 : 𝑅 → [0,1] which specifies a


probability measure as:

𝐹𝑥 (𝑥) = 𝑃(𝑋 ≤ 𝑥)

The most common cumulative distribution functions (CDFs) and their formulas:
𝑥
• Uniform distribution: 𝐹(𝑥) = , where a and b are the minimum and maximum
𝑏−𝑎
values of the distribution.
1 𝑥−𝜇
1
• Normal distribution: 𝐹(𝑥) = √2 𝜋 𝜎 2
𝑒 −2 (𝜎

where μ and σ are the mean and standard
deviation of the distribution.
• Exponential distribution: 𝐹(𝑥) = 1 − 𝑒 −𝜆𝑥 , where λ is the rate parameter of the
distribution.
86
𝜆𝑘 𝑒 −𝜆
• Poisson distribution: 𝐹(𝑥) = k is the number of occurrence and λ is the mean of
𝑘!
the distribution.

Probability mass functions: 𝑝𝑥 : 𝑋 ⟶ [0,1] such that 𝑝𝑥 (𝑥) = 𝑃(𝑋 = 𝑥)


𝑝
• X ~ Bernoulli(p): 𝑝(𝑥) {1 − 𝑝
• X ~ Geometric(p): 𝑝(𝑥) = 𝑝(1 − 𝑝)𝑥−1
𝜆𝑥
• X ~ Poisson(𝜆): 𝑝(𝑥) = 𝑒 −𝜆 𝑥!

Expectation:

• 𝐸[𝑎] = 𝑎 for any constant a ∈ 𝑅


• 𝐸[𝑎𝑓(𝑥)] = 𝑎𝐸[𝑓(𝑥)] for any constant a ∈ 𝑅
• 𝐸[𝑓(𝑥) + 𝑔(𝑥)] = 𝐸[𝑓(𝑥)] + 𝐸[𝑔(𝑥)]
• 𝐸[1{𝑋 = 𝑘}] = 𝑃(𝑋 = 𝑘)
• 𝐸[𝑓(𝑋)𝑔( 𝑌)] = 𝐸[𝑓(𝑋)]𝐸[𝑔(𝑌)] if X and Y are independent

Variance:

• 𝑉𝑎𝑟[𝑋] = 𝐸[𝑋 − 𝐸[𝑋]²]


• 𝑉𝑎𝑟[𝑋] = 𝐸[𝑋²] − 𝐸[𝑋]2 ]
• 𝑉𝑎𝑟[𝑎] = 0 for any constant a ∈ 𝑅
• 𝑉𝑎𝑟[𝑎𝑓(𝑥)] = 𝑎²𝑉𝑎𝑟[𝑓(𝑥)] for any constant a ∈ 𝑅
• 𝑉𝑎𝑟[𝑋 + 𝑌] = 𝑉𝑎𝑟[𝑋] + 𝑉𝑎𝑟[𝑌] + 2𝐶𝑜𝑣[𝑋, 𝑌]

Covariance: the covariance of two random variables X and Y is defined as:

• 𝐶𝑜𝑣[𝑋, 𝑌] = 𝐸[(𝑋 − 𝐸[𝑋])(𝑌 − 𝐸[𝑌])]


• 𝐶𝑜𝑣[𝑋, 𝑌] = 𝐸[𝑋𝑌] − 𝐸[𝑋]𝐸[𝑌]
• 𝐶𝑜𝑣[𝑋, 𝑌] = 0 If Y and X are independent
• 𝐶𝑜𝑣[𝑐𝑋, 𝑌] = 𝑐 𝐶𝑜𝑣[𝑋, 𝑌]
• 𝐶𝑜𝑣[𝑋, 𝑐𝑌] = 𝑐 𝐶𝑜𝑣[𝑋, 𝑌]
• 𝐶𝑜𝑣[𝑋 + 𝑌, 𝑍] = 𝐶𝑜𝑣[𝑋, 𝑍] + 𝐶𝑜𝑣[𝑌, 𝑍]
• 𝐶𝑜𝑣[𝑋 + 𝑌, 𝑍 + 𝑊] = 𝐶𝑜𝑣[𝑋, 𝑍] + 𝐶𝑜𝑣[𝑋, 𝑊] + 𝐶𝑜𝑣[𝑌, 𝑍] + 𝐶𝑜𝑣[𝑌, 𝑊]

87
For those who are unfamiliar with Python, here is a 1-hour course:
Introduction to python

Numerical Computing with NumPy

Objectives:

● Understand the fundamentals of NumPy and its role in numerical computing.


● Learn how to create and manipulate arrays using NumPy.
● Explore basic mathematical operations and functions provided by NumPy.

I. Introduction to NumPy
What is NumPy?

● NumPy (Numerical Python) is a fundamental package for numerical computations in Python.


● It provides support for arrays, matrices, and mathematical functions to efficiently handle
large datasets.
● NumPy is built on optimized C and Fortran libraries, making it fast and memory-efficient.

II. Creating NumPy Arrays


1. Importing NumPy: Before using NumPy, import it as import numpy as np.
2. Creating Arrays:
● Use np.array() to create arrays from Python lists.
● Arrays can be of any dimension (1D, 2D, etc.).

Example:

import numpy as np

# Creating a 1D array
arr1 = np.array([1, 2, 3, 4, 5])

# Creating a 2D array (matrix)


arr2 = np.array([[1, 2, 3], [4, 5, 6]])

III. Array Operations and Broadcasting

Basic Operations:

● NumPy supports element-wise arithmetic operations.


● Arrays of compatible shapes can be added, subtracted, multiplied, and divided.
Broadcasting:

● NumPy performs operations on arrays of different shapes through broadcasting.

88
● Smaller arrays are automatically broadcasted to match the shape of the larger array.

Example:

arr1 = np.array([1, 2, 3])


arr2 = np.array([10, 20, 30])

# Element-wise operations
result = arr1 + arr2 # [11, 22, 33]

# Broadcasting
scalar = 5
result = arr1 + scalar # [6, 7, 8]

IV. Mathematical Functions:

Element-wise Functions:

● NumPy provides various mathematical functions that operate element-wise on arrays.


● Examples: np.sqrt(), np.exp(), np.sin(), np.cos().
Aggregation Functions:

● Functions to compute summary statistics of arrays.


● Examples: np.mean(), np.sum(), np.min(), np.max().

V. Working with Multidimensional Arrays:

Indexing and Slicing:

● Access elements or sub-arrays using indexing and slicing.


● Indexing starts at 0.
Example:

matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

# Accessing elements
element = matrix[1, 2] # 6

# Slicing
row_slice = matrix[0, :] # [1, 2, 3]
column_slice = matrix[:, 1] # [2, 5, 8]

Further Resources:

Youtube course: Python NumPy Tutorial for Beginners

89
Many helpful resources are provided on the NumPy website: http://www.numpy.org/

Data Analysis with Pandas

Objectives:

● Understand the role of Pandas in data manipulation and analysis.


● Learn how to load, clean, and manipulate data using Pandas DataFrames.
● Explore common data analysis tasks with Pandas.
I. Introduction to Pandas:
What is Pandas?

Pandas is a powerful Python library for data manipulation and analysis.

It provides the DataFrame and Series objects to work with structured data efficiently.

Pandas is widely used in data preprocessing, cleaning, exploration, and visualization.

II. Loading and Inspecting Data:


Loading Data:

● Pandas supports reading various data formats: CSV, Excel, SQL, JSON, etc.
● Use functions like pd.read_csv(), pd.read_excel(), etc.
Inspecting Data:

● Explore the basic structure of data using methods like head(), tail(), info(), describe().
Example:

import pandas as pd

# Load data from a CSV file


data = pd.read_csv('data.csv')

# Display the first few rows


print(data.head())

# Get data summary


print(data.info())

III. Data Cleaning and Preprocessing:


Handling Missing Data:

● Use functions like isnull(), notnull(), fillna() to deal with missing values.
● Drop missing values using dropna().
Data Transformation: Apply transformations like renaming columns, changing data

types, and removing duplicates.

Example:

90
# Handling missing values
data.dropna() # Remove rows with missing values
data.fillna(0) # Fill missing values with zeros

# Data transformation
data.rename(columns={'old_name': 'new_name'}, inplace=True)
data['column'] = data['column'].astype(int)
data.drop_duplicates(inplace=True)

IV. Data Manipulation with Pandas:

Selecting Columns and Rows: Use indexing and slicing to select specific rows and

columns.

Filtering Data: Apply conditions to filter rows based on specific criteria.

Sorting Data: Sort data using sort_values().

Example:

# Selecting columns
column = data['column_name']

# Selecting rows with condition


filtered_data = data[data['column'] > 100]

# Sorting data
sorted_data = data.sort_values('column_name')

V. Aggregation and Grouping:

Aggregation Functions: Use functions like sum(), mean(), count() to compute

summary statistics.

Grouping Data: Group data based on one or more columns using groupby().

Example:

# Aggregation
total_amount = data['amounts'].sum()
average_return = data['return'].mean()

# Grouping

91
grouped_data = data.groupby('category')['amount'].sum()

Additional resources:

Youtube course: Pandas Data Science Tutorial

http://pandas.pydata.org/

92
Data Visualization

Objectives:

● Understand the importance of data visualization in data analysis.


● Learn how to create various types of plots using Matplotlib and Seaborn.
● Explore techniques for enhancing the visual representation of data.

I. Introduction to Data Visualization:


● Matplotlib and Seaborn are popular libraries for creating static visualizations.
● Plotly provides interactive visualizations suitable for web applications.

II. Basic Plotting with Matplotlib


Basic Plots:

● Create line plots, scatter plots, and bar plots using Matplotlib.
● Use plt.plot(), plt.scatter(), plt.bar().

Adding Labels and Titles: Label axes and add a title to the plot using plt.xlabel(),
plt.ylabel(),

and plt.title().

Example:

import matplotlib.pyplot as plt


# Line plot
plt.plot(x_values, y_values)
plt.xlabel('X-axis label')
plt.ylabel('Y-axis label')
plt.title('Title of the Plot')
plt.show()

III. Customizing Plots:


Styling Plots:

● Customize plot colors, line styles, and markers.


● Use parameters like color, linestyle, marker.
Adding Legends and Annotations:

● Add legends using plt.legend().


● Annotate points on the plot using plt.annotate().

93
Example:

plt.plot(x_values, y_values, color='blue', linestyle='--',


marker='o', label='Data')
plt.legend()
plt.annotate('Important point', xy=(x, y), xytext=(x_text,
y_text),arrowprops=dict(facecolor='black', arrowstyle='->'))

IV. Advanced Visualization with Seaborn:


Seaborn Advantages:

● Seaborn provides high-level interfaces for creating attractive statistical plots.


● It simplifies creating complex visualizations with minimal code.
Creating Plots with Seaborn:

● Use functions like sns.lineplot(), sns.scatterplot(), sns.barplot().


Example:

import seaborn as sns


# Scatter plot with Seaborn
sns.scatterplot(x='x_column', y='y_column', data=data_frame,
hue='category_column')
plt.xlabel('X-axis label')
plt.ylabel('Y-axis label')
plt.title('Title of the Plot')
plt.show()

V. Financial Plots:
Importance of Financial Plots:

● Financial plots play a crucial role in understanding market trends, asset performance,
and investment decisions.
● They visually represent time series data, volatility, and relationships between
financial instruments.
Plotting Time Series Data:

● Use line plots to visualize stock prices, market indices, and other time-dependent
data.
● Highlight trends, patterns, and key events in the financial data.

94
Example:

plt.figure(figsize=(10, 6))
plt.plot(date_column, price_column, label='Stock Price')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Stock Price Over Time')
plt.legend()
plt.show()

Candlestick Charts:

● Candlestick charts provide visual representation of price movements within a


specified time interval (e.g., day, week).
● Display open, close, high, and low prices for each interval.

Example:

import mplfinance as mpf


# Create a candlestick chart using mplfinance
mpf.plot(data_frame, type='candle')

Volatility and Moving Averages:

95
● Plotting volatility helps in understanding market risk.
● Moving averages (e.g., 20-day, 50-day) smooth out price data and reveal trends.

Example:

plt.figure(figsize=(10, 6))
# Plotting volatility
plt.plot(date_column, volatility_column, label='Volatility')
# Plotting moving averages
plt.plot(date_column, moving_average_20, label='20-day Moving
Average')
plt.plot(date_column, moving_average_50, label='50-day Moving
Average')
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Volatility and Moving Averages')
plt.legend()
plt.show()

Additional resources:

Youtube course: Data Visualisation avec Python

96
Financial Time Series

Objectives:

● Understand the unique characteristics of financial time series data.


● Learn how to import financial data from the web and perform summary statistics.
● Explore techniques for analyzing changes over time, resampling, and calculating rolling
statistics.
● Apply technical analysis concepts and correlation analysis in a financial context.

I. Introduction to Financial Time Series Data:


Characteristics of Financial Time Series:

● Financial data is sequential and timestamped.


● Examples include stock prices, market indices, exchange rates.
● Analyzing time series data aids in understanding market trends.

II. Financial Data Import and Cleaning:


Importing Data from the Web: Use libraries like pandas and pandas_datareader for data
retrieval.

Getting stock data with pandas datareader

Example: Importing stock data from Yahoo Finance.

import pandas as pd
import pandas_datareader as pdr
from datetime import datetime

# Define the start and end dates for the data fetch
start_date = datetime(2020, 1, 1)
end_date = datetime(2021, 1, 1)

# Fetch stock data for 'AAPL' (Apple Inc.) from Yahoo Finance
stock_data = pdr.get_data_yahoo('AAPL', start=start_date,
end=end_date)

# Print the first few rows of the fetched data


print(stock_data.head())

97
III. Summary Statistics:
Calculating Summary Statistics:

● Compute mean, median, standard deviation.


● Gain insights into central tendency and dispersion.
Summary Statistics

mean_price = stock_data['Close'].mean()
median_price = stock_data['Close'].median()
std_price = stock_data['Close'].std()

print(f"Mean Price: {mean_price}, Median Price: {median_price},


Standard Deviation: {std_price}")

IV. Changes Over Time:


Statistical analysis methods are often based on changes over time and not the absolute values
themselves. There are multiple options to calculate the changes in a time series over time,
including absolute differences, percentage changes, and logarithmic (log) returns.

Examples:

#diff() provides the absolute changes between two index


values.

data.diff().head()

Example:

#pct_change() calculates the percentage change between two


index values
data.pct_change().round(3).head()

Output:

98
V. Resampling and Rolling Statistics:
Resampling:

● Convert data to a different frequency.


● Analyze long-term trends.

monthly_data = stock_data.resample('M').last()
print(monthly_data.head())

Rolling Statistics: It is a financial tradition to work with rolling statistics, often also

called financial indicators or financial studies. Rolling statistics involve calculating metrics like
the moving average and standard deviation over a rolling window of data points. A rolling
window is like a moving time frame that slides through your data, and at each position, you
calculate the statistic within that window. This is particularly useful for smoothing out noisy
data and identifying trends.

Rolling Statistics

Let's take an example of calculating a rolling 20-day moving average and standard deviation for
a stock's closing prices:

stock_data['Rolling Mean'] =
stock_data['Close'].rolling(window=20).mean()
stock_data['Rolling Std'] =
stock_data['Close'].rolling(window=20).std()

Here, we're calculating the rolling mean and standard deviation using the .rolling() function
with a window size of 20. This means that at each data point, the average and standard
deviation of the previous 20 days will be calculated. You can adjust the window size to suit your
analysis requirements.

Additional resources:

99
Stock Market Analysis with Pandas Python Programming

100
Introduction to R

II. Introduction to R
R is a powerful programming language that is widely used in data analysis and research. It
provides a wide range of statistical and graphical techniques, making it a popular choice for
data scientists and researchers. R is also an open-source language, which means that it is free
to use and can be modified by anyone. Additionally, R has a large and active community of
users who contribute to its development by creating packages and libraries that extend its
functionality. Overall, R is a versatile and powerful tool for data analysis and research.

R comes with a basic Graphical User Interface (GUI), which includes a console and a script
editor. However, many users find the basic GUI to be limited and prefer to use an integrated
development environment (IDE) like RStudio, which provides a more comprehensive and user-
friendly interface for working with R.

1. Working with Rstudio

The RStudio IDE is split into four panes, and you can customize the content and layout to suit
your preferences.

The four panes of the RStudio IDE are:

• The code editor (top left): This is where you can write and edit R code.
• The console (bottom left): This is where you can execute R code and view the results.
• The help pages (top right): This is where you can access documentation and help files for R
functions and packages.
The environment stores the data frame, vectors, list and all the data type.

101
• The graphics viewer (bottom right): This is where you can view plots and other graphical
output
generated by R code.
Files: shows the working directories and the files in the working directories
Packages: you can install from packages, see your packages, see if there is update, and update
your packages.
The panes on the right have additional tabs to choose from.

The four panes can be arranged and suppressed as you like.

You write R code in the built-in editor and execute it in the console; the shortcut “send code to
console” keystrokes are CTRL-ENTER or CTRL-R in Windows and on a Mac.

The textual output appears in the console as usual.

2. Working Directories:

A working directory is a file path on your computer that sets the default location of any files
you read into R or save out of R.

It is the default location where R will look for files you want to load and where it will put any
files you save.

In other words, a working directory is like a little flag somewhere on your computer that is tied
to a specific analysis project. If you ask R to import a dataset from a text file or save a data
frame as a text file, it will assume that the file is inside your working directory. When you open
an RStudio project, it will automatically set your working directory to the appropriate location.

You can check the file path of your working directory by looking at bar at the top of the Console
pane.

You can only have one working directory active at any given time, and the active working
directory is called your current working directory.

102
getwd() is used for finding the current working directory

setwd() is used for setting up a new working directory.

setwd('/Users/nhy163/Documents/Alex/Teaching/first_project')

3. Packages

To install a package from CRAN you can use the install.packages() function. For example if you
want to install the remotes package enter the following code into the Console window of
RStudio (note: you will need a working internet connection to do this)

install.packages('remotes', dependencies = TRUE)

The dependencies = TRUE argument ensures that additional packages that are required will
also be installed.

It’s good practice to occasionally update your previously installed packages to get access to
new functionality and bug fixes. To update CRAN packages you can use the update.packages()
function (you will need a working internet connection for this)

update.packages(ask = FALSE)

The ask = FALSE argument avoids having to confirm every package download which can be a
pain if you have many packages installed.

Another method

RStudio provides a package installer to manage the downloads and installations of contributed
packages. You’ll find the package manager in the Packages tab on your chosen utility pane.

103
It lists only those packages that you currently have installed, along with their version numbers,
and you can use the checkboxes next to each package name to load it (instead of using library
at the R console prompt).

Below, I’ve just selected the box for the car package, which automatically executes the relevant
call to library in the console.

The figure also shows the Install and Update buttons for packages. To install a package, click
the Install button and enter the package you want in the field. RStudio will give you options as
you type, as shown for the ks package on the left of Figure B-7. Ensure “Install dependencies”
is checked in order to automatically install any additionally required packages.

To update packages, click the Update button to bring up the dialog box on the right of Figure
B-7; here you can choose to update either individual packages or all of them by clicking the
Select All button.

4. Import data into R

We can import data from various sources such as CSV files, Excel files, databases, or directly
from the web using packages such as quantmod.

The quantmod package is a popular package used for importing financial data into R. We can
use the read.csv() function to import data from CSV files, and the readxl package to import
data from Excel files.

d. Importing data from CSV files

104
read.csv() is a built-in function that help to import CSV file

To import data from a local file into R using the read.csv() function, you can follow these
steps:

1. Check your working directory to ensure that it is set to the location where you want to put
the CSV file.
2. Use the read.csv() function to upload the CSV file. Pass the file path as the first argument to
the function.
3. Set the header parameter to TRUE if your CSV file has a header row. This will treat the first
row as column names.
4. Set the sep parameter to specify the delimiter used in the CSV file. For comma-separated
values, use sep = ",".
5. The data will be imported into R and stored in an object with the name you specified.
6. You can use the object name to view the content of the imported data in the console.
7. Additionally, you can click on the object name in the environment pane of RStudio to open a
new window with the document's content.

Here's an example of how to import a CSV file using read.csv():

a contains the variable names by default.

# Check working directory

getwd()

# Import .csv file to global environment

Data <- read.csv('R_training.csv’, header = TRUE, sep = ",")

# Import .csv file to a new window

Data

e. Importing data from an excel sheet

We will use the read_excel() function from the readxl package

Example:

# Install and load the readxl package


install.packages("readxl")
library(readxl)
# Check working directory
getwd()
# Import Excel file to global environment
Data <- read_excel("C:/Users/Bob/Desktop/data.xlsx")
# Import Excel file to a new window
Data

105
f. Importing data from the web

Depending on the specific financial data you want to download; you may need to load relevant
packages.

For example, the "quantmod" package, Quantmod stands for quantitative financial modelling
framework provides functions for downloading stock data from multiple sources, including
Yahoo Finance and the Federal Reserve Economic Data (FRED)

install.packages("quantmod")

library(quantmod)

We can use getSymbols to get data (default is yahoo)

The head() function displays the first six rows of a data frame by default, or a specified number
of rows if you pass an argument to the function n=3.

getSymbols("AAPL")
head(AAPL,n=3)
## AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
## 2003-01-02 0.5083427 0.5281666 0.5079888 0.5239188 45357200
## 2003-01-03 0.5239188 0.5285210 0.5164849 0.5274589 36863400
## 2003-01-06 0.5320605 0.5444505 0.5267507 0.5274589 97633200
## AAPL.Adjusted
## 2003-01-02 0.919821
## 2003-01-03 0.926036
## 2003-01-06 0.926036

This is called OHLCVA price data.

We have open, high, low, close, volume and adjusted closing prices.

High and low are the highest and lowest prices of the trading day.

Open and close are the opening and the closing prices of the trading day.

Volume is the number of shares transacted on the trading day.

Adjusted closing price is the closing price that adjusts for event after market closes such as
stock splits and dividend.

To extract columns, we use Op, Hi, Lo, Cl, Vo and Ad

Open <- Op(AAPL) #Open Price


High <- Hi(AAPL) # High price
Low <- Lo(AAPL) # Low price
Close<- Cl(AAPL) #Close Price
Volume <- Vo(AAPL) #Volume
AdjClose <- Ad(AAPL) # Adjusted close

106
If you wish to only import at a certain date e.g.,. 2000-01-01 to 2015-09-25, we can restrict the
set the data to download.

getSymbols("AAPL", from='2000-01-01',to='2015-09-25')
## [1] "AAPL"

We can take the first 3 years by using first():

getSymbols("AAPL")
## [1] "AAPL"
AAPL <- first(AAPL,'3 years')
head(AAPL)
## AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
## 2007-01-03 12.32714 12.36857 11.70000 11.97143 309579900
## 2007-01-04 12.00714 12.27857 11.97429 12.23714 211815100
## 2007-01-05 12.25286 12.31428 12.05714 12.15000 208685400
## 2007-01-08 12.28000 12.36143 12.18286 12.21000 199276700
## 2007-01-09 12.35000 13.28286 12.16429 13.22429 837324600
## 2007-01-10 13.53571 13.97143 13.35000 13.85714 738220000
## AAPL.Adjusted
## 2007-01-03 10.41635
## 2007-01-04 10.64755
## 2007-01-05 10.57173
## 2007-01-08 10.62393
## 2007-01-09 11.50647
## 2007-01-10 12.05711
We can also import three stocks at the same time by using a vector.

getSymbols(c("AAPL","GOOG"))
## [1] "AAPL" "GOOG"

Besides prices, very often we are interested in the trading volume. Moreover, we would like to
find volume over time: weekly, monthly, quarterly and yearly. We can use apply and sum to
calculate the rolling sum of volume to each distinct period.

WeekVoYa<- apply.weekly(Vo(AAPL),sum)
# sum from Monday to Friday
MonthVoYa <- apply.monthly(Vo(AAPL),sum)
# sum to month
QuarterVoYa <- apply.quarterly(Vo(AAPL),sum)
# sum to quarter
YearVoYa <- apply.yearly(Vo(AAPL),sum)
# sum to year

In some case, we are interested in average than the sum. Then we can use apply and mean.
Below we calculate the weekly average volume of AAPL.

WeekAveVoClYa<- apply.weekly(Vo(AAPL),mean)

5. Manipulating Data

A vector is a basic data structure that contains elements of the same data type.

107
There are six types of atomic vectors in R: logical, integer, double, complex, character, and raw.

A vector can be created using the c() function, which combines elements of the same data type
into a vector.

The array() function takes vectors as input and uses the values in the dim parameter to create
an array. An array can store only one data type.

We can use the + operator to perform element-wise operations and broadcasting on vectors in
R.

The matrix() function is used to create matrices in R. We can use indexing and slicing to access
elements and subsets of the matrix.

The apply() function in R is used to apply a function to margins of an array or matrix. It returns
a vector, array, or list of values obtained by applying a function to margins of an array or
matrix.It is primarily used to avoid explicit uses of loop constructs.

Example:

a. The array() function


# Creating a 1D array
arr1 <- array(c(1, 2, 3, 4, 5))
# Creating a 2D array (matrix)
arr2 <- array(c(1, 2, 3, 4, 5, 6), dim = c(2, 3))

One dimension array is created by passing a vector of values to the array() function.

Two dimension array is created by passing a vector of values and specifying the dimensions
using the dim parameter.

To add two vectors element-wise or to add a scalar value to a vector we can use the +
operator

# Creating vectors
arr1 <- c(1, 2, 3)
arr2 <- c(10, 20, 30)
# Element-wise operations
result <- arr1 + arr2 # [11, 22, 33]
# Broadcasting
scalar <- 5
result <- arr1 + scalar # [6, 7, 8]

b. The matrix() function

# Creating a matrix
matrix <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3)
# Accessing elements
element <- matrix[2, 3] # 8
# Slicing

108
row_slice <- matrix[1, ] # [1, 4, 7]
column_slice <- matrix[, 2] # [4, 5, 6]

c. The apply() function:


# Creating a matrix
matrix <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3)

# Applying a function to the matrix


row_sums <- apply(matrix, 1, sum)
col_sums <- apply(matrix, 2, sum)

# Printing the results


print(row_sums)
print(col_sums)

We pass the matrix as the first argument, the margin as the second argument (1 for rows and
2 for columns), and the function to apply as the third argument

The apply() function can be used with functions like sum(), mean(), min(), max(), sd(), var() …

We inspect the data to understand its structure, content, and quality.

It is an essential step in the data analysis process, as it helps to identify any issues or anomalies
in the data that may affect the analysis results.

Some common functions used for inspecting data in R include head(), tail(), str(), summary(),
and View(). The head() and tail() functions display the first or last few rows of the data,
respectively.

The str() function displays the structure of the data, including the data type of each variable.

The summary() function provides summary statistics of the data, such as mean, median, and
quartiles. The View() function opens an interactive data viewer that allows us to explore the
data in a spreadsheet-like interface.

#Create example data


data<- data.frame(
x1=9:5,
x2=letters[1:5],
x3=letters[9:5]
)
#print example data
data

# displays the structure of the data


str(data)

# opens an interactive data viewer


View(data)

109
Other packages such as dplyr, ggplot2, and tidyr can also be used for data manipulation and
visualization. By inspecting the data, we can identify any issues or anomalies in the data and
take appropriate actions to clean and preprocess the data before performing analysis.

6. Visualizing data

We will be working on airquality data set for visualization in R:

data(airquality)

a. Bar plot
There are two types of bar plots- horizontal and vertical which represent data points as
horizontal or vertical bars of certain lengths proportional to the value of the data item.

They are generally used for continuous and categorical variable plotting.

By setting the horiz parameter to true and false, we can get horizontal and vertical bar plots
respectively.

# Horizontal Bar Plot for Ozone concentration in air

barplot(airquality[1:50,]$Ozone, main = 'Ozone Concenteration in air',

xlab = 'ozone levels', horiz = TRUE)

# Vertical Bar Plot for Ozone concentration in air

barplot(airquality$Ozone, main = 'Ozone Concenteration in air', xlab = 'ozone


levels',

col ='blue', horiz = FALSE)

110
b. Histogram

A histogram is like a bar chart as it uses bars of varying height to represent data distribution.

However, in a histogram values are grouped into consecutive intervals called bins.

In a Histogram, continuous values are grouped and displayed in these bins whose size can be
varied.

# Histogram for Maximum Daily Temperature

hist(airquality$Temp, main ="La Guardia Airport's\

Maximum Temperature (Daily)",

xlab ="Temperature(Fahrenheit)",

xlim = c(40, 125), col ="yellow",

freq = TRUE)

c. Box Plot
The statistical summary of the given data is presented graphically using a boxplot. A boxplot
depicts information like the minimum and maximum data point, the median value, first and
third quartile, and interquartile range.

# Box plot for average wind speed


data(airquality)

111
boxplot(airquality$Wind, main = "Average wind speed
\ at La Guardia Airport",
xlab = "Miles per hour", ylab = "Wind",
col = "orange", border = "brown",
horizontal = TRUE, notch = TRUE)

d. Scatter Plot

A scatter plot is composed of many points on a Cartesian plane. Each point denotes the value
taken by two parameters and helps us easily identify the relationship between them.

# Scatter plot for Ozone Concentration per month


data(airquality)

plot(airquality$Ozone, airquality$Month,
main ="Scatterplot Example",
xlab ="Ozone Concentration in parts per billion",
ylab =" Month of observation ", pch = 19)

112

You might also like