This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import the necessary libraries | |
| import yfinance as yf | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| # Import the price data of General Motors | |
| df = yf.download('GM','2008-01-02', '2020-2-27') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculate the daily percentage change, mean and sigma | |
| df['daily_pct_change'] = df['Adj Close'].pct_change() | |
| mu = df['daily_pct_change'].iloc[:-252].mean() | |
| sigma = df['daily_pct_change'].iloc[:-252].std() | |
| # Creating the random walk simulation of the probable price path | |
| simulation = {} | |
| simulation['Actual'] = list(df['Adj Close'].iloc[-252:].values) | |
| for sim in range(1,5): # Taking 5 paths |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Plotting the actual Adjusted Close price of General Motors | |
| df['Adj Close'][-252:].plot(figsize=(10,7),grid=True,legend=False) | |
| plt.xlabel('Year') | |
| plt.ylabel('Price') | |
| # Plotting the simulation of random walk | |
| simulation=pd.DataFrame(simulation) | |
| simulation.index=df[-252:].index | |
| simulation.plot(figsize=(10,7),grid=True,legend=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import 11 day Tesla data | |
| import yfinance as yf | |
| tesla = yf.download('TSLA','2020-01-27', '2020-02-11') | |
| tesla['Close'] | |
| # Calculating the 5 number summary | |
| from numpy import percentile | |
| # calculate quartiles | |
| All_quartiles = percentile(tesla['Close'], [25, 50, 75]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import statistics as st | |
| print("Variance of the Closing price is % s" | |
| %(st.variance(tesla['Close']))) | |
| print("Standard Deviation of Closing Price is % s " | |
| % (st.stdev(tesla['Close']))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| tesla['Close'].plot(figsize=(10,7)) | |
| plt.legend() | |
| plt.grid() | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing the modules | |
| import yfinance as yf | |
| import pandas as pd | |
| import numpy as np | |
| from sklearn.preprocessing import MinMaxScaler | |
| from sklearn.metrics import confusion_matrix | |
| from keras.models import Sequential | |
| from keras.layers import Dense, Dropout, LSTM | |
| # Downloading GOOGLE OHLCV using yfinance with adjusted prices |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import plotly | |
| import plotly.graph_objs as go | |
| plotly.offline.plot({ | |
| "data": [go.Scatter(x=[11, 15, 30, 37, 42], y=[15, 18, 71, 42, 42])], | |
| "layout": go.Layout(title="HTML file")}, auto_open=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import plotly | |
| import plotly.graph_objs as go | |
| plotly.offline.iplot({ | |
| "data": [go.Scatter(x=[11, 15, 30, 37, 42], y=[15, 18, 71, 42, 42])], | |
| "layout": go.Layout(title="Line plot")}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing libraries | |
| import yfinance as yf | |
| import plotly as py | |
| import plotly.graph_objects as go | |
| import pandas as pd | |
| # Import Tesla data | |
| tesla = yf.download('TSLA','2020-02-01', '2020-03-03') |