Forecasting with ARIMA: R Code

Step-1: ###R Packages Installed

library(fpp2)

library(readxl)

library(SPlit)

library(fpp2)

 

###Declare time-series data

###In this study I have file naming as HPI_AUS. All the date excel format.

HPI_AUS <-ts(AUSHPI[,2], start=c(2002,3), frequency=4)

 

Step-3: ###While forecasting, first that should be done within the sample, and if it is found valid, then only we forrecast out of sample.

###Split the given data into the training and test sets

split_HPI_AUS <- ts_split(ts.obj = HPI_AUS, sample.out= 8)

training <- split_AUSHPI$train

testing <- split_AUSHPI$test

length(training)

length(testing)


 Step-4:###Select the appropriate forecasting tool. Here I have used ARIMA (easy and quick model)

###ARIMA In-sample testing

arima_diag(training)

 

 

###Model forecasting In-sample

arima1 <- auto.arima(training, seasonal= TRUE)

autoplot(arima1)

check_res(arima1)

 

###Forecasting In-sample

fcast1<- forecast(arima1, h=8)

test_forecast(actual=HPI_AUS, forecast.obj = fcast1, test = testing)

accuracy(fcast1, testing)

 

###Auto ARIMA model Out of Sample

arima_diag(HPI_AUS)

fit_arima <- auto.arima(HPI_AUS, seasonal = TRUE )

autoplot(fit_arima)

check_res(fit_arima)

 

###Forecasting Out of Sample

fcast1 <- forecast(HPI_AUS, model = fit_arima, h=8)

plot_forecast(fcast1)

summary(fcast1)

 

###Do we have any option to validate the Forecasting Result?

Box.test(resid(fcast1), lag=1, type = "Ljung-Box")

Box.test(resid(fcast1), lag=5, type = "Ljung-Box")

Box.test(resid(fcast1), lag=10, type = "Ljung-Box")

Box.test(resid(fcast1), lag=15, type = "Ljung-Box")

Box.test(resid(fcast1), lag=20, type = "Ljung-Box")

Thank you

Inflation is a Hidden form of Tax in Nepal: A Granger Causality Test

Abstract 

Inflation is taken as a secret form of taxing people, thus in literature it is also known as an indirect form of tax. This has been tested by using the secondary data since 1975 to 2010 on government tax revenue (GTAX) and national consumer price index (NCPI) of Nepal. Initially, ADF test, then Granger Causality and finally OLS has been conducted. Granger Causality has suggested that NCPI causes GTAX which helped later to consider NCPI as an independent variable and GTAX as a dependent variable. After conducting OLS test it is found that NCPI impacts GTAX directly (Acharya, 2014). 

Key Words: Inflation, Tax, Granger Causality and OLS. 

Reference:

Acharya, S. (2014). Inflation is a hidden form of tax in Nepal: Granger Causality test. Khwopa Journal, 1(1), 61–75.

Four Growth Theories

Keynesian Economics

Golden Section Search Method: Fortran f90

Consider the nonlinear equation f(x)=4x2 –exp(x). Write a Fortran program that uses the Golden Section Search Method to find the solution accurate to within 10-6 for the nonlinear equation on [4,8]. 

Sauce Code:

Program  Assignmentq2

implicit none

real:: f

real::x, r, q1, q2,a, b, tol=1.0e-6

!Define Interval and Function

f(x) = 4*x**2-exp(x)

a=4

b=8

print*, "a", a, "b", b

!Evaluation of the function at the end point

r=(sqrt(5.0)-1)/2

q1=b-r*(b-a)

q2=a+r*(b-a)

 print*, "q1",q1, "q2", q2

 ! Creating Loop

!if ((b-a)<=tol) stop

do while ((b-a)>tol)

     !if(f(a)*f(b)<=0) then

     if(f(a)*f(q2)<=0) then

         b=q2

         q2=q1

         q1=b-r*(b-a)

     else

         a=q1

         q1=q2

         q2=a+r*(b-a)

    print*, "q1",q1, "q2", q2, "a", a, "b", b

     end if 

     end do

end program assignmentq2 

Gaussian Elimination Method: Fortran f90

 Question:

Solve the following system of linear equations using Gaussian Elimination using Fortran.

x1 + x2 - x3 + x4 - x5 = 2

2x1+ 2 x2 + x3 - x4 + x5 = 4

3x1 + x2-3 x3 -2x4+ 3 x5 = 8

4x1 + x2 - x3 +4 x4 -5x5 =16

16x1 -x2 + x3 - x4 - x5 =32

 

Solution:

program main

implicit none

integer, parameter :: n=5

double precision:: a(n,n), b(n), x(n)

integer:: i,j

! matrix A

  data (a(1,i), i=1,5) /  1.0,  1.0,  -1.0, 1.0, -1.0 /

  data (a(2,i), i=1,5) /  2.0,  2.0,  1.0, -1.0, 1.0 /

  data (a(3,i), i=1,5) /  3.0,  1.0,  -3.0, -2.0, 3.0 /

  data (a(4,i), i=1,5) /  4.0,  1.0,  -1.0, 4.0, -5.0 /

  data (a(5,i), i=1,5) /  16.0, -1.0, 1.0, -1.0, -1.0 /

! matrix b

  data (b(i),   i=1,5) /  2.0, 4.0, 8.0, 16.0, 32.0 /


! print a header and the original equations

  write (*,200)

  do i=1,n

     write (*,201) (a(i,j),j=1,n), b(i)

  end do


  call gauss_2(a,b,x,n)


! print matrix A and vector b after the elimination 

  write (*,202)

  do i = 1,n

     write (*,201)  (a(i,j),j=1,n), b(i)

  end do

! print solutions

  write (*,203)

  write (*,201) (x(i),i=1,n)

200 format (' Gauss elimination with scaling and pivoting ' &

    ,/,/,' Matrix A and vector b')

201 format (6f12.6)

202 format (/,' Matrix A and vector b after elimination')

203 format (/,' Solutions x(n)')

end

subroutine gauss_2(a,b,x,n)

implicit none 

integer:: n

double precision:: a(n,n), b(n), x(n)

double precision:: s(n)

double precision:: c, pivot, store

integer:: i, j, k, l


! step 1: begin forward elimination

do k=1, n-1


! step 2: "scaling"

! s(i) will have the largest element from row i 

  do i=k,n                       

    s(i) = 0.0

    do j=k,n                    

      s(i) = max(s(i),abs(a(i,j)))

    end do

  end do


! "pivoting 1" 

! row with the largest pivoting element

  pivot = abs(a(k,k)/s(k))

  l = k

  do j=k+1,n

    if(abs(a(j,k)/s(j)) > pivot) then

      pivot = abs(a(j,k)/s(j))

      l = j

    end if

  end do


! Check if the system has a sigular matrix

  if(pivot == 0.0) then

    write(*,*) ' The matrix is sigular '

    return

  end if


! "pivoting 2" interchange rows k and l (if needed)

if (l /= k) then

  do j=k,n

     store = a(k,j)

     a(k,j) = a(l,j)

     a(l,j) = store

  end do

  store = b(k)

  b(k) = b(l)

  b(l) = store

end if


! elimination (after scaling and pivoting)

   do i=k+1,n

      c=a(i,k)/a(k,k)

      a(i,k) = 0.0

      b(i)=b(i)- c*b(k)

      do j=k+1,n

         a(i,j) = a(i,j)-c*a(k,j)

      end do

   end do

end do


! backward substitution 

x(n) = b(n)/a(n,n)

do i=n-1,1,-1

   c=0.0

   do j=i+1,n

     c= c + a(i,j)*x(j)

   end do 

   x(i) = (b(i)- c)/a(i,i)

end do

end subroutine gauss_2

A "Lost Decade" in Nepalese Economy


I was looking for the dynamics of fiscal and monetary policy in the Nepalese economy.  Both have a specific economic and political explanation, though monetary policy stands more economic connotation than the fiscal one. Although the central bank has a specialized department and relatively competent human resources, even their document seems are unable to get the real picture of the economy.

Since 2004/05 to 20015/16 inflation remains higher than the GDP growth in Nepal. It happened not just like it to be.  In reality, it was committed because of the political, structural, and market-based phenomenon that are not even looked for a reason.

I have gone through another aspect to analyze the Nepalese economy whether it is 'paradigm shift '. Reviewing the documents and consulting with then officer bearer, I am almost convinced with the situation of 'paradigm lost' rather in Nepalese economy. Simply this conclusion is driven due to the failure of understanding the fundamentals of how the economy works.

Thus, the period 2004 to 2016, should be named as a 'lost decade' in Economic history of Nepal. It became so due to the worst ever understanding about the role of every economic actor.

Table-1: Relationship Between Real GDP Growth and CPI in Nepal


Note: This issue is elaborated further in an article and the link of the article is in comment box.