[SOLVED] 代写 C html python Assignment 5

30 $

File Name: 代写_C_html_python_Assignment_5.zip
File Size: 310.86 KB

SKU: 6787585089 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Assignment 5
For this assignment, you will do an exploratory data analysis for stock prices. The focus is on improving visualization skills.
NOTE: This assignment is very challenging because it will introduce a lot of new concepts and have you looking things up on your own Ill point you in the right direction to try to solve the tasks issued.

Well compare bank stocks and see how they changed over time.

Get the Data
In this section, you will learn how to use pandas to directly read data from Yahoo finance using pandas!
First, you need to start with the proper imports, which are already laid out for you here.
Note: Youll need to install pandasdatareader for this to work! Pandas datareader allows you to read stock information directly from the internet Use these links for install guidance conda install pandasdatareader OR pip install pandasdatareader
The Imports
Already filled out for you.
In34:
from pandasdatareader import data, wb
import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
import seaborn as sns

matplotlib inline

Data
You need to get data using pandas datareader. You will get stock information for the following banks:
Bank of America
CitiGroup
Goldman Sachs
JPMorgan Chase
Morgan Stanley
Wells Fargo
Figure out how to get the stock data from Jan 1st 2006 to current date for these banks. Set each bank to be a separate dataframe, with the variable name for that bank being its ticker symbol. This will involve a few steps:
1.Use datetime to set start and end datetime objects.
2.Figure out the ticker symbol for each bank.
3.Figure out how to use datareader to grab info on the stock.
Use this documentation page for hints and instructions it should just be a matter of replacing certain values. Use yahoo finance as a source, for example:
Bank of America
BACdata.DataReaderBAC, yahoo, start, end
In36:
start
end
In3:
Bank of America
BAC

CitiGroup
C

Goldman Sachs
GS

JPMorgan Chase
JPM

Morgan Stanley
MS

Wells Fargo
WFC
In4:
WFC
Out4:

High
Low
Open
Close
Volume
Adj Close
Date

20060103
31.975000
31.195000
31.600000
31.900000
11016400.0
21.045347
20060104
31.820000
31.365000
31.799999
31.530001
10870000.0
20.801256
20060105
31.555000
31.309999
31.500000
31.495001
10158000.0
20.778162
20060106
31.775000
31.385000
31.580000
31.680000
8403800.0
20.900213
20060109
31.825001
31.555000
31.674999
31.674999
5619600.0
20.896914







20191111
54.139999
53.730000
53.790001
54.049999
10659400.0
54.049999
20191112
54.240002
53.619999
53.750000
54.220001
15187600.0
54.220001
20191113
53.900002
53.209999
53.810001
53.290001
16846800.0
53.290001
20191114
53.560001
53.099998
53.220001
53.490002
16491400.0
53.490002
20191115
53.939999
53.430000
53.779999
53.799999
15225300.0
53.799999
3493 rows6 columns

Create a list of the ticker symbols as strings in alphabetical order. Call this list: tickers. this is done for you
In6:
tickersBAC, C, GS, JPM, MS, WFC

Use pd.concat to concatenate the bank dataframes together to a single data frame called bankstocks. Set the keys argument equal to the tickers list. Also pay attention to what axis you concatenate on. Google pandas concat
In7:

Set the column name levels this is filled out for you:
In8:
bankstocks.columns.namesBank Ticker,Stock Info

Check the head of the bankstocks dataframe.
In8:

Out8:
Bank Ticker
BAC
C

MS
WFC
Stock Info
Open
High
Low
Close
Volume
Open
High
Low
Close
Volume

Open
High
Low
Close
Volume
Open
High
Low
Close
Volume
Date

20060103
46.92
47.18
46.15
47.08
16296700
490.0
493.8
481.1
492.9
1537660

57.17
58.49
56.74
58.31
5377000
31.60
31.98
31.20
31.90
11016400
20060104
47.00
47.24
46.45
46.58
17757900
488.6
491.0
483.5
483.8
1871020

58.70
59.28
58.35
58.35
7977800
31.80
31.82
31.36
31.53
10871000
20060105
46.58
46.83
46.32
46.64
14970900
484.4
487.8
484.0
486.2
1143160

58.55
58.59
58.02
58.51
5778000
31.50
31.56
31.31
31.50
10158000
20060106
46.80
46.91
46.35
46.57
12599800
488.8
489.0
482.0
486.2
1370250

58.77
58.85
58.05
58.57
6889800
31.58
31.78
31.38
31.68
8403800
20060109
46.72
46.97
46.36
46.60
15620000
486.0
487.4
483.0
483.9
1680740

58.63
59.29
58.62
59.19
4144500
31.68
31.82
31.56
31.68
5619600
5 rows30 columns

EDA
Lets explore the data a bit! Before continuing, I encourage you to check out the documentation on MultiLevel Indexing and Using .xs. Reference the solutions if you can not figure out how to use .xs, since that will be a major part of this project.
What is the max Close price for each banks stock throughout the time period?
In9:

Out9:
Bank Ticker
BAC 54.900002
C564.099976
GS 273.380005
JPM130.380005
MS89.300003
WFC 65.930000
dtype: float64

Create a new empty DataFrame called returns. This dataframe will contain the returns for each banks stock. returns are typically defined by:
rtfracptpt1pt1fracptpt11
In10:

We can use pandas pctchange method on the Close column to create a column representing this return value. Create a for loop that goes and for each Bank Stock Ticker creates this returns column and sets it as a column in the returns DataFrame.
In11:

Out11:

BAC Return
C Return
GS Return
JPM Return
MS Return
WFC Return
Date

20060103
NaN
NaN
NaN
NaN
NaN
NaN
20060104
0.010620
0.018462
0.013812
0.014183
0.000686
0.011599
20060105
0.001288
0.004961
0.000393
0.003029
0.002742
0.001110
20060106
0.001501
0.000000
0.014169
0.007046
0.001025
0.005874
20060109
0.000644
0.004731
0.012030
0.016242
0.010586
0.000158

Create a pairplot using seaborn of the returns dataframe. Hint: 1:
In12:

Out12:
seaborn.axisgrid.PairGrid at 0x235e28c5128

Using this returns DataFrame, figure out on what dates each bank stock had the best and worst single day returns. You should notice that 4 of the banks share the same day for the worst drop, did anything significant happen that day? Hint: Google idxmin and idxman
In14:
Worst Drop 4 of them on Inauguration day
Out14:
BAC Return 20090120
C Return 20090227
GS Return20090120
JPM Return 20090120
MS Return20081009
WFC Return 20090120
dtype: datetime64ns
In15:
Best Single Day Gain
Out15:
BAC Return 20090409
C Return 20081124
GS Return20081124
JPM Return 20090121
MS Return20081013
WFC Return 20080716
dtype: datetime64ns

Take a look at the standard deviation of the returns, which stock would you classify as the riskiest over the entire time period? Which would you classify as the riskiest for the year 2018?
In18:
Citigroup is riskiest for entire period.
Out18:
BAC Return0.032286
C Return0.033885
GS Return 0.023020
JPM Return0.024493
MS Return 0.033308
WFC Return0.026649
dtype: float64
In20:
Very similar risk profiles, but Morgan Stanley is riskiest for 2018.

C:UsersTestUserMiniconda3envsdata501libsitepackagesipykernellauncher.py:1: FutureWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http:pandas.pydata.orgpandasdocsstableuserguideindexing.htmlixindexerisdeprecated
Entry point for launching an IPython kernel.
Out20:
BAC Return0.015616
C Return0.015093
GS Return 0.016175
JPM Return0.013879
MS Return 0.017187
WFC Return0.014804
dtype: float64

Create a distplot using seaborn of the 2018 returns for Morgan Stanley
In21:

C:UsersTestUserMiniconda3envsdata501libsitepackagesipykernellauncher.py:1: FutureWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http:pandas.pydata.orgpandasdocsstableuserguideindexing.htmlixindexerisdeprecated
Entry point for launching an IPython kernel.
Out21:
matplotlib.axes.subplots.AxesSubplot at 0x235e552e9e8

Create a distplot using seaborn of the 2008 returns for CitiGroup
In19:

Usersmarcianacondalibpython3.5sitepackagesstatsmodelsnonparametrickdetools.py:20: VisibleDeprecationWarning: using a noninteger number instead of an integer will result in an error in the future
yX:m21np.r0,Xm21:,01j
Out19:
matplotlib.axes.subplots.AxesSubplot at 0x11efb9518

More Visualization
A lot of this project will focus on visualizations. Feel free to use any of your preferred visualization libraries to try to recreate the described plots below, seaborn, matplotlib, plotly and cufflinks, or just pandas.
Imports
In22:
Plotly Method Imports
import plotly
import cufflinks as cf
cf.gooffline

Create a line plot showing Close price for each bank for the entire index of time. Hint: Try using a for loop, or use .xs to get a cross section of the data.
In23:

Out23:
matplotlib.legend.Legend at 0x235e8e4ae48

Moving Averages
Lets analyze the moving averages for these stocks in the year 2008.
Plot the rolling 30 day average against the Close Price for Bank Of Americas stock for the year 2008 Hint: Use ix,rolling and mean
In24:

Out24:
matplotlib.legend.Legend at 0x11f966cf8

Create a heatmap of the correlation between the stocks Close Price.
In25:

Out25:
matplotlib.axes.subplots.AxesSubplot at 0x235ea5c5b00

You will use cufflinks library to create some Technical Analysis plots.

Use .iplotkindcandle to create a candle plot of Bank of Americas stock from Jan 1st 2018 to Jan 1st 2019.
In29:

C:UsersTestUserMiniconda3envsdata501libsitepackagesipykernellauncher.py:1: FutureWarning:

.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http:pandas.pydata.orgpandasdocsstableuserguideindexing.htmlixindexerisdeprecated

Use .taplotstudysma to create a Simple Moving Averages plot of Morgan Stanley for the year 2018.
In31:

C:UsersTestUserMiniconda3envsdata501libsitepackagesipykernellauncher.py:1: FutureWarning:

.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http:pandas.pydata.orgpandasdocsstableuserguideindexing.htmlixindexerisdeprecated

Use .taplotstudyboll to create a Bollinger Band Plot for Bank of America for the year 2018.
In32:

C:UsersTestUserMiniconda3envsdata501libsitepackagesipykernellauncher.py:1: FutureWarning:

.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http:pandas.pydata.orgpandasdocsstableuserguideindexing.htmlixindexerisdeprecated

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 C html python Assignment 5
30 $