Stock Market Analysis with Pandas – DataReader and Plotly for Beginners

05 Jun 2023 Balmiki Mandal 0 AI/ML

Steps on how to perform stock market analysis with Pandas, DataReader, and Plotly for beginners:

  1. Import the necessary libraries.
import pandas as pd
import pandas_datareader as pdr
import plotly.graph_objects as go
  1. Specify the source of your data, time period, and stocks list for analysis.
start_date = '2022-01-01'
end_date = '2023-06-05'
stocks = ['GOOGL', 'AMZN', 'MSFT', 'AAPL', 'FB']
  1. Import stocks data and create a separate dataframe.
df = pdr.get_data_yahoo(stocks, start_date, end_date)
  1. The data has multilevel indexing. We took a cross-section of the dataframe to analyse each stock and its movement.
for stock in stocks:
    df_stock = df[stock]
    fig = go.Figure(data=[
        go.Candlestick(
            x=df_stock.index,
            open=df_stock['Open'],
            high=df_stock['High'],
            low=df_stock['Low'],
            close=df_stock['Close']
        )
    ])
    fig.show()
  1. Candlestick charts are important to get a better understanding of the past stock movements.

  2. We can also compare a few stocks for a specific time period.

fig = go.Figure(data=[
    go.Candlestick(
        x=df_stock.index,
        open=df_stock['Open'],
        high=df_stock['High'],
        low=df_stock['Low'],
        close=df_stock['Close'],
        name=stock
    ) for stock in stocks
])
fig.show()

This is just a basic example of how to perform stock market analysis with Pandas, DataReader, and Plotly. There are many other things you can do with these libraries, such as calculating technical indicators, performing statistical analysis, and backtesting trading strategies.

 

 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.