Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
277 views

Stocks Data Analysis and Visualization Using Python Assignment

This document describes using Python to analyze stock price data and visualize key metrics like daily returns and risks. It provides a dataset of daily stock prices for several major companies and an S&P 500 index. It then lists questions to help learn how to read the data, calculate daily returns, plot raw and normalized prices, correlate returns between stocks, and generate other visualizations to analyze stock performance and risk.

Uploaded by

bug myweeks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
277 views

Stocks Data Analysis and Visualization Using Python Assignment

This document describes using Python to analyze stock price data and visualize key metrics like daily returns and risks. It provides a dataset of daily stock prices for several major companies and an S&P 500 index. It then lists questions to help learn how to read the data, calculate daily returns, plot raw and normalized prices, correlate returns between stocks, and generate other visualizations to analyze stock performance and risk.

Uploaded by

bug myweeks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Stocks Data Analysis and Visualization Solution Using Python

Problem Statement:
For Investors to properly manage their portfolios, they need to visualize datasets, find
useful patterns and gain valuable insights such as stock daily returns and risks.
In this project we will use the power of python to perform stock data visualization and
stock return calculation.
Dataset:
Link: https://drive.google.com/file/d/1VX2IO8FVaFgv7dCPzH-
7WxSLHhxwkbK8/view?usp=sharing
The Dataset contains stock prices of certain companies listed in S&P 500. S&P 500 is
a stock market index that measures the stock performance of 500 large companies
listed on U.S. stock exchange.
Check the list of S&P 500 companies here:
https://en.wikipedia.org/wiki/List_of_S%26P_500_companies

Below is the list of stocks considered:


AAPL = Apple Stock
BA = Boeing
T = AT&T
MGM = MGM Resorts International (Hotel Industry)
AMZN = Amazon
IBM = IBM
TSLA = Tesla Motors
GOOG = Google
Questions:
1) How do you read the data from stock.csv file using pandas module.
2) Print out the number of stocks.
3) Print the name of stocks.(Try using for loop)
4) What is the average return of the S&P500?
5) Which stock or index has the minimum dispertion from the mean in dollar
value?
6) What is the maximum price for AMZN stock over the specified time
period?
7) Check if data contains any null values.
8) Get dataframe information.
9) Define a function to plot RAW STOCK PRICES (WITHOUT
NORMALIZATION/WITHOUT SCALING).
# The function takes in a Dataframe df as an input argument and does not
return anything back!
# The function performs data visualization.
# Pandas works great with matplotlib, you can simply plot data directly from a
Pandas DataFrame using plot() method(Take Date on X – axis).
10) Plot Normalized/Scaled stock prices.
# To plot Normalized/Sclaed stock prices means to start all of the stock prices
at one point so that they can be easily compared.This will help you to see the
amount of gains you are going to get from the listed companies.
# Create a Function that takes in Dataframe and returns Normalized Dataframe.
# For Normalization take the stock prices and divide them by the value in the
first row of dataframe.( Notice the massive gains in Tesla Stock)
11) Perform Interactive Data visualization using Plotly.
Ref: https://plotly.com/python/
Ref: https://plotly.com/python/line-charts/
# Write a Function to perform an interactive data plotting of RAW STOCK
PRICES (WITHOUT NORMALIZATION/WITHOUT SCALING) using
plotly express.
# Plotly.express module which is imported as px includes functions that can
plot interactive plots easily and effectively.
# Loop through each stock (while ignoring time columns with index 0)
# add a new Scatter trace.(hint:fig.add_scatter)
12) SimilarlyPlot normalized stock data in an interactive way.
13) It seems that most stocks experienced massive drops in 2020, let's assume
that you own 100 shares of the S&P500 and you bought them on Feb 19th,
2020. How much did you lose (in $) by March 23rd, 2020? Hint: S&P500
dropped from $3386.15 on Feb 19th, 2020 to $2237.4 by March 23rd, 2020.
14) Calculate the daily return for S&P 500.

# get sp500 data from the dataframe.

#l loop through every element in the data frame.


# Calculate the percentage of change from the previous day.
Hint: df_daily_return[j] = ((df[j]- df[j-1])/df[j-1]) * 100
# put zero in the first line item

15) Calculate the daily return for Amazon stock.


16) Define a function to calculate stocks daily returns (for all stocks)
# With in the function Loop through each stock (while ignoring time columns
with index 0)
# Loop through each row belonging to the stock
# Calculate the percentage of change from the previous day
Hint: df_daily_return[i][j] = ((df[i][j]- df[i][j-1])/df[i][j-1]) * 100
# Set the value of first row to zero since the previous value is not available
# Use the function to get Daily returns of all the stocks.

17) Plot the Daily returns vs. time graph using both static and interactive
plots.

Hint: use function obtianed in question 10 and question 11.


18) Calculate correlation between Daily returns of all stocks.
# Drop Date column.
# Use .corr() function
# Use heat map to show correlation.
19) From the heatmap obtained ans the following questions.
# What are the top 2 stocks that are positively correlated with the S&P500?
#What is the correlation between Amazon and Boeing? Comment on your
answer
# What is the correlation between MGM and Boeing? Comment on your
answer

20) Plot Histogram for Daily returns.


21) Based on the histogram, which of the following stocks are more risky? T or
TSLA

You might also like