[go: up one dir, main page]

0% found this document useful (0 votes)
16 views1 page

Financial Chatbox

The document outlines a financial chatbot that answers predefined queries regarding the financial statements of Microsoft, Tesla, and Apple for the years 2021 to 2023. It details the data loading process from a CSV file, the specific queries the chatbot can respond to, and its limitations, such as a limited query set and reliance on static data. The chatbot provides responses related to total revenue, net income, current assets, debt-to-equity ratio, and net profit margin.

Uploaded by

mawuliprosper544
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)
16 views1 page

Financial Chatbox

The document outlines a financial chatbot that answers predefined queries regarding the financial statements of Microsoft, Tesla, and Apple for the years 2021 to 2023. It details the data loading process from a CSV file, the specific queries the chatbot can respond to, and its limitations, such as a limited query set and reliance on static data. The chatbot provides responses related to total revenue, net income, current assets, debt-to-equity ratio, and net profit margin.

Uploaded by

mawuliprosper544
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/ 1

In [2]: import pandas as pd

import os

# Define the file path


file_path = 'C:/Users/mawul/OneDrive/Documents/financial statements.csv'

# Check if the file exists


if os.path.exists(file_path):
# Load the CSV file into a DataFrame
df = pd.read_csv(file_path)
# Display the first few rows of the DataFrame to verify
display(df.head())
else:
print(f"File not found: {file_path}. Please check the file path and try again.")

COMPANY (ALL AMMOUNT ARE IN MILLIONS) YEAR 3 YEAR 2 YEAR1

0 MICROSOFT 2023.0 2022.0 2021.0

1 TOTAL REVENUE 211915.0 198270.0 168088.0

2 NET INCOME 72361.0 72738.0 61271.0

3 TOTAL ASSET 411976.0 364840.0 333799.0

4 TOTAL LIABILITIES 205753.0 198298.0 191791.0

In [4]: # Define the financial data


data = {
'Microsoft': {
'2023': {'Total Revenue': 211915, 'Net Income': 72361, 'Total Asset': 411976, 'Total Liabilities': 205753, 'Cash Flow from Operating Activities': 87585},
'2022': {'Total Revenue': 198270, 'Net Income': 72738, 'Total Asset': 364840, 'Total Liabilities': 198298, 'Cash Flow from Operating Activities': 89035},
'2021': {'Total Revenue': 168088, 'Net Income': 61271, 'Total Asset': 333799, 'Total Liabilities': 191791, 'Cash Flow from Operating Activities': 76740}
},
'Tesla': {
'2023': {'Total Revenue': 96773, 'Net Income': 14974, 'Total Asset': 106618, 'Total Liabilities': 43009, 'Cash Flow from Operating Activities': 13256},
'2022': {'Total Revenue': 81462, 'Net Income': 12587, 'Total Asset': 82338, 'Total Liabilities': 36440, 'Cash Flow from Operating Activities': 14724},
'2021': {'Total Revenue': 53823, 'Net Income': 5644, 'Total Asset': 62131, 'Total Liabilities': 30548, 'Cash Flow from Operating Activities': 11497}
},
'Apple': {
'2023': {'Total Revenue': 383285, 'Net Income': 96995, 'Total Asset': 352583, 'Total Liabilities': 290437, 'Cash Flow from Operating Activities': 110543},
'2022': {'Total Revenue': 394328, 'Net Income': 99803, 'Total Asset': 352755, 'Total Liabilities': 302083, 'Cash Flow from Operating Activities': 122151},
'2021': {'Total Revenue': 365817, 'Net Income': 94680, 'Total Asset': 351002, 'Total Liabilities': 287912, 'Cash Flow from Operating Activities': 104038}
}
}

# Define the responses


responses = {
"What is the total revenue for Microsoft in 2023?": f"The total revenue for Microsoft in 2023 is {data['Microsoft']['2023']['Total Revenue']} million.",
"How has net income changed for Tesla over the last year?": f"The net income for Tesla in 2023 is {data['Tesla']['2023']['Net Income']} million, compared to {data['Tesla']['2022']['Net Income']} million in 2022.",
"What are the current assets for Apple in 2022?": f"The current assets for Apple in 2022 are {data['Apple']['2022']['Total Asset']} million.",
"What is the debt-to-equity ratio for Microsoft in 2021?": f"The debt-to-equity ratio for Microsoft in 2021 is {data['Microsoft']['2021']['Total Liabilities'] / (data['Microsoft']['2021']['Total Asset'] - data['Microsoft']['2021']['To
"How much is the net profit margin for Tesla in 2023?": f"The net profit margin for Tesla in 2023 is {(data['Tesla']['2023']['Net Income'] / data['Tesla']['2023']['Total Revenue']) * 100:.2f}%."
}

In [10]: # Function to get response based on user query


def get_response(query):
return responses.get(query, "Sorry, I don't understand that question.")

# Function to simulate chatbot interaction in Jupyter Notebook


def chatbot(query):
return get_response(query)

# Example queries to test the chatbot


queries = [
"What is the total revenue for Microsoft in 2023?",
"How has net income changed for Tesla over the last year?",
"What are the current assets for Apple in 2022?",
"What is the debt-to-equity ratio for Microsoft in 2021?",
"How much is the net profit margin for Tesla in 2023?"
]

# Test the chatbot with example queries


for query in queries:
print(f"Query: {query}")
print(f"Response: {chatbot(query)}\n")

Query: What is the total revenue for Microsoft in 2023?


Response: The total revenue for Microsoft in 2023 is 211915 million.

Query: How has net income changed for Tesla over the last year?
Response: The net income for Tesla in 2023 is 14974 million, compared to 12587 million in 2022.

Query: What are the current assets for Apple in 2022?


Response: The current assets for Apple in 2022 are 352755 million.

Query: What is the debt-to-equity ratio for Microsoft in 2021?


Response: The debt-to-equity ratio for Microsoft in 2021 is 1.35.

Query: How much is the net profit margin for Tesla in 2023?
Response: The net profit margin for Tesla in 2023 is 15.47%.

Financial Chatbot Documentation


Overview
This chatbot is designed to answer predefined financial queries based on the financial statements of Microsoft, Tesla, and Apple for the years 2021, 2022, and 2023. The chatbot uses a simple if-else logic to match user queries with
predefined responses.

How It Works
Data Loading: The financial data is loaded from a CSV file into a pandas DataFrame.
Predefined Queries: The chatbot can respond to specific financial queries related to total revenue, net income changes, current assets, debt-to-equity ratio, and net profit margin.
User Interaction: Users can type their queries, and the chatbot will provide the corresponding response. If the query is not recognized, the chatbot will inform the user.

Predefined Queries
"What is the total revenue for Microsoft in 2023?"
"How has net income changed for Tesla over the last year?"
"What are the current assets for Apple in 2022?"
"What is the debt-to-equity ratio for Microsoft in 2021?"
"How much is the net profit margin for Tesla in 2023?"

Limitations
Limited Query Set: The chatbot can only respond to the predefined queries listed above. It does not handle other types of financial questions.
Static Data: The responses are based on static data from the provided financial statements. Any updates to the financial data will require manual updates to the chatbot’s responses.
Simple Logic: The chatbot uses basic if-else logic, which may not be suitable for more complex interactions or dynamic data analysis.

In [ ]:

You might also like