Answer to Question #294545 in Python for suresh

Question #294545

a)     Typically, the stock market opens at 9:15 hours and closes at 15:30 hours. Each stock is defined by an opening price and a closing price which are the prices it opens and closes with. Within the operating hours, the stock price touches a maximum and minimum which are the highest and lowest prices achieved by the stock in the working hours of the stock market. You have access to ten years of monthly stock price data with the Open, High, Low and Close price and the number of stocks traded for each day given by the feature Volume. On some days when there is no trading, the parameters Open, High, Low and Close remain constant and Volume is zero.

 

Furthermore, your manager also claims that the model prediction is too bad since the data is polluted. Try to impress your new boss by preprocessing the data and by giving a proper rationale behind the steps you would follow. The two datasets should be merged before preprocessing. 



1
Expert's answer
2022-02-07T00:55:03-0500
# Import the yfinance. If you get module not found error the run !pip install yfinance from your Jupyter notebook
	import yfinance as yf
	

	# Get the data for the stock AAPL
	data = yf.download('AAPL','2016-01-01','2019-08-01')
	

	# Import the plotting library
	import matplotlib.pyplot as plt
	%matplotlib inline
	

	# Plot the close price of the AAPL
	data['Adj Close'].plot()
	plt.show()

# Define the ticker list
	import pandas as pd
	tickers_list = ['AAPL', 'WMT', 'IBM', 'MU', 'BA', 'AXP']
	

	# Fetch the data
	import yfinance as yf
	data = yf.download(tickers_list,'2015-1-1')['Adj Close']
	

	# Print first 5 rows of the data
	print(data.head())

# Plot all the close prices
	((data.pct_change()+1).cumprod()).plot(figsize=(10, 7))
	

	# Show the legend
	plt.legend()
	

	# Define the label for the title of the figure
	plt.title("Returns", fontsize=16)
	

	# Define the labels for x-axis and y-axis
	plt.ylabel('Cumulative Returns', fontsize=14)
	plt.xlabel('Year', fontsize=14)
	

	# Plot the grid lines
	plt.grid(which="major", color='k', linestyle='-.', linewidth=0.5)
	plt.show()

# Import package
	import yfinance as yf
	

	# Get the data
	data = yf.download(tickers="MSFT", period="5d", interval="1m")
	

	# Print the data
	print(data.tail())

# Import packages
	import yfinance as yf
	import pandas as pd
	

	# Read and print the stock tickers that make up S&P500
	tickers = pd.read_html(
	    'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0]
	print(tickers.head())
	

	# Get the data for this tickers from yahoo finance
	data = yf.download(tickers.Symbol.to_list(),'2021-1-1','2021-7-12', auto_adjust=True)['Close']
	print(data.head())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS