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 the 'steps' variable with the pipeline functions | |
| steps = [('scaler', StandardScaler()), ('svc', SVC())] | |
| # Pass the 'steps' to the Pipeline function | |
| pipeline = Pipeline(steps) |
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
| # 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'] |
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 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 |
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
| # 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 |
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
| # 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'] |
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 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') |
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
| # 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) |
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
| keywords = ['Real Madrid', 'SP500', 'ETH', 'ADA'] | |
| googlenews.set_time_range('08/02/2021', '08/04/2021') | |
| #googlenews.set_period('7d') | |
| googlenews.set_lang('en') |
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 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() |
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
| 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) |