#FRED is a open source and trust worthy  place to find financial data.We are going to use monthly data for our financial analysis.
Forecasting:
#Forecasting is a technique used to understand the past business patterns and modeling them to future
Quality of the forecast depends on below factors

Setting up the Working Directory

getwd()
## [1] "C:/Users/sasim/Desktop/Fall Semester 2021/Business Forecasting/Day1_Business_Forecasting"
setwd("C:/Users/sasim/Desktop/Fall Semester 2021/Business Forecasting/Day1_Business_Forecasting")

Packages to be used

        library(pacman)
        pacman::p_load(forecast)
        p_load(tidyverse, lubridate, rio, pdfetch, tidyverse, readxl,dygraphs)
        library(dygraphs)
        
                # Secondary packages        
                pacman::p_load(tsibble, fable)
                pacman::p_load(tsibbledata)
                pacman::p_load(feasts, fpp3)
                library(ggthemes)
                library(tsbox) #convert xts to tsibble
                library(TSstudio)
                library(xts)
                library(zoo)
                library(ggthemes)

Import and preview the data

* Currency Conversions: US$ exchange rate: Average of daily rates: National currency:USD for Argentina
#pdfetch_FRED is a function used to get the web data from FRED open source.
#head,tail helps us to preview the data.
#plot function helps us to visualize and develop high level understanding of the dataset

arg = pdfetch::pdfetch_FRED("ARGCCUSMA02STM")

head(arg); tail(arg)
##            ARGCCUSMA02STM
## 1960-01-31              0
## 1960-02-29              0
## 1960-03-31              0
## 1960-04-30              0
## 1960-05-31              0
## 1960-06-30              0
##            ARGCCUSMA02STM
## 2021-03-31        90.9659
## 2021-04-30        92.7640
## 2021-05-31        94.0042
## 2021-06-30        95.1543
## 2021-07-31        96.1348
## 2021-08-31        97.1110
plot(arg)

#Forecasting can be done only when we have atleast one vector (continuous variable) and this vector must be relative to a particular time interval.
str(arg)
## An 'xts' object on 1960-01-31/2021-08-31 containing:
##   Data: num [1:740, 1] 0 0 0 0 0 0 0 0 0 0 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "ARGCCUSMA02STM"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
#STR is a function which tells us whether a vector is a time-series variable or not.

Convert Vector to Time-series variable.

To convert a vector to timeseries, we must specify

arg.ts = ts(arg, start = c(1960,1), end = c(2021,6), frequency = 12)

Data Preparation

while working with time-series, we are always prone to null values. Try and remove the null values before data analysis

arg.ts = na.omit(arg.ts)

Picking the right time-series interval

# window function helps us to shorten the time-series interval and aggregate the data based on the frequency

arg.annual = window(arg.ts, start = c(1980,1), end = c(2021, 6), frequency = 1)
plot(arg.annual)

Forecast:

Just recollect the completed steps so far

# Now its time to go for final step(The amount of data)
# More the forecast period, The more inaccurate the forecast will be.
# Because future events might affect the predicted forecast.
# So its always advisable to go with less forecast period

# less forecast period with 95% confidence interval

autoplot(forecast(auto.arima(arg), h = 6)) + xlim(700,750)

#xlim helps us to zoom and see the patterns clearly in the data 


#pick more forecast period and see  how the forecast behaves
autoplot(forecast(auto.arima(arg), h = 24)) + xlim(700,750)

Conclusion:

Recommendations: