-
Notifications
You must be signed in to change notification settings - Fork 0
/
ma_1_simulation.Rmd
68 lines (59 loc) · 1.47 KB
/
ma_1_simulation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "Simulate Time Series"
runtime: shiny
output: html_document
---
This is an interactive document. It interactively simmulates a Moving average order 1 model.
The same code that could simulate the series non interactively is also included.
Make sure you have the following packages installed on your system.
```{r,echo=FALSE,message=FALSE}
# load packages ####
# if you do not have these packages - install.packages('package name')
library(tidyquant)
library(quantmod)
library(dplyr)
library(tidyverse)
library(ggplot2)
library(lubridate)
library(xts)
library(shiny)
```
```{r,echo=FALSE}
inputPanel(
sliderInput("phi","Correlation: ",min=0, max=0.99999,value=0.5,step = 0.01)
)
```
```{r,echo=FALSE}
x <- reactive({
date <- seq.Date(as.Date("2001/01/01"),as.Date("2013/01/01"),"days")
l <- length(date)
y <-arima.sim(model=list(ma=c(input$phi)),n=l)
d <- data.frame(date=date,y=y)
x <- xts(d[,-1],order.by = d[,1])
})
```
```{r,echo=FALSE,message=FALSE}
renderPlot({
plot(x())
})
```
```{r,echo=FALSE}
renderPlot({
acf(x())
})
```
```{r,echo=FALSE,include=FALSE,eval=FALSE}
date <- seq.Date(as.Date("2001/01/01"),as.Date("2013/01/01"),"days")
l <- length(date)
y <-arima.sim(model=list(ma=c(0.9)),n=l)
x <- data.frame(date=date,y=y)
x <- xts(x[,-1],order.by = x[,1])
```
```{r,echo=FALSE,message=FALSE,include=FALSE,eval=FALSE}
plot(x)
```
```{r,echo=FALSE,include=FALSE,eval=FALSE}
print(acf(x))
print(pacf(x) )
print(arima(x,order=c(0,0,1)))
```