0% found this document useful (0 votes)
86 views

Soluci On Tarea 4 Riesgo Financiero: Implementaci Onenr

This document appears to be a solutions document for a financial risk homework assignment in Spanish. It includes code written in the R programming language to analyze historical stock price data for five Chilean companies (Banmedica, Embonor, Aguas Andinas, IAM, and Ripley) and calculate value at risk (VaR) using univariate and multivariate approaches over different time horizons. The assignment asks students to calculate one-day and five-day VaR using historical, GARCH, and AR-GARCH models, as well as perform Monte Carlo simulations to estimate one-year VaR. It also tasks them with calculating multivariate one-day VaR using historical and constant variance methods and simulations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Soluci On Tarea 4 Riesgo Financiero: Implementaci Onenr

This document appears to be a solutions document for a financial risk homework assignment in Spanish. It includes code written in the R programming language to analyze historical stock price data for five Chilean companies (Banmedica, Embonor, Aguas Andinas, IAM, and Ripley) and calculate value at risk (VaR) using univariate and multivariate approaches over different time horizons. The assignment asks students to calculate one-day and five-day VaR using historical, GARCH, and AR-GARCH models, as well as perform Monte Carlo simulations to estimate one-year VaR. It also tasks them with calculating multivariate one-day VaR using historical and constant variance methods and simulations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Universidad de Santiago de Chile

Faculta de Administracion y Economa


Riesgo Financiero
Primer Semestre 2016

Soluci
on Tarea 4 Riesgo Financiero
Andres Medina - Juan P. Armijo - Nelson Jaque - Sebastian Araya
Implementaci
on en R:
#!/usr/bin/env Rscript
rm(list=ls())
library(ggplot2)
library(xts)
## Loading required package: zoo
##
## Attaching package: zoo
## The following objects are masked from package:base:
##
##
as.Date, as.Date.numeric
library(dygraphs)
library(zoo)
library(lubridate)
##
## Attaching package: lubridate
## The following object is masked from package:base:
##
##
date
library(grid)
library(gridExtra)
library(knitr)
dir <- '/home/anmedina/MEF/Riesgo_Financiero/Tarea_4'
setwd(dir)
## Lectura
data.read <- function(file){
dat <- read.csv2(file,header=TRUE,sep=";")
df <- dat[,c(1,5)]
df$Close <- round(df$Close,digits = 0)
df$Fecha <- dmy(df$Fecha)
return(df)}
1

##
d1
d2
d3
d4
d5

Data
<- data.read('banmedica.csv')
<- data.read('embonor.csv')
<- data.read('aguasa.csv')
<- data.read('iam.csv')
<- data.read('ripley.csv')

plot1 <- ggplot(d1,aes(Fecha,Close)) + geom_line(aes(color='Banmedica')) +


scale_colour_manual("", breaks = c(""),values = c("blue")) +
ggtitle("Precios de Cierre : Banmedica") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
plot2 <- ggplot(d2,aes(Fecha,Close)) + geom_line(aes(color='Embonor')) +
scale_colour_manual("", breaks = c(""),values = c("red")) +
ggtitle("Precios de Cierre : Embonor") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
plot3 <- ggplot(d3,aes(Fecha,Close)) + geom_line(aes(color='Aguas')) +
scale_colour_manual("", breaks = c("Aguas Andinas"),values = c("darkgreen")) +
ggtitle("Precios de Cierre : Aguas Andinas") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
plot4 <- ggplot(d4,aes(Fecha,Close)) + geom_line(aes(color='iam')) +
scale_colour_manual("", breaks = c(""),values = c("magenta")) +
ggtitle("Precios de Cierre : IAM") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
plot5 <- ggplot(d5,aes(Fecha,Close)) + geom_line(aes(color='Ripley')) +
scale_colour_manual("", breaks = c("Aguas Andinas"),values = c("orange")) +
ggtitle("Precios de Cierre : Ripley") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
grid.arrange(plot1,plot2,plot3,plot4,plot5,ncol=2,nrow=3)

Precios de Cierre : Banmedica

Precios de Cierre : Embonor


1600

1000

Close

Close

1200

800

1200

800
600
400
2006

2008

2010

2012

2014

400
2006

2016

2008

2010

2012

2014

Fecha

Fecha

Precios de Cierre : Aguas Andinas

Precios de Cierre : IAM

2016

400
1000

Close

Close

350
300
250

800

600
200
2006

2008

2010

2012

2014

2016

400
2006

2008

2010

Fecha

2012

2014

2016

Fecha

Precios de Cierre : Ripley

Close

800

600

400

200
2006

2008

2010

2012

2014

2016

Fecha

1. VaR Univariado : Calcule el VaR de una posicion de $ 1.000.000 al 99 % considerando un activo seleccionado:
a) Para un da a partir de los datos historicos (no parametrico)
## Retornos
return
<date
<rt
<-

Banmedica
diff(log(d5$Close))
d5$Fecha[-1]
cbind.data.frame(date,return)

## Plot Retornos Ripley


plot1 <- ggplot(rt,aes(date,return)) + geom_line(aes(color='Banmedica')) +
scale_colour_manual("", breaks = c(""),values = c("blue")) +
ggtitle("Retornos Ripley") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
3

## Histograma Retornos Ripley


plot2 <- ggplot(rt, aes(x = rt$return)) +
geom_histogram(aes(y = ..density..), fill = 'red', alpha = 0.5, binwidth =
xlab('Retornos') +
ylab('Densidad')
grid.arrange(plot1,plot2,ncol=1,nrow=2)
Retornos Ripley
0.3

return

0.2

0.1

0.0

0.1

2006

2008

2010

2012

2014

2016

date
30

Densidad

20

10

0
0.1

0.0

0.1

0.2

0.3

Retornos

b) Para un da, usando un modelo GARCH(1,1)


c) Para un da. usando un modelo AR(1)-GARCH(1,1)
d) Repita su respuesta en a) utilizando un horizonte de 5 das.
e) Realice 300 simulaciones (Monte Carlo) de un a
no de observaciones de precios
de activos para calcular VaR. Grafque.
2. VaR Multivariado : Calcule el VaR de una posicion de $1.000.000 al 99 % considerando un portafolio integrado por 4 activos, con participaciones iguales:
g) Para un da a partir de datos historicos (no parametrico)
h) Para un da , usando una estimacion de varianza constante
4

i) Realice 300 simulaciones de precios para calcular el VaR a un da. Grafque.

You might also like