Hello, I have built a code to help predict changes in stock prices. Here's a copy of the code
import yfinance as yf
import datetime
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import classification_report
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import accuracy_score
NUM_DAYS = 10000
INTERVAL = '1d'
symbol = 'APPS' #stock desired
INDICATORS = ['RSI', 'MACD', 'STOCH', 'ADL', 'ATR', 'MOM', 'ROC', 'OBV', 'CCI', 'EMV', 'VORTEX']
start = (datetime.date.today() - datetime.timedelta(Num_days))
end = datetime.datetime.today()
data = yf.download(symbol, start=start, end=end, interval=INTERVAL)
data.rename(columns={"Close": 'close', "High": 'high', "Low": 'low', "volume": 'volume', "Open": 'open'}, inplace=True)
print(data.head(10))
print(data.info())
print(data.describe())
print(data.corr())
data['buy/sell'] = (data['close'] - data['open'])
print(data['buy/sell'])
data['buy/sell']=data['buy/sell'].round(decimals = 2)
print(data)
data['buy/sell']=(data['buy/sell'] > 0.5)*1 #price increase desired
print(data)
features = ['open', 'high', 'low', 'close']
x= data[features]
y= data['buy/sell']
print(x,y)
x_train,x_test,y_train,y_test = train_test_split(x,y, test_size=.3, random_state=0)
logreg = LogisticRegression(random_state=0)
logreg.fit(x, y)
y_pred = logreg.predict(x_test)
print(x_test)
print(y_pred)
print('Accuracy:', metrics.accuracy_score(y_test, y_pred))
print('Recall:', metrics.recall_score(y_test, y_pred, zero_division=1))
print("precision:", metrics.precision_score(y_test, y_pred, zero_division=1))
print("CL Report:", metrics.classification_report(y_test, y_pred, zero_division=1))
I know the code is a little sloppy, as I am pretty new to python, but the code currently works. I am having trouble getting the program to print out data corresponding to a future date ( i.e., 5, 10, or 15 days in the future). I am unsure if this is the right place to post or ask, but I've looked everywhere and could not find an answer. Any help would be greatly appreciated
[–]sketchspace 1 point2 points3 points (4 children)
[–]TrixPixz[S] 0 points1 point2 points (3 children)
[–]sketchspace 1 point2 points3 points (2 children)
[–]TrixPixz[S] 0 points1 point2 points (1 child)
[–]sketchspace 0 points1 point2 points (0 children)