Skip to content

haxamanesh/Bank-Data-Time-Series-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Time Series Analysis of Bank Data

This repository contains an R script for performing time series analysis on bank loan data. The analysis includes model estimation, stationarity testing, parameter estimation, residual analysis, and forecasting.

Table of Contents

Installation

To run this script, you need to have R installed on your system. Additionally, you need to install the following R packages:

  • tseries
  • forecast

You can install these packages using the following commands in R:

install.packages("tseries")
install.packages("forecast")

Usage

  1. Clone the repository or download the script.

  2. Ensure you have installed the required packages:

    install.packages("tseries")
    install.packages("forecast")
  3. Download the dataset and place it in the specified location:

    Make sure the bank_case.txt file is located at C:\\Users\\hakhamanesh\\Downloads\\.

  4. Run the script:

    source('path_to_your_script.R')

Script Overview

Step 1: Install Packages and Import Dataset

The script installs the necessary packages and imports the dataset as a time series object.

install.packages("tseries")
install.packages("forecast")

library(tseries)
library(forecast)

bank_case <- as.ts(scan("C:\\Users\\hakhamanesh\\Downloads\\bank_case.txt"))
print(bank_case)

Step 2: Model Estimation

The script plots the time series data, autocorrelation function (ACF), and partial autocorrelation function (PACF).

par(mfrow=c(1,3))
plot(bank_case, main = "Time Series of Loans")
acf(bank_case, main = "ACF of Loans", lag.max = 10, ylim = c(-1,1))
pacf(bank_case, main = "PACF of Loans", lag.max = 10, ylim = c(-1,1))

Step 3: Test for Stationarity

The script tests the time series for stationarity using the Augmented Dickey-Fuller (ADF) test and performs differencing if necessary.

adf.test(bank_case)
bank_case_d1 <- diff(bank_case)
adf.test(bank_case_d1)
bank_case_d2 <- diff(bank_case_d1)
adf.test(bank_case_d2)
par(mfrow=c(1,3))
plot(bank_case_d2, main = "SOD Time Series of Loans")
acf(bank_case_d2, main = "ACF of SOD Loans", lag.max = 10, ylim = c(-1,1))
pacf(bank_case_d2, main = "PACF of SOD Loans", lag.max = 10, ylim=c(-1,1))

Step 4: Parameter Estimation

The script estimates the parameters of the ARIMA model.

bank_fit <- arima(x=bank_case, order = c(0,2,1))
bank_fit

Step 5: Fitted Values

The script calculates and prints the fitted values of the ARIMA model.

fitted(bank_fit)

Step 6: Residual Analysis

The script performs residual analysis to check the adequacy of the model.

par(mfrow = c(1,3))
plot(bank_fit$residuals, ylab = "Residuals")
acf(bank_fit$residuals, ylim = c(-1,1))
pacf(bank_fit$residuals, ylim = c(-1,1))

checkresiduals(bank_fit)

Step 7: Forecasting

The script forecasts future values using the ARIMA model and plots the forecast.

bank_pred <- forecast(bank_fit, h=24)
bank_pred
par(mfrow = c(1,1))
plot(bank_pred)

Notes

  • Ensure that the dataset path in the script matches the location of your dataset.
  • The script assumes the dataset is a univariate time series stored in a text file.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages