Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Predicting future stock prices using machine learning

$
0
0

I'm new to this and trying to predict stock prices training a machine learning model(xgb) in python. I start with getting the stock prices and then calculating techninchal indicators to use as features. I then then split the data into a training and testing set, with the features(modeling_df) as X and close prices(closes) as Y.

My problem is that I'm not sure that the model is actually predicting the prices based on past prices, but that the model is rather predicting the price by looking at the features at that current time. I also want to make sure that it kind of uses a "rolling window", so that if there for example is 30 values, then value 11-20 should be based on 0-10 and 21-30 should be based on 0-20.

If anyone knows if the solution to this is different for neural networks, then it would also be greatly appreciated!

scaled_features = scaler.fit_transform(modeling_df)X = scaled_featuresY = closesx_train, x_test, y_train, y_test = train_test_split(X,Y,test_size=0.05,shuffle=False)

then i use:

final_model = xgb.XGBRegressor(**best_params)final_model.fit(x_train,y_train, )predictions = final_model.predict(x_test)

I then display it using matplotlib.

I've tried shifting the whole dataset by 10 (and other values), to try and predict 10 datapoints into the future, but I'm not sure how to verify that it is actually working.

This is my graph (dataset is not being shifted).Candlesticks + blue line = actual pricesPurple line = predicted prices

Graph:Graph


Viewing all articles
Browse latest Browse all 23131

Trending Articles