Skip to content

Instantly share code, notes, and snippets.

# Create a variable n with a value of 10
n = 10
# Create a column by name, RSI and assign the calculation of RSI to it
df['RSI'] = ta.RSI(np.array(df['Close'].shift(1)), timeperiod=n)
df
#declare figure
fig = go.Figure()
#Set up traces
fig.add_trace(go.Candlestick(x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close'], name = 'market data'))
# Calculate the confusion matrix
cm = confusion_matrix(y[split:], y_predict)
cm
# Create a new SVC classifier
cls = SVC(C=best_C, kernel=best_kernel, gamma=best_gamma)
# Drop the rows with zero volume traded
df = df.drop(df[df['Volume'] == 0].index)
df = yf.download('TSLA',period = '1d', interval = '1m')
df
# 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
# Call the RandomizedSearchCV function and pass the parameters
rcv = RandomizedSearchCV(pipeline, parameters, cv=TimeSeriesSplit(n_splits=2))
parameters = {'svc__C': c,
'svc__gamma': g,
'svc__kernel': ['rbf']
}
# Test variables for 'c' and 'g'
c = [10, 100, 1000, 10000]
g = [1e-2, 1e-1, 1e0]