0% found this document useful (0 votes)
3 views

Bank Statement Simulator Script

The document outlines a Python script that simulates a bank statement from December 2, 2024, to June 2, 2025, accounting for business days while excluding weekends and Ghanaian holidays. It generates transactions including deposits, withdrawals, monthly interest, and fees, adjusting the final balance to a specified amount. The results are saved as a CSV file named 'Simulated_Bank_Statement_Dec2024_to_Jun2025.csv'.

Uploaded by

JOEL AMANKWAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Bank Statement Simulator Script

The document outlines a Python script that simulates a bank statement from December 2, 2024, to June 2, 2025, accounting for business days while excluding weekends and Ghanaian holidays. It generates transactions including deposits, withdrawals, monthly interest, and fees, adjusting the final balance to a specified amount. The results are saved as a CSV file named 'Simulated_Bank_Statement_Dec2024_to_Jun2025.csv'.

Uploaded by

JOEL AMANKWAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

from datetime import datetime, timedelta

import pandas as pd
import numpy as np
import holidays

# Simulation parameters
start_date = datetime(2024, 12, 2)
end_date = datetime(2025, 6, 2)
gh_holidays = holidays.Ghana(years=[2024, 2025])

# Generate business days excluding weekends and Ghanaian holidays


date_range = pd.date_range(start=start_date, end=end_date, freq='B')
date_range = [d for d in date_range if d not in gh_holidays]

# Initialize empty transaction log


transactions = []

# Set initial balance and running total


balance = 0.0
monthly_transactions = [] # To track monthly transaction volume for interest
calculation

# Function to get month end business day for monthly charge


def get_last_business_day(year, month):
last_day = pd.Timestamp(year, month + 1, 1) - pd.Timedelta(days=1) if month < 12
else pd.Timestamp(year + 1, 1, 1) - pd.Timedelta(days=1)
while last_day.weekday() >= 5 or last_day in gh_holidays:
last_day -= pd.Timedelta(days=1)
return last_day

# Simulate daily transactions


np.random.seed(42)
for date in date_range:
entry = {"Date": date.strftime("%Y-%m-%d")}

# On the 1st business day of each month, add interest


if date.day == 1 or (date - timedelta(days=1)).month != date.month:
interest = round(0.02 * sum(monthly_transactions), 2)
if interest > 0:
balance += interest
entry.update({"Description": "Monthly Interest", "Credit": interest,
"Debit": "", "Balance": round(balance, 2)})
transactions.append(entry)
entry = {"Date": date.strftime("%Y-%m-%d")}
monthly_transactions = [] # Reset for new month

# Add either deposit or withdrawal (not both)


if np.random.rand() > 0.5:
deposit = round(np.random.uniform(1200, 5000), 2)
balance += deposit
monthly_transactions.append(deposit)
entry.update({"Description": "Deposit", "Credit": deposit, "Debit": "",
"Balance": round(balance, 2)})
else:
withdrawal = round(np.random.uniform(600, 3530), 2)
if withdrawal <= balance:
balance -= withdrawal
monthly_transactions.append(withdrawal)
entry.update({"Description": "Withdrawal", "Credit": "", "Debit":
withdrawal, "Balance": round(balance, 2)})
else:
continue # Skip withdrawal if insufficient funds

transactions.append(entry)

# Add monthly fee at month end


last_bday = get_last_business_day(date.year, date.month)
if date == last_bday:
balance -= 15.00
fee_entry = {
"Date": date.strftime("%Y-%m-%d"),
"Description": "Monthly Account Fee",
"Credit": "",
"Debit": 15.00,
"Balance": round(balance, 2)
}
monthly_transactions.append(15.00)
transactions.append(fee_entry)

# Adjust final balance to match 210,450.00 on June 2, 2025


final_balance = 210_450.00
difference = final_balance - balance
if difference > 0:
balance += difference
transactions.append({
"Date": end_date.strftime("%Y-%m-%d"),
"Description": "Final Adjustment Deposit",
"Credit": round(difference, 2),
"Debit": "",
"Balance": round(balance, 2)
})
else:
balance -= abs(difference)
transactions.append({
"Date": end_date.strftime("%Y-%m-%d"),
"Description": "Final Adjustment Withdrawal",
"Credit": "",
"Debit": round(abs(difference), 2),
"Balance": round(balance, 2)
})

# Create DataFrame and save to CSV


df = pd.DataFrame(transactions)
df.to_csv("Simulated_Bank_Statement_Dec2024_to_Jun2025.csv", index=False)
print("Bank statement simulation complete. File saved as
Simulated_Bank_Statement_Dec2024_to_Jun2025.csv")

You might also like