Foram obtidos dos preços diários da ação VALE3.SA, que podem ser visualizados no gráfico abaixo.
\[ r_t = 100 \cdot (\log{p_{t}} - \log p_{t-1}), \] na qual:
$ r_t$ é o retorno percentual no instante \(t\); $ p_t$ é o preço do ativo no instante \(t\);
Também forma obtidos os retornos diários da ação VALE3.SA, que podem ser visualizados no gráfico abaixo.
A tabela abaixo apresenta estatísticas descritivas do retorno logaritimo da série de interesse.
\[ x_i, i = 1, \ldots, n \] \[ \bar x = \frac{1}{n} \sum_{i=1}^n x_i, i = 1, \ldots, n \]
\[ \hat \sigma^2 = \frac{1}{n} \sum_{i=1}^n (x_i - \bar x_i)^2, i = 1, \ldots, n \] \[ \hat \mu_3 = \frac{1}{n} \sum_{i=1}^n (x_i - \bar x)^3, i = 1, \ldots, n \] \[ c_3 = \frac{\hat \mu_3}{\hat \sigma^3}\] ### Curtose
\[ \hat \mu_4 = \frac{1}{n} \sum_{i=1}^n (x_i - \bar x)^4, i = 1, \ldots, n \]
\[ \hat c_4 = \frac{\hat \mu_4}{\sigma^4}\]
\[ \hat {ec}_4 = \frac{\hat \mu_4}{\sigma^4} -3 \]
| Medida | Estimativa |
|---|---|
| Quantil 1% | -8.63 |
| Quantil 5% | -4.68 |
| Quantil 10% | -3.38 |
| Primeiro Quartil | -1.53 |
| Média | 0.07 |
| Mediana | 0.05 |
| Terceiro Quartil | 1.67 |
| Quantil 90% | 3.52 |
| Quantil 95% | 4.92 |
| Quantil 99% | 8.73 |
| Desvio-padrão | 3.23 |
| Variância | 10.46 |
| Coeficiente de Assimetria | -0.47 |
| Curtose | 7.99 |
Várias estatísticas descritivas podem ser obtidas com um único comando: basicStats(rlogATIVO).
## VALE3.SA.Close
## nobs 1239.000
## NAs 0.000
## Minimum -28.182
## Maximum 19.357
## 1. Quartile -1.529
## 3. Quartile 1.674
## Mean 0.073
## Median 0.053
## Sum 90.642
## SE Mean 0.092
## LCL Mean -0.107
## UCL Mean 0.253
## Variance 10.462
## Stdev 3.234
## Skewness -0.475
## Kurtosis 7.993
\[\mu \thicksim N(\mu, \sigma^2), \mu \in R, \sigma \in \Bbb R$^{+} \]
Que é gerado com a seguinte distribuição de frequencias absolutas:
## [,1] [,2] [,3]
## [1,] -30 -27.5 1
## [2,] -25 -22.5 0
## [3,] -20 -17.5 2
## [4,] -15 -12.5 5
## [5,] -10 -7.5 44
## [6,] -5 -2.5 558
## [7,] 0 2.5 569
## [8,] 5 7.5 54
## [9,] 10 12.5 4
## [10,] 15 17.5 2
## [11,] 20 -27.5 1
Que é gerado com a seguinte distribuição de frequencias relativas:
## [,1] [,2] [,3]
## [1,] -30 -27.5 0.00016
## [2,] -25 -22.5 0.00000
## [3,] -20 -17.5 0.00032
## [4,] -15 -12.5 0.00081
## [5,] -10 -7.5 0.00710
## [6,] -5 -2.5 0.09007
## [7,] 0 2.5 0.09185
## [8,] 5 7.5 0.00872
## [9,] 10 12.5 0.00065
## [10,] 15 17.5 0.00032
## [11,] 20 -27.5 0.00016
Referência Boxplot com plotly..
fig
fig
É possível fazer o gráfico da função de distribuição acumulada:
fig
## Warning: 'box' objects don't have these attributes: 'cumulative'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'y', 'x', 'x0', 'y0', 'dx', 'dy', 'name', 'q1', 'median', 'q3', 'lowerfence', 'upperfence', 'notched', 'notchwidth', 'notchspan', 'boxpoints', 'jitter', 'pointpos', 'boxmean', 'mean', 'sd', 'orientation', 'quartilemethod', 'width', 'marker', 'line', 'fillcolor', 'whiskerwidth', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'text', 'hovertext', 'hovertemplate', 'hoveron', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'ysrc', 'xsrc', 'q1src', 'mediansrc', 'q3src', 'lowerfencesrc', 'upperfencesrc', 'notchspansrc', 'meansrc', 'sdsrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Encontre aqui como obter mais informações sobre como fazer histogramas com o Plotly.
O R apresenta em sua base quatro funções para lidar com distribuições de variáveis aleatóriias:
Para a distribuição Bernoulli as funções estão abaixo:
rbinom(x, prob, log = FALSE)qbinom(q, prob, lower.tail = TRUE, log.p = FALSE)pbinom(p, prob, lower.tail = TRUE, log.p = FALSE)nbinom(n, prob)Informações sobre a Bernoulli estão disponíveis na apresentada na documentação do R.
## Warning: 'histogram' objects don't have these attributes: 'binsx'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'y', 'text', 'hovertext', 'orientation', 'histfunc', 'histnorm', 'cumulative', 'nbinsx', 'xbins', 'nbinsy', 'ybins', 'autobinx', 'autobiny', 'bingroup', 'hovertemplate', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Para a distribuição binomial as funções são:
dbinom(x, size, prob, log = FALSE)pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)rbinom(n, size, prob)Informações sobre a binomial estão disponíveis na apresentada na documentação do R.
## Warning: 'histogram' objects don't have these attributes: 'binsx'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'y', 'text', 'hovertext', 'orientation', 'histfunc', 'histnorm', 'cumulative', 'nbinsx', 'xbins', 'nbinsy', 'ybins', 'autobinx', 'autobiny', 'bingroup', 'hovertemplate', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Para a distribuição binomial as funções são:
dnbinom(x, size, prob, mu, log = FALSE)pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE)qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE)rnbinom(n, size, prob, mu)É importante ter certeza de qual parametrização da distribuição estamos tratando. A geométrica é apresentada na documentação do R.
Para a distribuição binomial as funções são:
dnbinom(x, size, prob, mu, log = FALSE)pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE)qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE)rnbinom(n, size, prob, mu)Assim como no caso da geométrica, é importante ter certeza de qual parametrização da distribuição estamos tratando. A binomial negativa é apresentada na documentação do R.
Para a distribuição uniforme as funções são:
dunif(x, min = 0, max = 1, log = FALSE)punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)qunif(p, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)runif(n, min = 0, max = 1)Assim como no caso da geométrica, é importante ter certeza de qual parametrização da distribuição estamos tratando. A uniforme é apresentada na documentação do R.
Para a distribuição uniforme as funções são:
dnorm(x, mean = 0, sd = 1, log = FALSE)pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)rnorm(n, mean = 0, sd = 1)Assim como no caso da geométrica, é importante ter certeza de qual parametrização da distribuição estamos tratando. A normal é apresentada na documentação do R.
Para a distribuição uniforme as funções são:
dt(x, df, ncp, log = FALSE)pt(q, df, ncp, lower.tail = TRUE, log.p = FALSE)qt(p, df, ncp, lower.tail = TRUE, log.p = FALSE)rt(n, df, ncp)Assim como no caso da geométrica, é importante ter certeza de qual parametrização da distribuição estamos tratando. A dt é apresentada na documentação do R.
if(!require(fitdistrplus)) {install.packages("fitdistrplus")}
## Loading required package: fitdistrplus
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:plotly':
##
## select
## Loading required package: survival
require(fitdistrplus)
## Warning: 'histogram' objects don't have these attributes: 'binsx'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'y', 'text', 'hovertext', 'orientation', 'histfunc', 'histnorm', 'cumulative', 'nbinsx', 'xbins', 'nbinsy', 'ybins', 'autobinx', 'autobiny', 'bingroup', 'hovertemplate', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
plotdist(dados, histo = TRUE, demp = TRUE)
fn <- fitdist(as.vector(rlogATIVO), "norm")
ft<- fitdist(as.vector(rlogATIVO), "t", start=list(df=10))
par(mfrow = c(2, 2))
plot.legend <- c("Normal", "t-student")
denscomp(list(fn, ft), legendtext = plot.legend)
qqcomp(list(fn, ft), legendtext = plot.legend)
cdfcomp(list(fn, ft), legendtext = plot.legend)
ppcomp(list(fn, ft), legendtext = plot.legend)