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
| # Plot ROC area under the curve | |
| from sklearn.preprocessing import label_binarize | |
| from sklearn.multiclass import OneVsRestClassifier | |
| from sklearn.metrics import roc_curve, auc | |
| from itertools import cycle | |
| from sklearn import svm | |
| from scipy import interp | |
| # Binarize the output |
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
| def get_daily_adjusted_price_data(api_key, stock): | |
| url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={stock}&outputsize=full&apikey={api_key}" | |
| raw_data = requests.get(url).json() | |
| return raw_data | |
| def create_dataframe(raw_data): | |
| dataframe = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume']) | |
| for key in raw_data["Time Series (Daily)"].keys(): |
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
| raw_data.drop(['exchange'], axis=1, inplace=True) | |
| raw_data.drop(['delayed', 'realtimeEntitled'], axis=1, inplace=True) | |
| # Similar operation as above on a list of columns that only have 1 unique value | |
| for column in list(raw_data.columns): | |
| if raw_data[column].nunique() <= 1: | |
| raw_data.drop(column, axis=1, inplace=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
| raw_data.drop( | |
| ['cusip', | |
| 'assetType', | |
| 'description', | |
| 'assetMainType', | |
| 'symbol', | |
| 'securityStatus', | |
| 'symbol.1', | |
| 'bidTick', | |
| 'exchangeName', |
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
| CREATE DATABASE wallstreetbets; | |
| \connect wallstreetbets; | |
| CREATE TABLE sentiment_analysis( | |
| stock text, | |
| Bearish text, | |
| Neutral text, | |
| Bullish text, | |
| Total_Compound text, |
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
| from os import set_blocking | |
| import requests | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import date | |
| import plotly.graph_objects as go | |
| # Import data and convert date column to datetime datatype | |
| historic_sentiment_analysis = pd.read_csv('historic_sentiment_analysis.csv') | |
| historic_sentiment_analysis['date'] = pd.to_datetime(historic_sentiment_analysis['date']) |
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
| from os import set_blocking | |
| import requests | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import date | |
| import matplotlib.pyplot as plt | |
| # Load in df | |
| df = pd.read_csv('df.csv', index_col=0) |
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 Libraries | |
| import pandas as pd | |
| import praw | |
| from data import * | |
| import time | |
| import matplotlib.pyplot as plt | |
| import squarify | |
| from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
| from datetime import date |
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 numpy as np | |
| import pandas as pd | |
| '''includes US stock symbols with market cap > 100 Million, and price above $3. | |
| Download the csv file: | |
| https://www.nasdaq.com/market-activity/stocks/screener?exchange=nasdaq&letter=0&render=download | |
| for all of the NYSE, NASDAQ and NYSEAMERICAN public traded companies. | |
| ''' | |
| stocks = pd.read_csv('tickers.csv') |
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
| # features and target | |
| X = df.loc[:,'limit_bal':'Apr_Pmt'] | |
| y = df['Default'] | |
| # encode categorical | |
| categoricals = list(X.select_dtypes('object').columns) | |
| numericals = list(X.select_dtypes('int64').columns) | |
| def encode_cats(categoricals, numericals): | |
| """ |
NewerOlder