-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharima_simulation.Rmd
91 lines (76 loc) · 1.97 KB
/
arima_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
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(
numericInput(inputId = "AR",label = "Degree of Auto Regression",min = 0,max = 10,step = 1,value=0),
numericInput(inputId = "MA",label = "Degree of Moving Average",min = 0,max = 10,step = 1,value=0),
numericInput(inputId = "Difference",label = "Number of Differences",min = 0,max = 3,step = 1,value=0),
sliderInput("phi","Correlation: ",min=0, max=.9999,value=0.5)
)
```
```{r,eval=FALSE,include=FALSE}
AR <- 3
s <- seq(from=0, to=AR,by=1)
choices <- paste0("AR",s)
labels(choices) <- paste0("Auto Regressive")
choices
```
```{r,include=FALSE}
x <- list("AR 1" = "AR1")
x
```
```{r,include=FALSE}
eventReactive(input$AR,{
seq(from=0, to=input$AR,by=1)
})
```
```{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(ar=c(input$phi)),n=l)
d <- data.frame(date=date,y=y)
x <- xts(d[,-1],order.by = d[,1])
})
```
```{r,echo=FALSE}
renderPlot({
plot(x())
})
```
```{r,echo=FALSE}
renderPlot({
pacf(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(ar=c(0.5)),n=l)
d <- data.frame(date=date,y=y)
x <- xts(d[,-1],order.by = d[,1])
```
```{r,echo=FALSE,include=FALSE,eval=FALSE}
plot(x)
```
```{r,echo=FALSE,include=FALSE,eval=FALSE}
pacf(x)
```