ProgrammingStock Market Data/Price Prediction Script - Python
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
https://gyazo.com/21fd330e78c30c521278bdaa54e82e93.png
Project Background Information This script was a project I worked on for my Python class during college. I have not yet gotten this script to work 100% correctly just yet. There are also some errors with the price prediction. It will accurately display the current days opening price; however, it will not accurately predict next day opening price as intended. The purpose of this script is to datascrape yahoo finance and other finance sources to output financial data for a given ticker that you give it. This data will include charts for open/close/volume/high/low points, graph the rolling mean / standard deviation. It will also display results from the Dickey-Fuller test and ARIMA models. *This tutorial will NOT show you how to install libraries or your python environment, but it will walk you through the code and thought process of the script. If you need help installing libraries or python work environment, there are tons of tutorials on YouTube. *Note: All data/graphs shown are using data from 'TSLA' ticker. This data is not up to date because I had retrieved it months ago. Script should work to receive new data - for most of the features. *Full script at bottom of post* What is the Dickey-Fuller test? In statistics, the Dickey-Fuller test tests the null hypothesis that a unit root is present in an autoregressive time series model. The alternative hypothesis is different depending on which version of the test is used, but is usually stationarity or trend-stationarity. The test is named after the statisticians David Dickey and Wayne Fuller, who developed it in 1979.[1] What are ARIMA models? ARIMA models provide another approach to time series forecasting. Exponential smoothing and ARIMA models are the two most widely used approaches to time series forecasting, and provide complementary approaches to the problem. While exponential smoothing models are based on a description of the trend and seasonality in the data, ARIMA models aim to describe the autocorrelations in the data. ARIMA models are used for machine learning. There are tons of different ways they can be utilized. For our case, they help with price prediction. Now For the Code Installing Libraries #import libraries
This section imports the many libraries related to data scraping / data visualization and allows us access to financial data to pull from. Allowing Ticker Input / Data Fetching / Price Display # Ticker Input / Pricing Display / Data Fetching
This section defines how a ticker is given to our script and what to do once it is given one. Cleaning / Sorting the Data # Data Cleaning / Sorting
This section defines where the data is split to determine which data is shown and which data is hidden. Stationary Test # Stationary Test
Call Stationary Test test_stationarity(series) This section defines our stationary test and displays a graph for output. Stationary Test Output Stationary Test w/ Adjusted Close Point # Get the difference of each Adj Close point
Call Stationary Test w/ Adjusted Close Point test_stationarity(ticker0_close_diff_1) Stationary Test w/ Adjusted Close Point Output Graph Graphing (Partial) Autocorrelation from statsmodels.graphics.tsaplots import plot_acf,plot_pacf
(Partial) Autocorrelation Graph Output AMIRA Models # Use this block to
AMIRA Output (with warnings) Create List for Predictions / data points # Create list of x train valuess
This model tests the mean squared and saves it. Output Image Check Model # Check to see if it reloaded
Next Day Price Predictions print("next day predicted value: ",model_predictions[-1]) Output Image Green Line Setup / Get Monthly Data / Green Line Indicator Definition Green Line
# Green Line
Get Monthly Data # Get Monthly Data
Green Line Indicator Definition # Green Line Indicator Definition
Call Green Line Calculation calculate_GreenLine(dfmonth) Errors I am getting / Help Wanted / Additional Information Additional Information This project was a project I worked on for my python class. It was made in Jupyter Notebook which is why the code format looks kind of odd. I can share the .ipynb file for anyone that may be interested in helping get this project where it is intended to be. Help Wanted I am needing help situating the warnings/errors you have seen in these images. I am also wanting to get the next day price prediction to work properly. It currently gets same day opening price, not next day as intended. I would also like to eventually add some sort of weighted calculation to give meaning to the data it receives/outputs. This way, it can provide a recommendation of good/bad investment or something of the sort. Any suggestions / Feedback for improvement is always welcome! Error Images Full Script #import libraries
Closing Remarks If you have made it this far, I'd like to thank you for your time and interest in this script. The stock market and programming have always been of interest to me. More tutorials / programming posts to come. Stay tuned. |
Last edited by SiDev ; edited 3 times in total
#2. Posted:
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
This project also slightly utilizes TensorFlow. I did not mention this in the post. TensorFlow deserves its own post dedicated to just that. It has tons of capabilities and I would recommend anyone to look into it if interested in AI/Machine Learning. |
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
Status: Offline
Joined: Dec 13, 20203Year Member
Posts: 287
Reputation Power: 567
Jupyter Notebook .ipynb file
.ipynb Download Link Virus Scan Virus Scan Image |
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: May 24, 20149Year Member
Posts: 1,097
Reputation Power: 2689
Motto: Live Your Best Life
Motto: Live Your Best Life
Status: Offline
Joined: May 24, 20149Year Member
Posts: 1,097
Reputation Power: 2689
Motto: Live Your Best Life
I know nothing about this but if you could get it to accurately predict or come close enough to make a very educated guess of next day numbers this would be very useful and game changer. I would expect this to be hard due to so many variables so I am to say the least extremely impressed! |
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,740
Reputation Power: 448
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,740
Reputation Power: 448
Cool project!
For getting around errors, my advice is to read the error messages multiple times and really think about what you want your code to do. It says a variable is not defined, meaning you did not create the variable yet, or it is not available in the scope you think it is. Split is a method available to strings. It turns a string into an array (list) of smaller strings. If your variable is not a string but instead something like a DataFrame, number, or list, that method is unavailable because Python does not know how to split something like a DataFrame. Also, if you haven't already, definitely check out ChatGPT. It is great for getting things explained in laymen's terms. |
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Jun 15, 20149Year Member
Posts: 1,013
Reputation Power: 20444
Motto: There's magic on the other side of fear.
Motto: There's magic on the other side of fear.
Status: Offline
Joined: Jun 15, 20149Year Member
Posts: 1,013
Reputation Power: 20444
Motto: There's magic on the other side of fear.
not even gonna read all of it but looks like alot |
- 0useful
- 0not useful
Users browsing this topic: None