SlideShare a Scribd company logo
1 of 21
Download to read offline
Vu Pham
Scenario Generation Algorithm using R
(without optimization)
26.12.2016 Scenario Generation Algorithm using R 1Ашу Пракаш | Семенов Михаил Евгеньевич
Ashu Prakash
Indian Institute of Technology Kanpur, India
ashupk@iitk.ac.in
Dr Mikhail Semenov
Tomsk Polytechnic University, Russia
sme@tpu.ru
Vu Pham
I’m a third-year undergraduate student majoring in 4 year bachelorship
programme of Mathematics and Scientific Computing in the Department of
Mathematics and Statistics at the Indian Institute of Technology Kanpur,
India
My research area includes parts of Applied Mathematics, Finance,
Microeconomics and Business Analytics. I’m also interested in Computer
Programming and Multivariable Calculus.
I worked as an intern under Prof Mikhail Semenov, Tomsk Polytechnic
University, Russia. My project was to generate scenarios for stock markets
using different techniques (mainly without using optimisation)
A little about myself
26.12.2016 Scenario Generation Algorithm using R 2Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
I worked on an algorithm for moment-matching scenario generation. I tried
to produce scenarios and probability weights that match different moments.
In this approach, the statistical properties of the joint distribution are
specified in terms of moments, basically including the covariance matrix.
Optimisation is not employed in this scenario generation process and thus
this method is computationally more advantageous than previous
approaches. The algorithm is used for generating scenarios in a mean-CVaR
portfolio optimisation model.
This method is proposed in the paper "An algorithm for moment-matching
scenario generation with application to financial portfolio optimisation" by
Ponomareva, Roman, Date, (Published 2015)
Scenario Generation
26.12.2016 Scenario Generation Algorithm using R 3Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
I also worked on the paper “Generating Scenario Trees for Multistage
Decision Problems” by Høyland and Wallace, (Published 2001)
This paper deals with Tree Scenario Generation for multistage decision
problems with approximating the uncertainties by a limited number of
discrete outcomes.
The motivation for developing the method presented in this paper is the
implementation of a stochastic multistage asset allocation model.
There is a different paper which is actually a comment on this paper, by
Klaassen. "Comment on Generating Scenario Trees for Multistage Decision
Problems" by Pieter Klaassen, (Published 2002). This deals with removal of
arbitrage opportunities.
Scenario Generation
26.12.2016 Scenario Generation Algorithm using R 4Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
I have used the programming language R for all the statistical coding for the
generation of proposed algorithms.
My code followed the paper "An algorithm for moment-matching scenario
generation with application to financial portfolio optimisation" by
Ponomareva, Roman, Date, (Published 2015).
I tried to generate probabilities associated with the moment-matching
scenario generation. Mean, Variance, Skewness, Kurtosis are matched in the
proposed algorithm.
The input of the algorithm follows a covariance matrix, mean vector,
skewness and kurtosis. The aim was to generate a vector of positive
probabilities.
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 5Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
Let us assume we have an N – variate random vector r = (r1, r2, r3, … , rN)T
We know the distribution of this random vector in terms of following:
µ : target mean vector
∑ : target covariance matrix (positive definite)
kj : marginal third central moment (skewness) of rj, j = 1, 2, 3, … , N
ƺj : marginal fourth central moment (kurtosis) of rj, j = 1, 2, 3, … , N
We denote the average marginal moments as
Mean skewness : k’ =
1
𝑁
σ 𝑗=1
𝑁
kj
Mean kurtosis : ƺ’ =
1
𝑁
σ 𝑗=1
𝑁
ƺj
An even number of scenarios, 2Ns, proportional to the vector’s dimension,
are generated such that they match the first and second moments. These
scenarios are symmetrically distributed around the expected value such that
the variance–covariance matrix is matched
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 6Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
Three additional scenarios are generated in order to match the average
marginal skewness and the average marginal kurtosis of each individual
component of the random vector r.
Parameters for Scenario Generation
We have the inputs µ, ∑, kj , ƺj . Our programme must choose an arbitrary
positive integer s, an arbitrary nonzero deterministic vector Z, such that
∑ - ZZT > 0, and a scalar ρ ϵ 0,1
We randomly generate a ρ using a normal distribution.
Also, Z is generated using this ρ . We take Zj = ρ σjj (ρ = 0.45, in my case)
Here ∑jj = vector corresponding to the diagonal elements of ∑
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 7Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
The next part is to find L. In the paper, L is defined as a positive definite
matrix such that LLT = ∑ - ZZT . We may use Cholesky decomposition method
on ∑ - ZZT to find L.
Now we generate a random natural number ‘s’ after which we can find the
probability weights. Let pi’s be real scalars such that pi ∈ 0,1 . There are
many ways for generating pi’s.
Note that number of scenarios are independent on the dimension of the
random vector r as ‘s’ is a randomly generated positive integer.
pi’s can be generated by sampling from a uniform distribution or gamma
distribution method. The detailed explanation is provided in the next slide.
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 8Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
One method to generate pi is such that it satisfies
pi =
𝑠
𝑁𝛾
+ (
1
2𝑁𝑠
−
𝑠
𝑁𝛾
) U , where U ∈ 0,1 is a uniformly generated random
variable where 𝛾 is defined as
𝛾 = 2𝑠2
𝑁ƺ’ − 3
4
σ 𝑗=1
𝑁
𝑍4
𝑗
𝑁k'
σ 𝑗=1
𝑁
𝑍3
𝑗
2
σ𝑙 σ 𝑘 𝐿4
𝑙𝑘
Another method of generating pi is from gamma distribution. We generate U
in between (
1
𝑒
, 1 ) by gamma distribution, and taking pi = loge(U). In this
method, we must normalise the weights.
p𝑖′ =
𝑝𝑖
𝑁𝑠(2 σ 𝑝𝑖 + max(𝑝𝑖))
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 9Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
Now, after finding pi’s we must check that the following two conditions are
satisfied.
1.) σ𝑖=1
𝑠
𝑝𝑖 <
1
2𝑁
2.) σ𝑖=1
𝑠 1
𝑝𝑖
< 𝛾 if 𝛾 𝑖𝑠 𝑢𝑠𝑒𝑑
We define a new element in the vector p, ps+1 = 1 – 2N σ𝑖=1
𝑠
𝑝𝑖
Now we will define 𝜑1 𝑎𝑛𝑑 𝜑2 which will be used to find probabilities.
𝜑1 =
𝑁𝑘′ ps
+
1
σ 𝑗=1
𝑁
𝑍3
𝑗
and 𝜑2 = ps+1
𝑁ƺ’ −
1
2𝑠
2 σ 𝑙 σ 𝑘 𝐿4
𝑙𝑘
(σ𝑖=1
𝑠 1
𝑝𝑖
)
σ 𝑗=1
𝑁
𝑍4
𝑗
After determining the above values, we’ll find 𝛼 and 𝛽.
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 10Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
We define 𝛼 and 𝛽 as follows :
𝛼 = +
1
2
𝜑1 +
1
2
4𝜑2 − 3𝜑1
2
𝛽 = −
1
2
𝜑1 +
1
2
4𝜑2 − 3𝜑1
2
In our algorithm, we must have 4𝜑2 − 3𝜑1
2 ≥ 0
We define w1, w2 and w0 .
w1 =
1
𝛼(𝛼+𝛽)
, w2 =
1
𝛽(𝛼+𝛽)
and w0 = 1 -
1
𝛼𝛽
Observe that w1 + w2 + w0 = 1
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 11Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
After finding these values, our aim is to find the probability weights P.
We define, S = 2Ns + 3. Given p1, p2, … , ps+1 and w0 , w1, w2 from previous
steps. Vector P is formed as follows :
𝑃 = 𝑝1, 𝑝2, … , 𝑝 𝑠, 𝑝1, 𝑝2, … , 𝑝 𝑠, … , 𝑝 𝑠 + 1 𝑤0, 𝑝 𝑠 + 1 𝑤1, 𝑝 𝑠 + 1 𝑤2
All the elements of P must be non-negative. Also, σ 𝑃 = 1
Note that there is no optimisation involved in this whole algorithm.
Since there is no algorithm involved in this method, it’s the fastest way for
the moment-matching scenario generation.
My code in R is described in coming slides.
Scenario Generation Algorithm
26.12.2016 Scenario Generation Algorithm using R 12Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
My code in R
Initialising inputs for the algorithm.
Implementation of Algorithm in R
26.12.2016 Scenario Generation Algorithm using R 13Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
My code in R
We randomly generate ‘s’ (an integer ranging between 1 and 10000)
L is generated using Cholesky decomposition method.
Note: L must be positive definite
Implementation of Algorithm in R
26.12.2016 Scenario Generation Algorithm using R 14Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
My code in R (Loop is used to find the vector P with only positive elements)
Implementation of Algorithm in R
26.12.2016 Scenario Generation Algorithm using R 15Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
My code in R
Implementation of Algorithm in R
26.12.2016 Scenario Generation Algorithm using R 16Ашу Пракаш | Семенов Михаил Евгеньевич
𝛼, 𝛽, 𝑤1, 𝑤2 𝑎𝑛𝑑 𝑤0 𝑎𝑟𝑒 𝑑𝑒𝑓𝑖𝑛𝑒𝑑
Vector P with S = 2Ns + 3
elements is formed
For loop is created so that only
elements with positive values are in the
output result.
This code also checks
4𝜑2 − 3𝜑1
2 ≥ 0
Vu Pham
My code in R (Finalising the code)
The main loop is closed.
In the output vector P, sum of all the elements must be 1.
sum(P) = 1 ??? Yes
Finally we can get the value of ‘s’ at which the loop terminated.
Implementation of Algorithm in R
26.12.2016 Scenario Generation Algorithm using R 17Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
I also did some works with Prof Semenov. I tried to understand one of his
research paper on Options Portfolio.
I’m still working with an algorithm in that paper and like to work further in
the future.
I read some more research papers on Stock Market Scenario Generation.
I thank Prof Mikhail Semenov for mentoring me in this one month project. I
learned a lot during this time period.
I also thank National Research Tomsk Polytechnic University, Russia for
giving this research internship opportunity.
Internship at TPU
26.12.2016 Scenario Generation Algorithm using R 18Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
IIT Kanpur and TPU has an agreement on academic research collaboration
which was signed on 06.07.2015
IITK and TPU have many areas of common interest in education and
research.
This collaborative agreement has programmes like
a) Faculty/Scientist/Staff exchanges
b) Student exchanges (at both UG and PG level)
TPU is the only university in Russia with which IITK has a collaboration.
Our agreement is valid up to 06.07.2020
IITK & TPU Collaboration
26.12.2016 Scenario Generation Algorithm using R 19Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
Ponomareva, Roman, Date, “An algorithm for moment-matching scenario
generation with application to financial portfolio optimisation”. (European
Journal of Operational Research, 2015)
Høyland and Wallace, “Generating Scenario Trees for Multistage Decision
Problems”. (Norwegian University of Science and Technology, 2001)
Pieter Klaassen, Comment on “Generating Scenario Trees for Multistage
Decision Problems”. (The Netherlands, Vrije Universiteit, 2002)
Hoffman, “Combinatorial optimization: Current successes and directions for
the future”. (Journal of Computational and Applied Mathematics 124 (2000)
341-360)
Mico Loretan, “Generating market risk scenarios using principal components
analysis: methodological and practical considerations”. (Federal Reserve
Board, March 1997)
Wurtz, Chalabi, Chen, Ellis, “Portfolio Optimization with R/Rmetrics”.
(Zurich, Rmetrics Association & Finance Online, May 2009)
References
26.12.2016 Scenario Generation Algorithm using R 20Ашу Пракаш | Семенов Михаил Евгеньевич
Vu Pham
СПАСИБО
Thank You !
26.12.2016 Scenario Generation Algorithm using R 21Ашу Пракаш | Семенов Михаил Евгеньевич

More Related Content

What's hot

Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
 
Statr session 25 and 26
Statr session 25 and 26Statr session 25 and 26
Statr session 25 and 26Ruru Chowdhury
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetHoang Nguyen Phong
 
Linear regression by Kodebay
Linear regression by KodebayLinear regression by Kodebay
Linear regression by KodebayKodebay
 
Singh presentation
Singh presentationSingh presentation
Singh presentationgagan22
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetHoang Nguyen Phong
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applicationsRinkuMonani
 
Gauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingGauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingSM. Aurnob
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss SeidelEric Davishahl
 

What's hot (13)

D0422025033
D0422025033D0422025033
D0422025033
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Exp keja 1
Exp keja 1Exp keja 1
Exp keja 1
 
Statr session 25 and 26
Statr session 25 and 26Statr session 25 and 26
Statr session 25 and 26
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
 
Brute force
Brute forceBrute force
Brute force
 
Linear regression by Kodebay
Linear regression by KodebayLinear regression by Kodebay
Linear regression by Kodebay
 
Singh presentation
Singh presentationSingh presentation
Singh presentation
 
Extrapolation
ExtrapolationExtrapolation
Extrapolation
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
 
Gauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingGauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial Pivoting
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss Seidel
 

Viewers also liked

Discovering Discovery
Discovering DiscoveryDiscovering Discovery
Discovering DiscoveryFayjur Rahman
 
Sahbe haftomin badr
Sahbe haftomin badrSahbe haftomin badr
Sahbe haftomin badrArsalan Jala
 
Whitehall International Newsletter
Whitehall International NewsletterWhitehall International Newsletter
Whitehall International NewsletterMaura Satchell
 
Bases de la terapeutica quirurgica cancer de endometrio
Bases de la terapeutica quirurgica cancer de endometrioBases de la terapeutica quirurgica cancer de endometrio
Bases de la terapeutica quirurgica cancer de endometriogsa14solano
 
методичні рекомендації ро роботі в компас
методичні рекомендації ро роботі в компасметодичні рекомендації ро роботі в компас
методичні рекомендації ро роботі в компасcdecit
 
Building the future: perspectives on large scale change
Building the future: perspectives on large scale changeBuilding the future: perspectives on large scale change
Building the future: perspectives on large scale changeNHS Improving Quality
 
MicroGuide app, pop up uni, 1pm, 3 september 2015
MicroGuide app, pop up uni, 1pm, 3 september 2015MicroGuide app, pop up uni, 1pm, 3 september 2015
MicroGuide app, pop up uni, 1pm, 3 september 2015NHS England
 
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...HIMSS UK
 
Sesion iecan gil
Sesion iecan gilSesion iecan gil
Sesion iecan gilgsa14solano
 
Biología molecular del cacu
Biología molecular del cacuBiología molecular del cacu
Biología molecular del cacugsa14solano
 
Especialidade em Astronomia - Desbravadores
Especialidade em Astronomia - DesbravadoresEspecialidade em Astronomia - Desbravadores
Especialidade em Astronomia - DesbravadoresAndré Luiz Marques
 
camping
campingcamping
campingCaratR
 
Carat media news_letter-871report
Carat media news_letter-871reportCarat media news_letter-871report
Carat media news_letter-871reportCaratR
 
Bambuild Brand Design Guidelines
Bambuild Brand Design Guidelines Bambuild Brand Design Guidelines
Bambuild Brand Design Guidelines Lauren Johnson
 
técnicas inyección de contraste en tc
técnicas inyección de contraste en tctécnicas inyección de contraste en tc
técnicas inyección de contraste en tccristiancg2005
 
Rastreamento e diagnóstico precoce do câncer de mama 19 set2012
Rastreamento e diagnóstico precoce  do câncer de mama 19 set2012Rastreamento e diagnóstico precoce  do câncer de mama 19 set2012
Rastreamento e diagnóstico precoce do câncer de mama 19 set2012Graciela Luongo
 
Formación de imagen en TC
Formación de imagen en TCFormación de imagen en TC
Formación de imagen en TCAndrea Yáñez
 
Anatomia Y Fisiologia De La Glandula Mamaria
Anatomia Y Fisiologia De La Glandula MamariaAnatomia Y Fisiologia De La Glandula Mamaria
Anatomia Y Fisiologia De La Glandula MamariaDANTX
 

Viewers also liked (20)

Discovering Discovery
Discovering DiscoveryDiscovering Discovery
Discovering Discovery
 
Sahbe haftomin badr
Sahbe haftomin badrSahbe haftomin badr
Sahbe haftomin badr
 
Whitehall International Newsletter
Whitehall International NewsletterWhitehall International Newsletter
Whitehall International Newsletter
 
Bases de la terapeutica quirurgica cancer de endometrio
Bases de la terapeutica quirurgica cancer de endometrioBases de la terapeutica quirurgica cancer de endometrio
Bases de la terapeutica quirurgica cancer de endometrio
 
методичні рекомендації ро роботі в компас
методичні рекомендації ро роботі в компасметодичні рекомендації ро роботі в компас
методичні рекомендації ро роботі в компас
 
Building the future: perspectives on large scale change
Building the future: perspectives on large scale changeBuilding the future: perspectives on large scale change
Building the future: perspectives on large scale change
 
MicroGuide app, pop up uni, 1pm, 3 september 2015
MicroGuide app, pop up uni, 1pm, 3 september 2015MicroGuide app, pop up uni, 1pm, 3 september 2015
MicroGuide app, pop up uni, 1pm, 3 september 2015
 
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...
The Art of the Possible – Enabling Care Homes with Technology to Reduce Admis...
 
Sesion iecan gil
Sesion iecan gilSesion iecan gil
Sesion iecan gil
 
Biología molecular del cacu
Biología molecular del cacuBiología molecular del cacu
Biología molecular del cacu
 
Especialidade em Astronomia - Desbravadores
Especialidade em Astronomia - DesbravadoresEspecialidade em Astronomia - Desbravadores
Especialidade em Astronomia - Desbravadores
 
camping
campingcamping
camping
 
Carat media news_letter-871report
Carat media news_letter-871reportCarat media news_letter-871report
Carat media news_letter-871report
 
Bambuild Brand Design Guidelines
Bambuild Brand Design Guidelines Bambuild Brand Design Guidelines
Bambuild Brand Design Guidelines
 
técnicas inyección de contraste en tc
técnicas inyección de contraste en tctécnicas inyección de contraste en tc
técnicas inyección de contraste en tc
 
Métodos de biópsia no cancer de mama
Métodos de biópsia no cancer de mamaMétodos de biópsia no cancer de mama
Métodos de biópsia no cancer de mama
 
Rastreamento e diagnóstico precoce do câncer de mama 19 set2012
Rastreamento e diagnóstico precoce  do câncer de mama 19 set2012Rastreamento e diagnóstico precoce  do câncer de mama 19 set2012
Rastreamento e diagnóstico precoce do câncer de mama 19 set2012
 
Formación de imagen en TC
Formación de imagen en TCFormación de imagen en TC
Formación de imagen en TC
 
Anatomia Y Fisiologia De La Glandula Mamaria
Anatomia Y Fisiologia De La Glandula MamariaAnatomia Y Fisiologia De La Glandula Mamaria
Anatomia Y Fisiologia De La Glandula Mamaria
 
Patrones radiologicos pulmonares
Patrones radiologicos pulmonaresPatrones radiologicos pulmonares
Patrones radiologicos pulmonares
 

Similar to Scenario Generation Algortihm using R

Intro to Quant Trading Strategies (Lecture 2 of 10)
Intro to Quant Trading Strategies (Lecture 2 of 10)Intro to Quant Trading Strategies (Lecture 2 of 10)
Intro to Quant Trading Strategies (Lecture 2 of 10)Adrian Aley
 
Riemannian gossip algorithms for decentralized matrix completion
Riemannian gossip algorithms for decentralized matrix completionRiemannian gossip algorithms for decentralized matrix completion
Riemannian gossip algorithms for decentralized matrix completionBamdev Mishra
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmJim Jimenez
 
QTML2021 UAP Quantum Feature Map
QTML2021 UAP Quantum Feature MapQTML2021 UAP Quantum Feature Map
QTML2021 UAP Quantum Feature MapHa Phuong
 
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...AIST
 
One Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical ComputationOne Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical ComputationWork-Bench
 
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...Waqas Tariq
 
STLtalk about statistical analysis and its application
STLtalk about statistical analysis and its applicationSTLtalk about statistical analysis and its application
STLtalk about statistical analysis and its applicationJulieDash5
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docxmccormicknadine86
 
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...Lviv Startup Club
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docxbissacr
 
Koh_Liang_ICML2017
Koh_Liang_ICML2017Koh_Liang_ICML2017
Koh_Liang_ICML2017Masa Kato
 
A new Evolutionary Reinforcement Scheme for Stochastic Learning Automata
A new Evolutionary Reinforcement Scheme for Stochastic Learning AutomataA new Evolutionary Reinforcement Scheme for Stochastic Learning Automata
A new Evolutionary Reinforcement Scheme for Stochastic Learning Automatainfopapers
 
!Business statistics tekst
!Business statistics tekst!Business statistics tekst
!Business statistics tekstKing Nisar
 

Similar to Scenario Generation Algortihm using R (20)

Intro to Quant Trading Strategies (Lecture 2 of 10)
Intro to Quant Trading Strategies (Lecture 2 of 10)Intro to Quant Trading Strategies (Lecture 2 of 10)
Intro to Quant Trading Strategies (Lecture 2 of 10)
 
Riemannian gossip algorithms for decentralized matrix completion
Riemannian gossip algorithms for decentralized matrix completionRiemannian gossip algorithms for decentralized matrix completion
Riemannian gossip algorithms for decentralized matrix completion
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
QTML2021 UAP Quantum Feature Map
QTML2021 UAP Quantum Feature MapQTML2021 UAP Quantum Feature Map
QTML2021 UAP Quantum Feature Map
 
Methods of point estimation
Methods of point estimationMethods of point estimation
Methods of point estimation
 
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
 
One Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical ComputationOne Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical Computation
 
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...
A Computationally Efficient Algorithm to Solve Generalized Method of Moments ...
 
STLtalk about statistical analysis and its application
STLtalk about statistical analysis and its applicationSTLtalk about statistical analysis and its application
STLtalk about statistical analysis and its application
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docx
 
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...
Богдан Павлишенко (Bohdan Pavlyshenko) - "Linear, Machine Learning and Probab...
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docx
 
Koh_Liang_ICML2017
Koh_Liang_ICML2017Koh_Liang_ICML2017
Koh_Liang_ICML2017
 
A new Evolutionary Reinforcement Scheme for Stochastic Learning Automata
A new Evolutionary Reinforcement Scheme for Stochastic Learning AutomataA new Evolutionary Reinforcement Scheme for Stochastic Learning Automata
A new Evolutionary Reinforcement Scheme for Stochastic Learning Automata
 
Hmm and neural networks
Hmm and neural networksHmm and neural networks
Hmm and neural networks
 
Finite Difference Method for Nonlocal Singularly Perturbed Problem
Finite Difference Method for Nonlocal Singularly Perturbed ProblemFinite Difference Method for Nonlocal Singularly Perturbed Problem
Finite Difference Method for Nonlocal Singularly Perturbed Problem
 
1. linear model, inference, prediction
1. linear model, inference, prediction1. linear model, inference, prediction
1. linear model, inference, prediction
 
!Business statistics tekst
!Business statistics tekst!Business statistics tekst
!Business statistics tekst
 
Dismath part2 2013
Dismath part2 2013Dismath part2 2013
Dismath part2 2013
 

Scenario Generation Algortihm using R

  • 1. Vu Pham Scenario Generation Algorithm using R (without optimization) 26.12.2016 Scenario Generation Algorithm using R 1Ашу Пракаш | Семенов Михаил Евгеньевич Ashu Prakash Indian Institute of Technology Kanpur, India ashupk@iitk.ac.in Dr Mikhail Semenov Tomsk Polytechnic University, Russia sme@tpu.ru
  • 2. Vu Pham I’m a third-year undergraduate student majoring in 4 year bachelorship programme of Mathematics and Scientific Computing in the Department of Mathematics and Statistics at the Indian Institute of Technology Kanpur, India My research area includes parts of Applied Mathematics, Finance, Microeconomics and Business Analytics. I’m also interested in Computer Programming and Multivariable Calculus. I worked as an intern under Prof Mikhail Semenov, Tomsk Polytechnic University, Russia. My project was to generate scenarios for stock markets using different techniques (mainly without using optimisation) A little about myself 26.12.2016 Scenario Generation Algorithm using R 2Ашу Пракаш | Семенов Михаил Евгеньевич
  • 3. Vu Pham I worked on an algorithm for moment-matching scenario generation. I tried to produce scenarios and probability weights that match different moments. In this approach, the statistical properties of the joint distribution are specified in terms of moments, basically including the covariance matrix. Optimisation is not employed in this scenario generation process and thus this method is computationally more advantageous than previous approaches. The algorithm is used for generating scenarios in a mean-CVaR portfolio optimisation model. This method is proposed in the paper "An algorithm for moment-matching scenario generation with application to financial portfolio optimisation" by Ponomareva, Roman, Date, (Published 2015) Scenario Generation 26.12.2016 Scenario Generation Algorithm using R 3Ашу Пракаш | Семенов Михаил Евгеньевич
  • 4. Vu Pham I also worked on the paper “Generating Scenario Trees for Multistage Decision Problems” by Høyland and Wallace, (Published 2001) This paper deals with Tree Scenario Generation for multistage decision problems with approximating the uncertainties by a limited number of discrete outcomes. The motivation for developing the method presented in this paper is the implementation of a stochastic multistage asset allocation model. There is a different paper which is actually a comment on this paper, by Klaassen. "Comment on Generating Scenario Trees for Multistage Decision Problems" by Pieter Klaassen, (Published 2002). This deals with removal of arbitrage opportunities. Scenario Generation 26.12.2016 Scenario Generation Algorithm using R 4Ашу Пракаш | Семенов Михаил Евгеньевич
  • 5. Vu Pham I have used the programming language R for all the statistical coding for the generation of proposed algorithms. My code followed the paper "An algorithm for moment-matching scenario generation with application to financial portfolio optimisation" by Ponomareva, Roman, Date, (Published 2015). I tried to generate probabilities associated with the moment-matching scenario generation. Mean, Variance, Skewness, Kurtosis are matched in the proposed algorithm. The input of the algorithm follows a covariance matrix, mean vector, skewness and kurtosis. The aim was to generate a vector of positive probabilities. Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 5Ашу Пракаш | Семенов Михаил Евгеньевич
  • 6. Vu Pham Let us assume we have an N – variate random vector r = (r1, r2, r3, … , rN)T We know the distribution of this random vector in terms of following: µ : target mean vector ∑ : target covariance matrix (positive definite) kj : marginal third central moment (skewness) of rj, j = 1, 2, 3, … , N ƺj : marginal fourth central moment (kurtosis) of rj, j = 1, 2, 3, … , N We denote the average marginal moments as Mean skewness : k’ = 1 𝑁 σ 𝑗=1 𝑁 kj Mean kurtosis : ƺ’ = 1 𝑁 σ 𝑗=1 𝑁 ƺj An even number of scenarios, 2Ns, proportional to the vector’s dimension, are generated such that they match the first and second moments. These scenarios are symmetrically distributed around the expected value such that the variance–covariance matrix is matched Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 6Ашу Пракаш | Семенов Михаил Евгеньевич
  • 7. Vu Pham Three additional scenarios are generated in order to match the average marginal skewness and the average marginal kurtosis of each individual component of the random vector r. Parameters for Scenario Generation We have the inputs µ, ∑, kj , ƺj . Our programme must choose an arbitrary positive integer s, an arbitrary nonzero deterministic vector Z, such that ∑ - ZZT > 0, and a scalar ρ ϵ 0,1 We randomly generate a ρ using a normal distribution. Also, Z is generated using this ρ . We take Zj = ρ σjj (ρ = 0.45, in my case) Here ∑jj = vector corresponding to the diagonal elements of ∑ Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 7Ашу Пракаш | Семенов Михаил Евгеньевич
  • 8. Vu Pham The next part is to find L. In the paper, L is defined as a positive definite matrix such that LLT = ∑ - ZZT . We may use Cholesky decomposition method on ∑ - ZZT to find L. Now we generate a random natural number ‘s’ after which we can find the probability weights. Let pi’s be real scalars such that pi ∈ 0,1 . There are many ways for generating pi’s. Note that number of scenarios are independent on the dimension of the random vector r as ‘s’ is a randomly generated positive integer. pi’s can be generated by sampling from a uniform distribution or gamma distribution method. The detailed explanation is provided in the next slide. Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 8Ашу Пракаш | Семенов Михаил Евгеньевич
  • 9. Vu Pham One method to generate pi is such that it satisfies pi = 𝑠 𝑁𝛾 + ( 1 2𝑁𝑠 − 𝑠 𝑁𝛾 ) U , where U ∈ 0,1 is a uniformly generated random variable where 𝛾 is defined as 𝛾 = 2𝑠2 𝑁ƺ’ − 3 4 σ 𝑗=1 𝑁 𝑍4 𝑗 𝑁k' σ 𝑗=1 𝑁 𝑍3 𝑗 2 σ𝑙 σ 𝑘 𝐿4 𝑙𝑘 Another method of generating pi is from gamma distribution. We generate U in between ( 1 𝑒 , 1 ) by gamma distribution, and taking pi = loge(U). In this method, we must normalise the weights. p𝑖′ = 𝑝𝑖 𝑁𝑠(2 σ 𝑝𝑖 + max(𝑝𝑖)) Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 9Ашу Пракаш | Семенов Михаил Евгеньевич
  • 10. Vu Pham Now, after finding pi’s we must check that the following two conditions are satisfied. 1.) σ𝑖=1 𝑠 𝑝𝑖 < 1 2𝑁 2.) σ𝑖=1 𝑠 1 𝑝𝑖 < 𝛾 if 𝛾 𝑖𝑠 𝑢𝑠𝑒𝑑 We define a new element in the vector p, ps+1 = 1 – 2N σ𝑖=1 𝑠 𝑝𝑖 Now we will define 𝜑1 𝑎𝑛𝑑 𝜑2 which will be used to find probabilities. 𝜑1 = 𝑁𝑘′ ps + 1 σ 𝑗=1 𝑁 𝑍3 𝑗 and 𝜑2 = ps+1 𝑁ƺ’ − 1 2𝑠 2 σ 𝑙 σ 𝑘 𝐿4 𝑙𝑘 (σ𝑖=1 𝑠 1 𝑝𝑖 ) σ 𝑗=1 𝑁 𝑍4 𝑗 After determining the above values, we’ll find 𝛼 and 𝛽. Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 10Ашу Пракаш | Семенов Михаил Евгеньевич
  • 11. Vu Pham We define 𝛼 and 𝛽 as follows : 𝛼 = + 1 2 𝜑1 + 1 2 4𝜑2 − 3𝜑1 2 𝛽 = − 1 2 𝜑1 + 1 2 4𝜑2 − 3𝜑1 2 In our algorithm, we must have 4𝜑2 − 3𝜑1 2 ≥ 0 We define w1, w2 and w0 . w1 = 1 𝛼(𝛼+𝛽) , w2 = 1 𝛽(𝛼+𝛽) and w0 = 1 - 1 𝛼𝛽 Observe that w1 + w2 + w0 = 1 Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 11Ашу Пракаш | Семенов Михаил Евгеньевич
  • 12. Vu Pham After finding these values, our aim is to find the probability weights P. We define, S = 2Ns + 3. Given p1, p2, … , ps+1 and w0 , w1, w2 from previous steps. Vector P is formed as follows : 𝑃 = 𝑝1, 𝑝2, … , 𝑝 𝑠, 𝑝1, 𝑝2, … , 𝑝 𝑠, … , 𝑝 𝑠 + 1 𝑤0, 𝑝 𝑠 + 1 𝑤1, 𝑝 𝑠 + 1 𝑤2 All the elements of P must be non-negative. Also, σ 𝑃 = 1 Note that there is no optimisation involved in this whole algorithm. Since there is no algorithm involved in this method, it’s the fastest way for the moment-matching scenario generation. My code in R is described in coming slides. Scenario Generation Algorithm 26.12.2016 Scenario Generation Algorithm using R 12Ашу Пракаш | Семенов Михаил Евгеньевич
  • 13. Vu Pham My code in R Initialising inputs for the algorithm. Implementation of Algorithm in R 26.12.2016 Scenario Generation Algorithm using R 13Ашу Пракаш | Семенов Михаил Евгеньевич
  • 14. Vu Pham My code in R We randomly generate ‘s’ (an integer ranging between 1 and 10000) L is generated using Cholesky decomposition method. Note: L must be positive definite Implementation of Algorithm in R 26.12.2016 Scenario Generation Algorithm using R 14Ашу Пракаш | Семенов Михаил Евгеньевич
  • 15. Vu Pham My code in R (Loop is used to find the vector P with only positive elements) Implementation of Algorithm in R 26.12.2016 Scenario Generation Algorithm using R 15Ашу Пракаш | Семенов Михаил Евгеньевич
  • 16. Vu Pham My code in R Implementation of Algorithm in R 26.12.2016 Scenario Generation Algorithm using R 16Ашу Пракаш | Семенов Михаил Евгеньевич 𝛼, 𝛽, 𝑤1, 𝑤2 𝑎𝑛𝑑 𝑤0 𝑎𝑟𝑒 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 Vector P with S = 2Ns + 3 elements is formed For loop is created so that only elements with positive values are in the output result. This code also checks 4𝜑2 − 3𝜑1 2 ≥ 0
  • 17. Vu Pham My code in R (Finalising the code) The main loop is closed. In the output vector P, sum of all the elements must be 1. sum(P) = 1 ??? Yes Finally we can get the value of ‘s’ at which the loop terminated. Implementation of Algorithm in R 26.12.2016 Scenario Generation Algorithm using R 17Ашу Пракаш | Семенов Михаил Евгеньевич
  • 18. Vu Pham I also did some works with Prof Semenov. I tried to understand one of his research paper on Options Portfolio. I’m still working with an algorithm in that paper and like to work further in the future. I read some more research papers on Stock Market Scenario Generation. I thank Prof Mikhail Semenov for mentoring me in this one month project. I learned a lot during this time period. I also thank National Research Tomsk Polytechnic University, Russia for giving this research internship opportunity. Internship at TPU 26.12.2016 Scenario Generation Algorithm using R 18Ашу Пракаш | Семенов Михаил Евгеньевич
  • 19. Vu Pham IIT Kanpur and TPU has an agreement on academic research collaboration which was signed on 06.07.2015 IITK and TPU have many areas of common interest in education and research. This collaborative agreement has programmes like a) Faculty/Scientist/Staff exchanges b) Student exchanges (at both UG and PG level) TPU is the only university in Russia with which IITK has a collaboration. Our agreement is valid up to 06.07.2020 IITK & TPU Collaboration 26.12.2016 Scenario Generation Algorithm using R 19Ашу Пракаш | Семенов Михаил Евгеньевич
  • 20. Vu Pham Ponomareva, Roman, Date, “An algorithm for moment-matching scenario generation with application to financial portfolio optimisation”. (European Journal of Operational Research, 2015) Høyland and Wallace, “Generating Scenario Trees for Multistage Decision Problems”. (Norwegian University of Science and Technology, 2001) Pieter Klaassen, Comment on “Generating Scenario Trees for Multistage Decision Problems”. (The Netherlands, Vrije Universiteit, 2002) Hoffman, “Combinatorial optimization: Current successes and directions for the future”. (Journal of Computational and Applied Mathematics 124 (2000) 341-360) Mico Loretan, “Generating market risk scenarios using principal components analysis: methodological and practical considerations”. (Federal Reserve Board, March 1997) Wurtz, Chalabi, Chen, Ellis, “Portfolio Optimization with R/Rmetrics”. (Zurich, Rmetrics Association & Finance Online, May 2009) References 26.12.2016 Scenario Generation Algorithm using R 20Ашу Пракаш | Семенов Михаил Евгеньевич
  • 21. Vu Pham СПАСИБО Thank You ! 26.12.2016 Scenario Generation Algorithm using R 21Ашу Пракаш | Семенов Михаил Евгеньевич