yasinkuyu / binance-trader

💰 Cryptocurrency Trading Bot for Binance (Experimental)
2.49k stars 824 forks source link

Trying to integrate stock prediction csv script #223

Open obstructables opened 6 years ago

obstructables commented 6 years ago

I've been trying to integrate this script into the bot, however I am missing a csv file. I vaguely recall an earlier version of this bot using .accdb files @yasinkuyu if this is right, I'd love to get those for this script to work.

import csv import numpy import sklearn.svm from sklear.svm import SVR import matploitlib.pyplot as plt

dates = [] prices = []

def get_name(filename): with open(filename, 'r') as csvfile: next(csvFileReader) for row in csvFileReader: dates.append(int(row[0].split('-')[0])) priices.append(float(row[1])) return def predict_prices(dates, prices, x): dates = np.reshape(dates, (len(dates), 1))

svr_lin = SVR(kernel= 'linear', C=1e3)
svr_poly = SVR(kernel= 'poly', C=1e3, degree=2)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin.fit(dates, prices)
svr_poly.fit(dates, prices)
svr_rbf.fit(dates, prices)

plt.scatter(dates, prices, color='black', label='Data')
plt.plot(dates, svr_lin.prdict(dates, color='green', label='Linear Model'))
plt.plot(dates, svr_poly.prdict(dates, color='blue', label='Polynomial Model'))
plt.plot(dates, svr_rbf.prdict(dates, color='red', label='RBF Model'))
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Support Vector Regression')
plt.legend()
plt.show()

return svr_lin.predict(x)[0], svr_poly.predict(x)[0], svr_rbf.predict(x)[0]

get_data('aapl.csv')

predicted_price(predict_price(dates, prices, 29))

print(predicted_price)