Homework_23A

Add to your simulation program, the simulation of the SDE for Geometric Brownian motion and Vasicek process.

#Code VB.Net

https://drive.google.com/file/d/1H0-ZDydHAcNYE99PgGGagWG48yS0qGPj/view?usp=sharing

The code contains the stochastic processes of the applications:

  • 13_A
    • where represent the sum of i Bernoulli random variables px(1-p)(1-x) observed at the times j=1, …, i.
    • Represent with histogram the distribution of f(i) at different time. (f(i) is the sum of i Bernoulli random variables)
    • compute the absolute and relative frequency of the f(i)’s contained in the interval (p-ε, p+ε)
'generate for m paths n points
Public Function Generate_path() As Path
 ...
  for i = 0 to n
      ...
      p = 0.5 ' or a value between 0,1
      Dim v As Double = R.NextDouble
           If v <= p Then
                path.sequence.Add(0)
           else
                path.sequence.Add(1)
      ...
   next
   ...
End Function
  • 15_A
    • where illustrate the Glivenko-Cantelli theorem
    • and create both the histogram and the empirical CDF of the sample mean
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick   
   'Increase m and n for  closer to theor function

    For i = prec_m To m - 1
        listOfPath.Add(Generate_glCantPath(i))
    Next
   ...
    n += 1
    prec_m = m
    m += n
End Sub
' Uniform convergence of empirical CDF to the theoretical convergence
'1/n*(sum of indicator function)
Public Function Generate_glCantPath(m_path As Integer) As Path
...
 For i = 0 To n
        Dim ran As Double = R.NextDouble() * 100
        If ran < v Then
            path.sequence.Add(1)
            path.gl_canMean += 1
        Else
            path.sequence.Add(0)
            path.gl_canMean += 0
        End If


    Next

    path.gl_canMean /= n
...
End function
  • 18_A
    • where represent Poisson Distribution
    • P(i) = P(i-1) + Random step(i), for i = 1, …, n, where Random step(i) is now a Bernoulli random variable with success probability equal to λ * (1/n)
    • represent with histogram the distribution of P(i).
    • Represent also the distributions of the following quantities (and any other quantity that you think of interest):
      • Distance (time elapsed) of individual jumps from the origin
      • Distance (time elapsed) between consecutive jumps

'generate for m paths n points
Public Function Generate_path() As Path
 ...
  for i = 1 to n +1
      ...
      Dim prob As Double = path.probability(i - 1)
      p = lambda/n' or a value between 0,1
      Dim v As Double = R.NextDouble
           If v <= p Then
                 path.probability.Add(prob + v)
           else
                 path.probability.Add(prob)
      ...
   next
   ...
End Function
  • 20_A
    • where represent Brownian Motion
    • P(t) = P(t-1) + Random step(t), for t = 1, …, n, where Random step(t) is now: σ * sqrt(1/n) * Z(t), where Z(t) is a N(0,1) random variable
    • represent with histogram the distribution of P(t).
'Generate N(0,1)
Public Function Generate_z()
        Dim u1 As Double
        Dim u2 As Double
        Dim s As Double = 1.0

        While s >= 1.0
            u1 = 2.0 * R.NextDouble - 1
            u2 = 2.0 * R.NextDouble - 1
            s = u1 * u1 + u2 * u2
        End While

        Return u1 * Math.Sqrt((-2 * Math.Log(s)) / s)
    End Function
Public Function Generate_pathNormal()
    ...
      For i = 1 To n
            Dim z As Double = Generate_z()
            'Generate Rademacher random variable 
            Dim v As Double = R.NextDouble * 2.0 - 1
            Dim rand As Double = (sigma / Math.Sqrt(n) * z)
            If v <= rand Then
               ...
            End if
   ...
End Function
  • 23_A
    • Geometric Brownian motion
    • Vasicek process

https://drive.google.com/file/d/1OXINcmOoxhJx-ptDG324MYrnrg_xfqZx/view?usp=sharing

Collaboration:

Luca Scarmozzino https://stats4cyber.wordpress.com/

Homework_22A

Refine your statistical application in the following way:

To the contingency table, add or make sure it has the following features: 2) the option to display the frequencies either in absolute or relative form, with totals 2) the option to display the histograms “around” the table, in a compact form.

Code VB.NET

https://drive.google.com/file/d/1WYN5gVGdhYOwm1wAyA7ByCm40G4ZC0PU/view?usp=sharing

Homework_21A

Consider the general scheme we have used so far to simulate some stochastic processes (such as the relative frequency of success in a sequence of trials, the sample mean, the random walk, the Poisson point process) and now add this new process to our simulator.
Same scheme as previous simulations programs, except changing the way to compute the values of the paths at each time. Starting from value 0 at time 0, for each of m paths, at each new time compute P(t) = P(t-1) + Random step(t), for t = 1, …, n, where Random step(t) is now: σ * sqrt(1/n) * Z(t), where Z(t) is a N(0,1) random variable (the deviation σ is a user parameter, to scale the process dispersion).
At time n (last time) and one (or more) other chosen inner time 1<j<n (j is a program parameter) create and represent with histogram the distribution of P(t). Observe the behavior of the process for large n.

Code VB.NET

https://drive.google.com/file/d/18VrAuvDyjSh2ntiNrCYFsxfhpS_3jtxi/view?usp=sharing

n = 600
m = 400
sigma = 100

Homework_22R

An “analog” of the CLT for stochastic process: the Brownian motion as limit of random walk and the functional CLT (Donsker theorem). Explain the intuitive meaning of this result.

A (μ, σ) Brownian motion is the limiting case of random walk.

  • A particle moves ∆x to the left with probability 1−p.
  • It moves to the right with probability p after ∆t time.
  • Define:
    Xi = +1, if the ith move is to the right
    Xi = -1, if the ith move is to the left
  • Xi are independent with
    P[Xi = 1] = p = 1 – P[Xi = -1]
  • Assume n = t/t is an integer
  • Its position at time t is
    Y(t) = x(X1 + X2 + … + Xn)
  • Recall
    E[Xi] = 2p – 1
    Var[Xi] = 1 – (2p – 1)2
  • And
    E[Y(t)] = n(x)(2p – 1)
    Var[Y(t)] = n(x)(1 – (2p – 1)2)
    with ∆x = σ√∆t and p = [ 1 + (μ/σ) √∆t]/2
  • Thus, {Y(t), t≥0} converges to a (μ, σ) Brownian motion by the central limit theorem.
  • Brownian motion with zero drift is the limiting case of symmetric random walk by choosing μ = 0

Functional extension of the central limit theorem, the Donsker’s theorem.

Let X1 , X2 , X3 , … be a sequence of independent and identically distributed (i.i.d.) random variables with mean 0 and variance 1.

Let S_n:=\sum_{i=1}^n X_i. The stochastic process S := ( Sn ) n ∈ N is known as a random walk.

Define the diffusively rescaled random walk (partial-sum process) by

t ∈ [0,1]

The central limit theorem asserts that W(n)(1) converges in distribution to a standard Gaussian random variable W(1) as n -> ∞ .

In its modern form, Donsker’s invariance principle states that:
As random variables taking values in the Skorokhod space D [0,1] (The set of all càdlàg functions from E to M is often denoted by D(E,M) and is called Skorokhod space), the random function W(n) converges in distribution to a standard Brownian motion W := (W(t)) t ∈ [0,1] as n -> ∞

https://www.csie.ntu.edu.tw/~lyuu/finance1/2014/20140423.pdf
https://en.wikipedia.org/wiki/Donsker%27s_theorem
https://en.wikipedia.org/wiki/C%C3%A0dl%C3%A0g#Skorokhod_space

Homework_21R

What is a Brownian diffusion process. History, importance, definition and applications.

Brownian motion

A stochastic process, defined on a common probability space
(Ω, Σ, P)
with the following properties:

  • Increments must be independent and stationary (Cause is a Lévy process)
  • Increments has the N(0,Δt) distribution
  • x0 = 0
  • Path must be continuous with probability 1 (Almost sure):
    P{ω ∈ Ω : X( . , ω) is continuous} = 1

Diffusion Processes

A continuous time stochastic process with(almost surely) continuous sample paths which has the Markov property (the conditional probability distribution of future states of the process depends only upon the present state, not on the sequence of events that preceded it.) is called a diffusion.

The simplest and most fundamental diffusion process is Brownian motion(The independent increments imply the Markov property).

Also called Wiener process, It is one of the best known Lévy processes (càdlàg stochastic processes with stationary independent increments) and occurs frequently in pure and applied mathematics, economics, quantitative finance, evolutionary biology, and physics.

Brownian motion was discovered by the biologist Robert Brown in 1827, who observed through a microscope the random swarming motion of pollen grains in water.
The theory of Brownian motion was developed by Bachelier in his 1900 PhD Thesis and independently by Einstein in his 1905 paper which used Brownian motion to estimate Avogadro’s number and the size of molecules.
Wiener in 1923 proved that there exists a version of BM with continuous paths.

https://en.wikipedia.org/wiki/Markov_property
https://arxiv.org/pdf/1802.09679.pdf
http://dept.stat.lsa.umich.edu/~ionides/620/notes/diffusions.pdf
https://dlib.bc.edu/islandora/object/bc-ir%3A102098/datastream/PDF/view

Homework_12RA

Find out what you have just generated in exercise 18_A. How can you interpret what you see? Can you find out about all the well known distributions that “naturally (and “magically”) arise” in this process ?

Poisson Distribution

A Poisson Process is a model for a series of discrete event where the average time between events is known, but the exact timing of events is random.

A Poisson Process meets the following criteria

  1. Events are independent of each other. The occurrence of one event does not affect the probability another event will occur.
  2. The average rate (events per time period) is constant.
  3. Two events cannot occur at the same time.

A discrete random variable X is said to have a Poisson distribution with parameter λ > 0 if for k = 0, 1, 2, …, the probability mass function of X is given by:

k is the number of occurrences
λ = E(x) = Var(x)

Homework_19A

Consider the general scheme we have used so far to simulate some stochastic processes (such as the relative frequency of success in a sequence of trials, the sample mean and the random walk) and now add this new process to our simulator.
Same scheme as previous program (random walk), except changing the way to compute the values of the paths at each time. Starting from value 0 at time 0, for each of m paths, at each new time compute P(i) = P(i-1) + Random step(i), for i = 1, …, n, where Random step(i) is now a Bernoulli random variable with success probability equal to λ * (1/n)  (where λ is a user parameter, eg. 50, 100, …).
At time n (last time) and one (or more) other chosen inner time 1<j<n (j is a program parameter) create and represent with histogram the distribution of P(i). 

Represent also the distributions of the following quantities (and any other quantity that you think of interest):
– Distance (time elapsed) of individual jumps from the origin
– Distance (time elapsed) between consecutive jumps

19_A Add to your statistical application, on each variable histogram, and across the scatterplot, 3 lines indicating the 3 quartiles (use online algos for computations).

Update: Code VB.Net v2.0

https://drive.google.com/file/d/1j3oEg5IOTGTaJl7pHzdeTjOuToOulNcl/view?usp=sharing

Code VB.Net

I must fix hinstogram and add distance, so update coming soon.

https://drive.google.com/file/d/1p_8JK3LvxbFk4SnOp73wPlG0z-_Ba2Qp/view?usp=sharing

Homework_20R

General correlation coefficient for ranks and the most common indices that can be derived by it. Can you make some interesting example of computation of these correlation coefficients for ranks?

Ranks

Are the places that observation occupies in the sample order.

A rank correlation is any of several statistics that measure an ordinal association(the relationship between rankings of different ordinal variables or different rankings of the same variable). The “ranking” is the assignment of the ordering labels “first”, “second”, “third”, etc. to different observations of a particular variable.

A rank correlation coefficient measures the degree of similarity between two rankings, and can be used to assess the significance of the relation between them.

Kendall (1970) showed that his τ and Spearman’s ρ are particular cases of a general correlation coefficient Γ:

Suppose we have a set of n objects characterized by two properties x and y. To any pair of individuals, say i-th and j-th, one can assign x-score aij = -aij and y-score bij = -bij, so:

Example

Suppose that two experts order four wines called {a,b,c,d}.
The first expert gives the following order: O1= [a,c,b,d], which corresponds to the following ranks R1 = [1,3,2,4].
The second expert orders the wines as O2 = [a,c,d,b] which corresponds to the following ranks R2 = [1,4,2,3]. The order given by the first expertis composed of the following 6 ordered pairs:

P1 = {[a,c], [a,b], [a,d], [c,b], [c,d], [b,d]}

The order given by the second expert is composed of the following6 ordered pairs

P2 = {[a,c], [a,b], [a,d], [c,b], [c,d], [d,b]}

The set of pairs which are in only one set of ordered pairs is

{[b,d] [d,b]}

which gives a value of d(P1,P2) = 2 .
With this value of the symmetric difference distance we compute the value of the Kendall rank correlation coefficient between the order given by these two experts as:

This large value of τ indicates that the two experts strongly agree on their evaluation of the wines (in fact their agree about everything but one pair).

https://www.sciencedirect.com/science/article/pii/S0888613X16300172
https://en.wikipedia.org/wiki/Rank_correlation
https://personal.utdallas.edu/~herve/Abdi-KendallCorrelation2007-pretty.pdf

Homework19_R

Distributions of the order statistics: look on the web for the most simple (but still rigorous) and clear derivations of the distributions, explaining in your own words the methods used.

Order statistics

Pdf of the order statistics for a sample of size n = 5 from an exponential distribution with unit scale parameter

In statistics, the kth order statistic of a statistical sample is equal to its kth-smallest value.
It is among the most fundamental tools in non-parametric statistics and inference(With ranks).

Important special cases of the order statistics are the minimum and maximum value of a sample, and the sample median.
The sample median is a particular quantine: q is equal two, so the distribution is split into two part with the same frequencies.

If we have empirical sample, so, we can order it and find the order empirical sample:

Empirical sample

X1,X2,…,Xn

Empirical ordered sample

x(1),x(2),…,x(n)

X(k) means that is the k-th smallest value.

Note: In the case where the distribution F is continuous, we can make the stronger statement that x(1) < x(2) < x(3) < x(4) < x(5)

Probability Density

The PDF, by definition, for X(k) is:


So we can find easily:

Density for the FIRST ordinate statistic:

P{x(1) ∈ (x, x+dx)} = P(one of the X’s ∈ (x, x + dx) and all others > x) = they are iid => nf(x)dx (1 − F(x))n−1 with:

  • nf(x)dx from definition of the density (P{one of the X’s ∈ (x, x + dx)})
  • (1 − F(x))n−1 (P{all others n-1 obs > x + dx }) -> note that is the complement of the CDF

Density for the MAX order statistic:

P{x(n) ∈ (x, x+dx)} = P(one of the X’s ∈ (x, x + dx) and all others < x) = they are iid => nf(x)dx F(x)n−1 with:

  • nf(x)dx from definition of the density (P{one of the X’s ∈ (x, x + dx)})
  • F(x)n−1 (P{all others n-1 obs < x + dx }) -> note that is the CDF

Density for GENERAL case:

We must calculate density for the general case: this is a combinatory problem. (We have different way to distribute the observation in both side)

P{x(k) ∈ (x , x + dx)} =P(one of the X’s ∈ (x, x + dx) and exactly k−1 of the others < x):

Note that this looks like the Beta Distribution(r,s).

We have the binomial coefficient because we must choose k-1 elements from n-1 elements.

https://www2.stat.duke.edu/courses/Spring12/sta104.1/Lectures/Lec15.pdf
https://en.wikipedia.org/wiki/Order_statistic
https://en.wikipedia.org/wiki/Binomial_coefficient

Homework in collaboration with Luca Scarmozzino: https://stats4cyber.wordpress.com/

Homework15_A

Simple illustration of the Glivenko-Cantelli theorem ( http://home.uchicago.edu/~amshaikh/webfiles/glivenko-cantelli_topics.pdf ).
Consider random variables from a Uniform distribution (not necessarily in the same range), and create both the histogram and the empirical CDF of the sample mean. Show with an animation what happens when the number of observations increases. What do we see here?

Update: Code VB.Net v2.0

https://drive.google.com/file/d/1-6fRYwmREvvVgiv-hI7khTEmcMpuZjhg/view?usp=sharing

Changed way to build the path, follow the definition:

1/n * sum (indicator function) with x ​​in R.

VB.NET Code

https://drive.google.com/file/d/1xbpG-stSMS-8T-M6QnoHNYb6cRhZxHw5/view?usp=sharing

We can see that as the number of observations increases, the empirical cdf closest to the real cdf and the histogram take a bell shape. The empirical CDF, infact, usually approximates the CDF quite well, especially for large samples.

I have to thank Luca Scarmozzino who helped me with this homework!
https://stats4cyber.wordpress.com/

https://stats.stackexchange.com/questions/239937/empirical-cdf-vs-cdf