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 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 |
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
| #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')) |
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
| # Calculate the confusion matrix | |
| cm = confusion_matrix(y[split:], y_predict) | |
| cm |
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 new SVC classifier | |
| cls = SVC(C=best_C, kernel=best_kernel, gamma=best_gamma) |
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
| # Drop the rows with zero volume traded | |
| df = df.drop(df[df['Volume'] == 0].index) |
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
| df = yf.download('TSLA',period = '1d', interval = '1m') | |
| df |
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
| # 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 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
| # Call the RandomizedSearchCV function and pass the parameters | |
| rcv = RandomizedSearchCV(pipeline, parameters, cv=TimeSeriesSplit(n_splits=2)) |
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
| parameters = {'svc__C': c, | |
| 'svc__gamma': g, | |
| 'svc__kernel': ['rbf'] | |
| } |
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
| # Test variables for 'c' and 'g' | |
| c = [10, 100, 1000, 10000] | |
| g = [1e-2, 1e-1, 1e0] |