---
title: "PESTLE analysis - Economic"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
theme: united
navbar:
- { icon: "fa-facebook", href: "https://www.facebook.com/b.byambadorj0212/",align: right, target: blank}
- { icon: "fa-github", href: "https://github.com/Byambaa212/R_Graphic_Gallery",align: right, target: blank}
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(highcharter)
library(forecast)
library(stargazer)
library(dplyr)
```
# Валютын ханш
Column {.tabset}
-----------------------------------------------------------------------
###
```{r}
data1 <- read_xlsx("data.xlsx", sheet=1)
attach(data1)
r3_trend <- lm(value~time(value)+I(time(value)^2)+I(time(value)^3), data=data1)
r_best <- cbind(trend=time(value),quad=I(time(value)^2),
cubic=I(time(value)^3))
r_best_arma <- Arima(value, order = c(1,0,3),xreg = r_best,include.constant = TRUE)
date <- seq(from = as.Date("1994-01-01"), to = as.Date("2026-08-01"), by = 'month')
r_best_arma_ts <- ts(r_best_arma$fitted , frequency = 12, start = c(1994,1,1))
fc <- forecast(r_best_arma_ts, level = 95, h=60)
hchart(fc) %>%
hc_exporting(enabled = TRUE) %>%
hc_yAxis( title = list(text = ""),
labels = list( format = "{value:,.0f}")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = F),
enableMouseTracking = T )
)%>%
hc_title(text="Валютын ханшийн 5 жилийн прогноз (сараар)",align="center",
style = list(fontWeight = "bold", fontSize = "20px")) %>%
hc_legend(layout = 'horizontal', align = 'center', verticalAlign = 'bottom',
style = list(fontSize = "100px")) %>%
hc_tooltip(table = TRUE,
sort = TRUE,
pointFormat = paste0( '
\u25CF',
"{point.y:.2f}"),
headerFormat = ' {point.x: %Y-%m-%d}'
) %>%
hc_add_theme(hc_theme_monokai())
```
###
```{r}
options(scipen=999)
plot(time(data1$date), data1$value, type="l", col="red",ylab="",xlab="",lwd=2, ylim=c(-200, 3000),
main="Quadratic trend & ARMA(1,3)")
par(new=TRUE)
plot(r_best_arma$fitted, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1 ,
col="green", axes=F, ylim=c(-200, 3000))
par(new=TRUE)
plot(r_best_arma$residuals, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1,
col="blue", axes=F, ylim=c(-200, 3000))
legend("topleft",c("Actual", "Fitted","Residual"),lty=c(1,1,1),
col=c("red","green","blue"),cex=0.88)
```
# БДНБ
## Column 1 {.tabset}
###
```{r}
data2 <- read_xlsx("data.xlsx", sheet=2)
r1_trend <- lm(value~time(value), data=data2)
tsdata2 <- ts(data2$value, frequency = 4,start = c(2005,1),end=c(2020,4))
attach(data2)
r_best <- cbind(trend=time(value))
r_best_arma <- Arima(value, order = c(2,0,0),seasonal=c(0,1,1),
xreg = r_best,include.constant = TRUE)
r_best_arma_ts <- ts(r_best_arma$fitted , frequency = 4,start = c(2005,1),end=c(2020,4))
fc <- forecast(r_best_arma_ts, level = 95, h=20)
hchart(fc) %>%
hc_exporting(enabled = TRUE) %>%
hc_yAxis( title = list(text = ""),
labels = list( format = "{value:,.0f}")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = F),
enableMouseTracking = T )
)%>%
hc_title(text="БДНБ-ний 5 жилийн прогноз(улирлаар)",align="center",
style = list(fontWeight = "bold", fontSize = "20px")) %>%
hc_legend(layout = 'horizontal', align = 'center', verticalAlign = 'bottom',
style = list(fontSize = "100px")) %>%
hc_tooltip(table = TRUE,
sort = TRUE,
pointFormat = paste0( '
\u25CF',
"{point.y:.2f}"),
headerFormat = ' {point.x: %Y-%m-%d}'
) %>%
hc_add_theme(hc_theme_monokai())
```
###
```{r}
options(scipen=999)
plot(time(data2$date), data2$value, type="l", col="red",ylab="",xlab="",lwd=2, ylim=c(-1400000, 5500000),
main="Linear trend & Seasonality & ARMA(2,0)")
par(new=TRUE)
plot(r_best_arma$fitted, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1 ,
col="green", axes=F, ylim=c(-1400000, 5500000))
par(new=TRUE)
plot(r_best_arma$residuals, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1,
col="blue", axes=F, ylim=c(-1400000, 5500000))
legend("topleft",c("Actual", "Fitted","Residual"),lty=c(1,1,1),
col=c("red","green","blue"),cex=0.88)
```
# Ажилгүйдлийн түвшин
## Column 1 {.tabset}
###
```{r}
data3 <- read_xlsx("data.xlsx", sheet=3)
r3_trend <- lm(value~time(value)+I(time(value)^2)+I(time(value)^3), data=data3)
tsdata3 <- ts(data3$value, frequency = 1,start = c(1992),end=c(2020))
r3_trend_ar1 <- lm(value~time(value)+I(time(value)^2)+I(time(value)^3)+lag((value),1), data=data3)
r_best <- cbind(trend=time(value), quadratic=I(time(value)^2) ,cubic=I(time(value)^3))
r_best_arma <- Arima(value, order = c(1,0,0),
xreg = r_best,include.constant = TRUE)
r3_trend_ar1_ts <- ts(r3_trend_ar1$fitted , frequency = 1,start = c(1992),end=c(2020))
fc <- forecast(r3_trend_ar1_ts, level = 95, h=5)
hchart(fc) %>%
hc_exporting(enabled = TRUE) %>%
hc_yAxis( title = list(text = ""),
labels = list( format = "{value:,.0f}")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = F),
enableMouseTracking = T )
)%>%
hc_title(text="Ажилгүйдлийн түвшингийн 5 жилийн прогноз (жилээр)",align="center",
style = list(fontWeight = "bold", fontSize = "20px")) %>%
hc_legend(layout = 'horizontal', align = 'center', verticalAlign = 'bottom',
style = list(fontSize = "100px")) %>%
hc_tooltip(table = TRUE,
sort = TRUE,
pointFormat = paste0( '
\u25CF',
"{point.y:.2f}"),
headerFormat = ' {point.x: %Y-%m-%d}'
) %>%
hc_add_theme(hc_theme_monokai())
```
###
```{r}
plot(time(data3$date), data3$value, type="l", col="red",ylab="",xlab="",lwd=2,ylim=c(-3,12),
main="Cubic trend & Seasonality & ARMA(1,0)")
par(new=TRUE)
plot(r3_trend_ar1$fitted.values, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1 ,
col="green", axes=F,ylim=c(-3,12))
par(new=TRUE)
plot(r3_trend_ar1$residuals, lwd=2,type="l",ylab="", xlab="" , yaxt="n", xaxt="n",lty=1,
col="blue", axes=F,ylim=c(-3,12))
legend("topleft",c("Actual", "Fitted","Residual"),lty=c(1,1,1),
col=c("red","green","blue"),cex=0.88)
```
# Инфляци
## Column 1 {.active .tabset-fade .tabset-pills}
###
```{r}
data4 <- read_xlsx("data.xlsx", sheet=4)
tsdata4 <- ts(data4$value, frequency = 1,start = c(1998),end=c(2020))
fc <- forecast(tsdata4, level = 95, h=5)
hchart(fc) %>%
hc_exporting(enabled = TRUE) %>%
hc_yAxis( title = list(text = ""),
labels = list( format = "{value:,.0f}")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = F),
enableMouseTracking = T )
)%>%
hc_title(text="Инфляцийн 5 жилийн прогноз (жилээр)",align="center",
style = list(fontWeight = "bold", fontSize = "20px")) %>%
hc_legend(layout = 'horizontal', align = 'center', verticalAlign = 'bottom',
style = list(fontSize = "100px")) %>%
hc_tooltip(table = TRUE,
sort = TRUE,
pointFormat = paste0( '
\u25CF',
"{point.y:.2f}"),
headerFormat = ' {point.x: %Y-%m-%d}'
) %>%
hc_add_theme(hc_theme_monokai())
```