Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!
This article is an excerpt from the book, The Future of Finance with ChatGPT and Power BI, by James Bryant, Alok Mukherjee. Enhance decision-making, transform your market approach, and find investment opportunities by exploring AI, finance, and data visualization with ChatGPT's analytics and Power BI's visuals
In this section, we will explore an interesting example of how ChatGPT can be used to analyze and summarize earnings reports, enabling you to identify key insights and trends quickly. With the vast amount of information available in earnings reports, it can be challenging to sift through data and identify the most critical elements. Let’s see how ChatGPT can help.
Here’s the scenario – Palo Alto Networks has just released its quarterly earnings report. You want to understand the company’s financial performance and identify any trends or potential issues that may impact the stock price or investment potential:
Step 1 – Extract key data points:
To get started, provide ChatGPT with the relevant earnings report data, such as revenue, net income, EPS, and any other important metrics. Be sure to include both current and historical data for comparison purposes. You can either input this data manually or automate the process using an API or web scraper. Let’s explore the automated process to add Palo Alto Networks’ financial information from September 2021 to March 2023 to ChatGPT.
Step 1.1 – Automating data collection with Python and API/web scraping:
1. Choose a financial API or web scraping library in Python:
2. Set up your Python script for data collection:
3. Collect historical data from September 2021 to March 2023 for the relevant financial metrics:
4. Save the collected data in a structured format, such as a CSV file or a pandas DataFrame, for further processing and analysis:
With these additions, you should have a better understanding of where to obtain financial data and the necessary Python libraries to import for their data collection scripts.
We will now provide a step-by-step guide using Python code for Palo Alto Networks’ financial data.
Extract Palo Alto Networks’ quarterly financial data (revenue, net income, and EPS) for the time period September 2021–March 2023, and save it in a CSV file as text input, using the Alpha Vantage API key (finance website):
1. Install the necessary Python package and pandas library in Command Prompt:
pip install requests
pip install pandas
2. Create a new Python script file in Notepad, Notepad++, PyCharm, or Visual Studio code. It is important that you add your Alpha Vantage API key in the following api_key line. Copy and paste the following code into your Python script file, and name it PANW.py:
import requests
import pandas as pd
api_key = "YOUR_API_KEY"
symbol = "PANW"
url = f"https://www.alphavantage.co/
query?function=EARNINGS&symbol={symbol}&apikey={api_key}"
try:
response = requests.get(url)
response.raise_for_status() # Raise HTTPError for bad
responses
data = response.json()
if 'quarterlyEarnings' in data:
quarterly_data = data['quarterlyEarnings']
df = pd.DataFrame(quarterly_data)
df_filtered = df[(df['reportedDate'] >= '2021-09-01') & (df['reportedDate'] <= '2023-03-31')]
df_filtered.to_csv("palo_alto_financial_data.csv",
index=False)
input_text = "Analyze the earnings data of Palo Alto Networks from September 2021 to March 2023.\n\n"
for idx, row in df_filtered.iterrows():
quarter = idx + 1
revenue = row.get('revenue', 'N/A')
net_income = row.get('netIncome', 'N/A')
eps = row.get('earningsPerShare', 'N/A')
input_text += f"Quarter {quarter}:\n"
input_text += f"Revenue: ${revenue}\n"
input_text += f"Net Income: ${net_income}\n"
input_text += f"Earnings Per Share: ${eps}\n\n"
with open("palo_alto_financial_summary.txt", "w") as f:
f.write(input_text)
else:
print("Data not available.")
except requests.RequestException as e:
print(f"An error occurred: {e}")
3. Run the Python script file:
Python PANW.py
4. A separate text file, palo_alto_financial_summary.txt, and a CSV file, palo_ alto_financial_data.csv, will be created once the Python script has been executed:
You can upload the CSV file (palo_alto_financial_data.csv) to ChatGPT directly if you are a ChatGPT Plus user by following these steps:
Uploading a CSV file directly into ChatGPT is supported through the Advanced Data Analysis option for ChatGPT Plus users. You can access the OpenAI website at https://openai.com/, and then log in using your login credentials. Once logged in, access your Settings and Beta options by clicking on the three dots near your email address in the bottom-left corner of the screen. Go to Beta features and activate the Advanced data analysis function by moving the slider to the right to activate (the option will turn green). Once this feature is activated, go to GPT-4 at the top center of the screen and then select Advanced Data Analysis from the drop-down list. You can click on the plus sign in the dialog box to upload the CSV file to ChatGPT:
• CSV file size limitations: 500 MB
• CSV file retention: Files are retained while a conversation is active and for three hours after the conversation is paused
If you are not a ChatGPT Plus user, follow the following instructions using the OpenAI API to upload the CSV file (palo_alto_financial_data.csv) into ChatGPT, and analyze the data using the GPT 3.5 turbo model:
1. Create a new Python script file in Notepad, Notepad++, PyCharm, or Visual Studio Code. It is important that you add your OpenAI API key to the following api_key line. Copy and paste the following code into your Python script file and name it OPENAIAPI.py:
import openai
import pandas as pd
df = pd.read_csv("palo_alto_financial_data.csv")
csv_string = df.to_string(index=False)
api_key = "your_openai_api_key_here"
openai.api_key = api_key
input_text = f"Here is the financial data for Palo Alto
Networks:\n\n{csv_string}\n\nPlease analyze the data and provide
insights."
response = openai.Completion.create(
engine="gpt-3.5-turbo", # Specifying GPT-3.5-turbo engine
prompt=input_text,
max_tokens=200 # Limiting the length of the generated text
)
generated_text = response.choices[0].text.strip()
print("GPT-3.5-turbo PANW Analysis:", generated_text)
2. Run the Python script file:
Python OPENAIAPI.py
In conclusion, harnessing ChatGPT's capabilities, we've navigated Palo Alto Networks' earnings landscape. From automated data extraction to insightful analysis, this journey unveiled crucial financial trends. Whether utilizing APIs or scraping web data, the process demystified complexities, offering a streamlined approach. By generating comprehensive summaries and interacting with ChatGPT for deeper insights, the pathway to understanding financial data has been simplified. Embracing AI-powered analysis enables swift comprehension of earnings reports, empowering informed decisions in the realm of financial scrutiny and investment strategies.
James Bryant, a finance and technology expert, excels at identifying untapped opportunities and leveraging cutting-edge tools to optimize financial processes. With expertise in finance automation, risk management, investments, trading, and banking, he's known for staying ahead of trends and driving innovation in the financial industry. James has built corporate treasuries like Salesforce and transformed companies like Stanford Health Care through digital innovation. He is passionate about sharing his knowledge and empowering others to excel in finance. Outside of work, James enjoys skiing with his family in Lake Tahoe, running half marathons, and exploring new destinations and culinary experiences with his wife and daughter.
Aloke Mukherjee is a seasoned technologist with over a decade of experience in business architecture, digital transformation, and solutions architecture. He excels at applying data-driven solutions to real-world problems and has proficiency in data analytics and planning. Aloke worked at EMC Corp and Genentech and currently spearheads the digital transformation of Finance Business Intelligence at Stanford Health Care. In addition to his work, Aloke is a Certified Personal Trainer and is passionate about helping his clients stay fit. Aloke also has a passion for wine and exploring new vineyards.