Skip to content

Instantly share code, notes, and snippets.

# Create the 'steps' variable with the pipeline functions
steps = [('scaler', StandardScaler()), ('svc', SVC())]
# Pass the 'steps' to the Pipeline function
pipeline = Pipeline(steps)
# Use drop method to drop the columns
X = df.drop(['Close', 'Signal', 'High',
'Low', 'Volume', 'Ret'], axis=1)
# Create a variable which contains all the 'Signal' values
y = df['Signal']
# Create a column by name, 'Signal' and initialize with 0
df['Signal'] = 0
# Assign a value of 1 to 'Signal' column for the quantile with the highest returns
df.loc[df['Ret'] > df['Ret'][:split].quantile(q=0.66), 'Signal'] = 1
# Assign a value of -1 to 'Signal' column for the quantile with the lowest returns
df.loc[df['Ret'] < df['Ret'][:split].quantile(q=0.34), 'Signal'] = -1
# Data manipulation libraries
import pandas as pd
import numpy as np
# Machine learning libraries
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import RandomizedSearchCV
from sklearn.model_selection import TimeSeriesSplit
from sklearn.pipeline import Pipeline
# Gathering all the data of the current page to one dataframe
def newsfeed(article_info, raw_dictionary):
for i in range(len(raw_dictionary)-1):
if raw_dictionary is not None:
# Fetch the date and time and convert it into datetime format
date = raw_dictionary[i]['datetime']
date = pd.to_datetime(date)
# Fetch the title, time, description and source of the news articles
title = raw_dictionary[i]['title']
time = raw_dictionary[i]['date']
# Import pandas and numpy
import pandas as pd
import numpy as np
# Import the GoogleNews package to fetch the news articles
from GoogleNews import GoogleNews
googlenews = GoogleNews()
keywords = ['Real Madrid', 'SP500', 'ETH', 'ADA']
googlenews.set_time_range('08/02/2021', '08/03/2021')
#googlenews.set_period('7d')
# Dataframe to store the news article information
article_info = pd.DataFrame(columns=['Date', 'Time', 'Title', 'Articles', 'Link'])
# Gathering all the data of the current page to one dataframe
def newsfeed(article_info, raw_dictionary):
for i in range(len(raw_dictionary)-1):
if raw_dictionary is not None:
# Fetch the date and time and convert it into datetime format
date = raw_dictionary[i]['datetime']
date = pd.to_datetime(date)
keywords = ['Real Madrid', 'SP500', 'ETH', 'ADA']
googlenews.set_time_range('08/02/2021', '08/04/2021')
#googlenews.set_period('7d')
googlenews.set_lang('en')
# Import pandas and numpy
import pandas as pd
import numpy as np
# Import the GoogleNews package to fetch the news articles
from GoogleNews import GoogleNews
googlenews = GoogleNews()
i = 0
Date=[]
while(i<len(data)):
Date.append(datetime.fromtimestamp(data[i][0]/1000).strftime('%Y-%m-%d %H:%M:%S'))
i+=1
df['Date'] = Date
df.set_index('Date', inplace = True)