AssemblyAI
AssemblyAI

@AssemblyAI

7 Tweets 7 reads Oct 26, 2022
Learn how to predict stock prices with Python, the yfinance package, and a cool forecasting algorithm.
Let's look at the code step by step๐Ÿ‘‡๐Ÿงต
1. As the forecasting algorithm we use Prophet:
facebook.github.io
If you use Google Colab, it is already installed. Otherwise, you can install it with pip.
To download stock data, we use yfinance. This is not preinstalled so let's install it:
2. As training data we need stock prices from the past.
Select a stock you want to predict and a range from a date in the past until today.
Then use yfinance to download the data.
3. To train the algorithm we only need this data:
x = Date
y = Closing stock price from this date
(Note: We need to rename the columns so that it works with Prophet)
Then fit the data to Prophet, select a future period to predict, and call m.predict():
4. Now we have the forecast!
We can plot it with m.plot()
You can change n_years above and play around with different periods to predict.
5. We can also plot the trend, and the weekly and yearly forecast:
6. And that's it!
If you enjoyed this thread, leave us a like and retweet the first tweet, and consider following us @AssemblyAI for more ML content๐Ÿ˜Š

Loading suggestions...