This file contains 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
#Neccessary librairies | |
from binance import Client | |
import pandas as pd | |
import numpy as np | |
import talib as ta | |
import time | |
#Insert your secret key | |
key = 'AsEGPnZK7hpF7DFUb4Bdsmd5nTf1q6qQ1ULhqlaafdPWl0T1l6bbTm6QyuTrOJeP' | |
secret = '640p8wsE9cOUmJ7qH2RkleRzOn8HCdlXE2r4uZctLgP25Cp4lT9j3cCrAsrslKUx' |
This file contains 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
#Copy and paste your API keys within these variables | |
key = 'H0gXdPT6Zu12L7siZQBOoI3JJZaN2i9leT7eM457IFHHG980aeds76' | |
secret = '2KwevuHUq1IHW1jsC4WBtABn4hzB2i9leT7eM457IFHHG980aeds76' | |
# Store the connection command line within a variable called "client" | |
client = Client(api_key=key, api_secret = secret) |
This file contains 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'] | |
# Test variables for 'c' and 'g' | |
c = [10, 100, 1000, 10000] | |
g = [1e-2, 1e-1, 1e0] |
This file contains 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
# Save the predicted values for the train data | |
df.iloc[:split, df.columns.get_loc('Pred_Signal')] = pd.Series( | |
cls.predict(ss1.transform(X.iloc[:split])).tolist()) | |
# Save the predicted values for the test data | |
df.iloc[split:, df.columns.get_loc('Pred_Signal')] = y_predict |
This file contains 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
# Pass the test data to the predict function and store the values into 'y_predict' | |
y_predict = cls.predict(ss1.transform(X.iloc[split:])) | |
# Initiate a column by name, 'Pred_Signal' and assign 0 to it | |
df['Pred_Signal'] = 0 |
This file contains 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 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
# Call the 'fit' method of rcv and pass the train data to it | |
rcv.fit(X.iloc[:split], y.iloc[:split]) | |
# Call the 'best_params_' method to obtain the best parameters of C | |
best_C = rcv.best_params_['svc__C'] | |
# Call the 'best_params_' method to obtain the best parameters of kernel | |
best_kernel = rcv.best_params_['svc__kernel'] | |
# Call the 'best_params_' method to obtain the best parameters of gamma |
This file contains 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
# Instantiate the StandardScaler | |
ss1 = StandardScaler() | |
# Pass the scaled train data to the SVC classifier | |
cls.fit(ss1.fit_transform(X.iloc[:split]), y.iloc[:split]) |
This file contains 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
# Test variables for 'c' and 'g' | |
#Setting the different values to test within C, Gamma and Kernel | |
c = [10, 100, 1000, 10000] | |
g = [1e-2, 1e-1, 1e0] | |
# Intialise the parameters | |
parameters = {'svc__C': c, | |
'svc__gamma': g, | |
'svc__kernel': ['rbf'] | |
} |
This file contains 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 packages | |
import pandas as pd | |
import numpy as np | |
import yfinance as yf | |
#Scrap the data | |
#data = pd.read_html('https://indiancompanies.in/listed-companies-in-nse-with-symbol/')[0] | |
data = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0]["Symbol"] | |
data |
NewerOlder