library(quantmod)
## Warning: package 'quantmod' was built under R version 3.5.2
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.5.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.5.2
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.5.2
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(graphics)
library(readxl)
library(moments)
## Warning: package 'moments' was built under R version 3.5.2
library(stats)
library(fTrading)
## Warning: package 'fTrading' was built under R version 3.5.2
## Loading required package: timeDate
##
## Attaching package: 'timeDate'
## The following objects are masked from 'package:moments':
##
## kurtosis, skewness
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.5.2
##
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
##
## time<-
## Loading required package: fBasics
## Warning: package 'fBasics' was built under R version 3.5.2
##
## Attaching package: 'fBasics'
## The following object is masked from 'package:TTR':
##
## volatility
##
## Attaching package: 'fTrading'
## The following object is masked from 'package:TTR':
##
## SMA
library(readxl)
TALLER_CELSIA <- read_excel("C:/Users/windows/Desktop/PREGRADO 2019-1/TEORIA DE RIESGO/TALLER CELSIA.xlsx")
View(TALLER_CELSIA)
head(TALLER_CELSIA)
1 CALCULO DE RENDMIENTOS
R<-(TALLER_CELSIA$Rendimientos)
head(R)
## [1] 0.000000000 -0.006222795 0.003738322 0.001243008 0.008658063
## [6] 0.008583744
summary(R)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.0544513 -0.0042736 0.0000000 0.0001259 0.0048822 0.0454359
En la media Se puede observar en los datos que la media de los rendimientos esta en 0.0001259 un valos positivo apesar de que llego a un valor minimoen perdidas
Media
mean(R)
## [1] 0.00012586
En la varianza podemos apreciar que la variabilidad de los rendimientos con respecto a su media es de 0.0001067
Varianza
var(R)
## [1] 0.0001067852
La desviacion estandar nos indica la dispercion que tienen los rendimientos con respecto a los rendimientos
Desviacion
sd(R)
## [1] 0.01033369
Asimetria
skewness(R)
## [1] -0.5276258
## attr(,"method")
## [1] "moment"
curtosis
kurtosis(R)
## [1] 4.387975
## attr(,"method")
## [1] "excess"
3.TALLOS Y HOJAS
stem(R)
##
## The decimal point is 2 digit(s) to the left of the |
##
## -5 | 43
## -4 |
## -4 | 4
## -3 | 6
## -3 | 10
## -2 | 7555
## -2 | 32111000
## -1 | 998877666665555
## -1 | 4444443333222221111000000000000
## -0 | 999999999998888877777777777766666666666665555555555555
## -0 | 44444444444444443333333333333333333322222222222222222222222222222222+23
## 0 | 00000000000000000000000000000000000000000000000000000000001111111111+77
## 0 | 5555555555556666666666666777777888888888888889999999999
## 1 | 0000000000000111111222222223333333344
## 1 | 555555566677888888999
## 2 | 00011344
## 2 | 556
## 3 | 12
## 3 | 5
## 4 |
## 4 | 5
4.CAJAS
boxplot(R, main = "RENDIMIENTOS CELSIA")
5. HISTOGRAMA,AGREGANDO CURVA NORMAL
hist(R,breaks = 20, prob = TRUE, main = "RENDIMIENTOS CELSIA")
lines(density(R))
6. GRAFICO DE LINEAS
a <- zoo(TALLER_CELSIA$Rendimientos, TALLER_CELSIA$Fecha)
b <- as.xts(a,as.Date(TALLER_CELSIA$Fecha))
D <- as.quantmod.OHLC(b, c("Rendimientos"))
chartSeries(D, type = "line", theme = "white", pch = 16, line.type="l")
qqline(R)
7. GRAFICO DE PROBABILIDAD NORMAL
qqnorm(R)
qqnormPlot(R)
shapiro.test(R)
##
## Shapiro-Wilk normality test
##
## data: R
## W = 0.93639, p-value = 7.16e-14
ren = R^2
var2<- sum(ren)/length(R)
var2
## [1] 0.00010659
VENTANAS MOVILES
library(caTools)
## Warning: package 'caTools' was built under R version 3.5.2
n = 506
k = 25
vem<- runsd(R , k,center = runmean(R,k))
v.venta<-vem[n]^2
plot(vem)
SUAVIZAMIENTO EXPONENCIAL
L<-1:n
lambda<-0.94
lambda2<-lambda^(L-1)
G<-R^2
S<- lambda2*G
t<-sum(S)
sigmat<- (1-lambda)*t
suavexpo<-cbind(L,R,lambda2,G,sigmat)
head(suavexpo)
## L R lambda2 G sigmat
## [1,] 1 0.000000000 1.000000 0.000000e+00 6.816887e-05
## [2,] 2 -0.006222795 0.940000 3.872318e-05 6.816887e-05
## [3,] 3 0.003738322 0.883600 1.397505e-05 6.816887e-05
## [4,] 4 0.001243008 0.830584 1.545069e-06 6.816887e-05
## [5,] 5 0.008658063 0.780749 7.496205e-05 6.816887e-05
## [6,] 6 0.008583744 0.733904 7.368066e-05 6.816887e-05
sigma<-sqrt(sigmat)
sigma
## [1] 0.008256444