УДК 336.761.6 

Evaluation of shock influences on Russian financial market using R
Ivanov Nikita, B.Sc.
Davnis Valeriy, Ph.D., professor 
Voronezh state university, Universitetskaya ploshad street, building 1, Voronezh, Russia, 394006, email: ivan.nikita2010@yandex.ru
Purpose: explore how political (local conflicts) and economical (sanctions imposed by US and Europe governments) shocks affect local financial market “Risk – Return” curve. Discussion:  we use Modern portfolio theory to build “before shock  Risk – Return curve” and “after shock Risk- Return curve”. For the “before shock” period we use securities prices from 31 Dec 2011 to 31 Dec 2013. “After shock” period is defined from 31 Dec 2013 to 31 Dec 2015. We then compare two curves and summarize our results. Results: we see that “after shock Risk – Return curve” lies righter than the “before shock” one. We observe growth in risk in recent 2 years. Finally, we see that in the “after shock” period investors could gain returns that they couldn’t reach in the “before shock’ period. 
Key words: modern portfolio theory, risk, return, shock

Introduction
Modern portfolio theory (MPT) is a theory of finance that attempts to maximize portfolio expected return for a given amount of portfolio risk, or equivalently minimize risk for a given level of expected return, by carefully choosing the proportions of various assets. This theory was introduced by Hurry Markowitz in 1952 in his article [2] and a book in 1959 [3].  In our article we use MPT to construct “Risk – Return” curve for Russian financial market. In our case Russian market includes major securities (“blue chips”) that represent key sectors of the economy. 
Methodology
We construct two portfolios (two “Risk – Return” curves) - “before shock” and “after shock” – and determine how shocks influence local financial market. “Before shock” period for risk-return calculation is determined from 31 December 2011 to 31 December 2013 when political and other factors that influence the economy were pretty stable. “After shock” period is determined from 31 December 2013 to 31 December 2015 and represents period of political (Crimea conflict) and economical (sanctions posed on Russian economy by governments of USA and Europe) influences on the whole Russian economy and local financial market in particularly.  We explore how such shocks changed, if they are, a position of local market “Risk – Return” curve and what is the difference between “before” and “after shock” periods. We include following 9 securities in our portfolio: Norilsk Nickel (GMKN), Avtovaz (AVAZ), Severstal (CHFM), Rosseti (RSTI), Lukoil (LKOH), Magnit (MGNT), Polyus Gold (PLZL), Sberbank (SBER), Pharmstandard (PHST). All of them are traded on the “Moscow Exchange MICEX-RTS”.
In theory there exist different approaches to find weights of securities that bring minimum level of risk for a given level of return. In our little survey we do this calculus in R using function “solve.QP” from package “Quadprog”. This implies using approach supplied by Goldfarb and Idnani in [3, 4].  We determine vector of returns and use quadratic programming (solve.QP function) to find combinations of weights minimizing vector of standard deviations. In matrix formulation we minimize following expression  with constraint, where  and  matrix and vector to be minimized,  is a vector holding the values of   and  is a matrix containing the non-zero elements of the matrix  that defines the constraints.
Practice part
First we download data for Russian companies ("blue chips") that represent main industries in the economy. We use period between 01 Jan 2012 and 31 Dec 2013. A code below is shown only for one stock (GMKN) to calculate its monthly returns. A code for other assets is the same and will be lying behind the scenes.
GMKN.data <- read.csv("GMKN_120101_131231.csv", header = T, sep = ";")
GMKN.data <- GMKN.data[-25, ]
date <- seq(as.Date("2014-01-01"), as.Date("2015-12-01"), by = "month")
GMKN.data <- cbind(date, GMKN.data[, c(3, 8)])
library(xts)
GMKN.data <- xts(GMKN.data[, 3], order.by = GMKN.data[, 1])
library(quantmod)
GMKN.ret <- Delt(GMKN.data)[-1, ]
names(GMKN.ret) <- "GMKN.ret"
head(GMKN.ret)
##                GMKN.ret
## 2014-02-01 -0.006019952
## 2014-03-01 -0.065582281
## 2014-04-01 -0.035555556
## 2014-05-01 -0.053763441
## 2014-06-01  0.090909091
## 2014-07-01 -0.069568452
Then we group our data of returns into one table. We calculate average return for each asset using apply operator in R. We determine minimum and maximum returns that we will need in further analysis. Finally we calculate variance-covariance matrix for our set of returns.
Russian_1.ret <- cbind(GMKN.ret, AVAZ.ret, CHMF.ret, RSTI.ret, LKOH.ret, MGNT.ret, PLZL.ret, SBER.ret, PHST.ret)
Russian_1.avg.ret <- apply(Russian_1.ret, 2, mean)
Russian_1.min.ret <- min(Russian_1.avg.ret)
Russian_1.max.ret <- max(Russian_1.avg.ret)
Russian_1.min.ret
## [1] -0.03901559
Russian_1.max.ret
## [1] 0.0484453
VCOV_Russian_1 <- cov(Russian_1.ret)
VCOV_Russian_1
##              GMKN.ret      AVAZ.ret      CHMF.ret    RSTI.ret     LKOH.ret
## GMKN.ret 0.0044257689  0.0030277893  0.0015592575 0.004197792 0.0011909327
## AVAZ.ret 0.0030277893  0.0095930042  0.0041125644 0.007332716 0.0007655863
## CHMF.ret 0.0015592575  0.0041125644  0.0082513454 0.003450032 0.0008694756
## RSTI.ret 0.0041977915  0.0073327155  0.0034500317 0.028295340 0.0028602017
## LKOH.ret 0.0011909327  0.0007655863  0.0008694756 0.002860202 0.0010853000
## MGNT.ret 0.0016605639 -0.0001538017  0.0005970387 0.003148203 0.0009979531
## PLZL.ret 0.0022048448  0.0006962388  0.0041735839 0.008385899 0.0016752879
## SBER.ret 0.0017349305  0.0005744905  0.0021063992 0.004139068 0.0012819704
## PHST.ret 0.0004477741  0.0005252903 -0.0033157985 0.001402582 0.0003974972
##               MGNT.ret     PLZL.ret     SBER.ret      PHST.ret
## GMKN.ret  0.0016605639 0.0022048448 0.0017349305  0.0004477741
## AVAZ.ret -0.0001538017 0.0006962388 0.0005744905  0.0005252903
## CHMF.ret  0.0005970387 0.0041735839 0.0021063992 -0.0033157985
## RSTI.ret  0.0031482030 0.0083858988 0.0041390676  0.0014025817
## LKOH.ret  0.0009979531 0.0016752879 0.0012819704  0.0003974972
## MGNT.ret  0.0046152114 0.0037334474 0.0036935088  0.0024634161
## PLZL.ret  0.0037334474 0.0146460816 0.0054660305  0.0027448855
## SBER.ret  0.0036935088 0.0054660305 0.0044938821  0.0026391852
## PHST.ret  0.0024634161 0.0027448855 0.0026391852  0.0087146659
Now we create vectors for return, standard deviation and weights for our portfolio. While in our case quadratic programming finds the combination of securities that yield minimum risk for a specific level of return, we need to set our return target vector. Lower bound of this vector will, obviously, be the minimum return in our matrix of returns. It is not so obvious which value to choose for our upper bound of the vector of target returns. Since we allow short selling we may achieve higher return than the maximum return in a matrix of returns. In our case as an upper bound for the target vector we use maximum return multiplied by 2 as it suggested in [1].
Russian_1.tgt.ret <- seq(Russian_1.min.ret, Russian_1.max.ret*2, length = 100)
Russian_1.tgt.sd <- rep(0, length = 100)
Russian_1.wgt <- matrix(0, nrow = 100, ncol = 9)
We are ready to run the optimizer. For this purposes we use function "solve.QP" from the package "Quadproq". Optimizer will fill in with appropriate values our standard deviations and weights vectors.
library(quadprog)
for (i in 1:length(Russian_1.tgt.ret)) {
  Dmat <- 2*VCOV_Russian_1
  dvec <- c(rep(0, length(Russian_1.avg.ret)))
  Amat <- cbind(rep(1, length(Russian_1.avg.ret)), Russian_1.avg.ret)
  bvec <- c(1, Russian_1.tgt.ret[i])
  soln <- solve.QP(Dmat, dvec, Amat, bvec = bvec, meq = 2)
  Russian_1.tgt.sd[i] <- sqrt(soln$value)
  Russian_1.wgt[i,] <- soln$solution}
colnames(Russian_1.wgt) <- c("GMKN", "AVAZ", "CHMF", "RSTI", "LKOH", "MGNT", "PLZL", "SBER", "PHST")
Russian_1.portfolio <- cbind(Russian_1.tgt.ret, Russian_1.tgt.sd, Russian_1.wgt)
colnames(Russian_1.portfolio)[1:2] <- c("Return", "Risk")
Russian_1.portfolio <- as.data.frame(Russian_1.portfolio)
head(Russian_1.portfolio)
##        Return       Risk      GMKN        AVAZ      CHMF       RSTI
## 1 -0.03901559 0.05104758 0.1932293 -0.09802339 0.3184636 0.03325511
## 2 -0.03764280 0.05004378 0.1873583 -0.09592188 0.3152638 0.03096061
## 3 -0.03627001 0.04904797 0.1814872 -0.09382036 0.3120641 0.02866611
## 4 -0.03489722 0.04806063 0.1756162 -0.09171884 0.3088643 0.02637161
## 5 -0.03352443 0.04708232 0.1697452 -0.08961732 0.3056646 0.02407711
## 6 -0.03215164 0.04611359 0.1638742 -0.08751581 0.3024648 0.02178261
##        LKOH       MGNT        PLZL      SBER      PHST
## 1 0.7576121 -0.8220858 -0.10796163 0.2860456 0.4394652
## 2 0.7617309 -0.7943609 -0.10560200 0.2677334 0.4328377
## 3 0.7658496 -0.7666359 -0.10324237 0.2494212 0.4262103
## 4 0.7699684 -0.7389109 -0.10088274 0.2311090 0.4195829
## 5 0.7740872 -0.7111859 -0.09852311 0.2127968 0.4129555
## 6 0.7782059 -0.6834609 -0.09616348 0.1944846 0.4063281
Let's check that everything done right. For this purpose we check sum of weights for each column in our matrix of weights.
apply(Russian_1.wgt, 1, sum)
##   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [36] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [71] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Since everything is okay, let's fix a range of standard deviation (risk) of our portfolio.
Russian_1.sd.range <- range(Russian_1.portfolio$Risk)
Russian_1.sd.range
## [1] 0.02674009 0.07832675
We do the same procedure for our Russian securities in period from 01 Jan 2014 to 31 Dec 2015. As we remember this is the period when Russian economy suffered different kinds of shocks such as imposed sanctions from US and Europe governments. Since the code for this procedure is exactly the same we will hide it.
Now we combine all our data of returns into one table. We fix a range of standard deviation for this portfolio.
Russian_2.sd.range <- range(Russian_2.portfolio$Risk)
Russian_2.sd.range
## [1] 0.04589199 0.20499264
Let's recall a range for the first portfolio (before shock).
Russian_1.sd.range
## [1] 0.02674009 0.07832675
We observe huge difference. While for the first portfolio the range equals to 0.05 for the second one it is 0.16. In other words, range for the standard deviation of the portfolio "After shock" exceeds the same range for "Before shock" portfolio 3 times (3.084143 to be precise). Let's plot our "Risk-Return" curves for both portfolios to illustrate our results.
plot(x = Russian_1.portfolio$Risk, y = Russian_1.portfolio$Return, type = "l", lwd = 2, xlim = c(0.025, 0.205), ylim = c(-0.04, 0.155), col = "blue", xlab = "Portfolio risk", ylab = "Portfolio return", main = "Comparing two portfolios", cex.axis = 1.2, cex.lab = 1.5, cex.main = 1.5)
lines(x = Russian_2.portfolio$Risk, y = Russian_2.portfolio$Return, lwd = 2, lty = 2, col = "red") 
legend('bottomright', c("'Before shock' portfolio", "'After shock' portfolio"), lty = c(1, 2), lwd = c(2, 2), cex = 1.2, col = c("blue", "red"))

Picture 1. Portfolio’s “Risk – Return” curves comparison.
We see that after shock risk-return curve lies righter than before the shock one. For every chosen return “before shock” portfolio brings lower risk (standard deviation) than “after shock” one. In other words, in “after shock” period Russian market became more riskier. Furthermore, from the graph we see that in “after shock” period we can achieve returns that were couldn’t reach in the “before shock” period. 
Conclusion
In this article we investigated how political and economical shocks influenced Russian financial market. We used MPT approach to construct “Risk – Return” curves for “before shock” and “after shock” periods. Then we compared both curves and determined following results of our research:
1)	Russian “after shock” financial market brings higher risk for an investor for every set of returns than the “before shock” one;
2)	Risk (standard deviation) range of the “after shock” market exceeds risk range of the “before shock” market 3 times;
3)	Due to growth in risk on “after shock” market investors now may achieve returns that they couldn’t achieve on the “before shock” one.
Please note that the research conducted in this article is based on particular set of securities that – in our opinion – may represent Russian financial market. Results may vary due to different sets of assets used in an analysis. 
References:
1.	Clifford S. Ang. Analyzing financial data and implementing financial models using R;
2.	D. Goldfarb and A. Idnani (1982). Dual and Primal-Dual Methods for Solving Strictly Convex Quadratic Programs. In J. P. Hennart (ed.), Numerical Analysis, Springer-Verlag, Berlin, pages 226–239;
3.	D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving strictly convex quadratic programs. Mathematical Programming, 27, 1–33; 
4.	Markowitz H.M. Portfolio Selection. Journal of Finance, 1952, vol. 7, no 1, pp. 77-91.

УДК 336.761.6 
Оценка влияния шоков на российский фондовый рынок с помощью R
Иванов Никита Олегович, бакалавр
Давнис Валерий Владимирович, д.э.н., профессор
Воронежский государственный университет, Университетская пл., 1, Воронеж, Россия, 394006, email: ivan.nikita2010@yandex.ru
Цель: исследовать как политические (локальный конфликт) и экономические (санкции со стороны США и ЕС) шоки влияют на кривую «Риск – Доходность» локального фондового рынка. Обсуждение: мы используем Современную портфельную теорию для построения кривой риск – доходность «до шока» и «после шока». В качестве периода «до шока» мы используем период между 31 декабря 2011 года по 31 декабря 2013 года. Период «после шока» определим как промежуток времени между 31 декабря 2013 года и 31 декабря 2015 года. Мы сравним две полученные кривые и проинтерпретируем полученные результаты. Результаты: видим, что кривая Риск – Доходность «после шока» лежит правее аналогичной кривой «до шока». Наблюдается рост риска для инвестора за последние 2 года. Кроме того, видим, что в период «после шока» инвестор может получить доходность, которая была ему недоступна в период «до шока».
Ключевые слова: современная портфельная теория, риск, доходность, шок.
Список источников:
1.	Clifford S. Ang. Analyzing financial data and implementing financial models using R;
2.	D. Goldfarb and A. Idnani (1982). Dual and Primal-Dual Methods for Solving Strictly Convex Quadratic Programs. In J. P. Hennart (ed.), Numerical Analysis, Springer-Verlag, Berlin, pages 226–239;
3.	D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving strictly convex quadratic programs. Mathematical Programming, 27, 1–33; 
4.	Markowitz H.M. Portfolio Selection. Journal of Finance, 1952, vol. 7, no 1, pp. 77-91.