Exploring Financial Markets With Python - A Simple Guide To Stock - by Dotun Alex Omoboye - Medium
Exploring Financial Markets With Python - A Simple Guide To Stock - by Dotun Alex Omoboye - Medium
Danilo Freitas
[email protected]
Free
Requirements
Try for $ 5 $ 4/month
Before we go into the financial aspect of Python, ensure you have the necessary
libraries installed. You can install them using the following:
pip install yfinance matplotlib pandas
Free
# Plotting
plt.figure(figsize=(14, 10))
Be part of a better internet.
# Closing Price and 60-day SMA
Get 20% off2,membership
plt.subplot(2, 1) for a limited time.
plt.plot(stock_data.index, stock_data['Close'],
label=f'{symbol} Closing Price')
plt.plot(stock_data.index, stock_data['SMA_60'],
label=f'{symbol}Free
60-day SMA', linestyle='--')
plt.title(f'{symbol} Closing Price and 60-day SMA')
plt.xlabel('Date')
Distraction-free reading. No ads.
plt.ylabel('Price (GBP)')
plt.legend()
Organize your knowledge with lists and highlights.
# Opening Price
Tell your story. Find your audience.
plt.subplot(2, 2, 2)
plt.plot(stock_data.index, stock_data['Open'],
label=f'{symbol} Opening Price', color='orange')
plt.title(f'{symbol} Opening Price')
plt.xlabel('Date')
plt.ylabel('Price (GBP)')
plt.legend()
# Volume
Membership
plt.subplot(2, 2, 3) Get 20% off
plt.bar(stock_data.index, stock_data['Volume'],
label=f'{symbol} Volume', color='green')
Read member-only
plt.title(f'{symbol} stories
Volume')
plt.xlabel('Date')
Support writers you read most
plt.ylabel('Volume')
plt.legend()
Earn money for your writing
# Daily Percentage Change
Listen to audio narrations
plt.subplot(2, 2, 4)
plt.plot(stock_data.index, stock_data['Daily_Return'],
Read offline with the Medium app
label=f'{symbol} Daily % Change', color='purple')
plt.title(f'{symbol} Daily Percentage Change')
plt.xlabel('Date')
plt.ylabel('% Change')
plt.legend()
plt.tight_layout()
plt.show()
except Exception as e:
print(f"Error fetching data for {symbol}: {e}")
Free
#Output
Enter financial stock symbols separated by commas (e.g., AAPL,
MSFT): AAPL, AMZN, GOOGL, TSLA, COMP, GS, META, MSFT, DJIA
#Output
[*********************100%%**********************] 1 of 1 completed
The code generates four charts for each stock symbol entered by the user, These
Be part of aofbetter
charts provide a visual representation various internet.
aspects of the selected stocks, such
as closing and Get 20%
opening off membership
prices, moving averages,for
andadaily
limited time.changes,
percentage
allowing for a quick and intuitive analysis of their historical performance. Let’s
break down each chart:
Free
Opening Price Chart:
Data: This chart displays the opening
Distraction-free prices
reading. of the selected stocks over the
No ads.
specified time period.
Organize your knowledge with lists and highlights.
Title and Labels: The chart has a title indicating that it shows the Opening Prices
for the selected stocks. The x-axis represents the date, and the y-axis represents
the opening price in USD.
Lines: The solid line represents the closing prices, and the dashed line
represents the 60-day SMA.
Title and Labels: Similar to the Closing Price chart, but with an additional
indication of the SMA.
Legend: The legend distinguishes between Closing Price and 60-day SMA.
Be part
Daily Percentage Change of a better internet.
Chart:
Get 20%
Data: This chart offthe
displays membership for
daily percentage a limited
change time.
in closing prices for the
selected stocks.
[*********************100%%**********************]
Listen to audio narrations 1 of 1 completed
#Google
Read offline with the Medium app
[*********************100%%**********************] 1 of 1 completed
[*********************100%%**********************] 1 of 1 completed
Free
[*********************100%%**********************] 1 of 1 completed
Data Analysis: The script calculates a 60-day simple moving average (SMA) for each
financial stock.
Data Visualization: It uses matplotlib to plot the closing prices and the 60-day SMA.
This Python script offers a simple yet effective way to analyze and visualize financial
market prices. Whether you are a financial analyst, stock market investor or just an
enthusiast, Python can be a powerful ally in understanding and interpreting
Be
financial data. Feel free to part ofthe
customize a better internet.
script based on your specific financial
analysis needs.Get 20% off membership for a limited time.
Follow
Free
Machine Learning Predictions for the 2023 Cricket World Cup:
Leveraging Python and Historical Match
Distraction-free reading. No ads.
Introduction
Organize your knowledge with lists and highlights.
Oct 5, 2023 2
Tell your story. Find your audience.
Free
Sep 1, 2023 4 2
Support
Alexander Nguyen in Level Up Codingwriters you read most
Free
FREE Stock APIs
Being a college undergrad, you will find a lot of people expressing their thoughts about how
stock market helped them toDistraction-free reading. No ads.
earn a lot, and…
Organize your knowledge with lists and highlights.
Feb 6 884 8
Tell your story. Find your audience.
Lists
Staff Picks
681 stories · 1114 saves
Membership Get 20% off
Self-Improvement
Support101
writers you read most
20 stories · 2244 saves
Earn money for your writing
Productivity 101
Listen to audio narrations
20 stories · 1987 saves
Free
Prompt Engineering Is Dead: DSPy Is New Paradigm For Prompting
DSPy Paradigm: Let’s program — not prompt — LLMs
Distraction-free reading. No ads.
Free
Predicting Stock Prices with an LSTM Model in Python
Free
Fundamental Analysis for ranking Stocks with Python API
This article will rank stocks based on their fundamentals and stock details. The approach
builds on the previous articleDistraction-free
"Fundamental reading.
Stock… No ads.
Free