Created
June 8, 2023 21:02
-
-
Save renet123/ff5f72c5d60365fcc0034ba5a564b54c to your computer and use it in GitHub Desktop.
Python script for automated reporting using AI with financial data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LinearRegression | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# Example Balance Sheet and Income Statement Data | |
# Replace with your actual data | |
balance_sheet_data = { | |
'Year': [2020, 2021, 2022], | |
'Assets': [100000, 120000, 140000], | |
'Liabilities': [50000, 60000, 70000], | |
'Equity': [50000, 60000, 70000] | |
} | |
income_statement_data = { | |
'Year': [2020, 2021, 2022], | |
'Revenue': [200000, 220000, 240000], | |
'Expenses': [150000, 160000, 170000], | |
'Net Income': [50000, 60000, 70000] | |
} | |
# Convert to DataFrame | |
balance_sheet = pd.DataFrame(balance_sheet_data) | |
income_statement = pd.DataFrame(income_statement_data) | |
# Merge DataFrames on Year | |
financial_data = pd.merge(balance_sheet, income_statement, on='Year') | |
# Scale data | |
scaler = StandardScaler() | |
financial_data_scaled = scaler.fit_transform(financial_data) | |
# Train model to predict next year's Net Income based on previous financial data | |
model = LinearRegression() | |
model.fit(financial_data_scaled[:, :-1], financial_data_scaled[:, -1]) | |
# Make predictions | |
predictions = model.predict(financial_data_scaled[:, :-1]) | |
# Plot results | |
plt.figure(figsize=(10, 6)) | |
plt.plot(financial_data['Year'], financial_data_scaled[:, -1], label='Actual') | |
plt.plot(financial_data['Year'], predictions, label='Predicted') | |
plt.title('Actual vs Predicted Net Income') | |
plt.legend() | |
plt.show() | |
# Save results to CSV | |
results = pd.DataFrame({'Year': financial_data['Year'], 'Actual': financial_data_scaled[:, -1], 'Predicted': predictions}) | |
results.to_csv('results.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment