bvkin / trade_bot

Bot to automatically manage a stock portfolio
1 stars 0 forks source link

Implement K-Nearest-Neighbors on Bollinger Bands #42

Open bbell03 opened 10 months ago

bbell03 commented 10 months ago

Start learning on trading data and strategy for enhanced decision making.

bbell03 commented 10 months ago

from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split

X, y = get_clean_Xy(data)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=0)

clf = KNeighborsClassifier(7)  # Model the output based on 7 "nearest" examples
clf.fit(X_train, y_train)

y_pred = clf.predict(X_test)

_ = pd.DataFrame({'y_true': y_test, 'y_pred': y_pred}).plot(figsize=(15, 2), alpha=.7)
print('Classification accuracy: ', np.mean(y_test == y_pred))
bbell03 commented 10 months ago

https://colab.research.google.com/github/kernc/backtesting.py/blob/master/doc/examples/Trading%20with%20Machine%20Learning.ipynb#scrollTo=HjgBAM5CgJv8