HomeCryptoFor Traders Who Don’t Code And Don’t Think They Can. Do This...

For Traders Who Don’t Code And Don’t Think They Can. Do This Right Now. It Can Change Your Life.


Getting the most out of Neural Prophet

It’s a lot easier than you think.

We all have our talents and shortcomings. I suck at musical instruments, foreign languages and calculus. I wasn’t so hot at C# and Python either until I learned about StackOverflow, which has a bunch of honest-to-goodness coding experts with a solution to every coding mess that I have ever managed to get myself into.

Just like it doesn’t take 3 years at Le Cordon Bleu to grill a great hamburger, it doesn’t take forever to learn enough C# and Python to get your computer to do something really useful to make you more self-reliant as a trader and investor.

To prove my point, and to convince you that you are overestimating the difficulty level, we are not only going to jump into the deep end of the pool, we are going cliff diving — time series forecasting with a feed-forward neural network.

We are going to use Google Colab to run our neural net. There are only a few minutes of prep work to set this up.

To create your Google Colab file and get started with Google Colab, go to Google Drive and create a Google Drive account if you do not have one. Now, click on the “New” button at the top left corner of your Google Drive page, then click on More ▷ Google Colaboratory.

Adding Colaboratory From Google Drive

Now, copy and paste each section of code below from here into a new cell in you Google Colab notebook. You can click on the little black circle to the left of the cell to run the code and make sure there are no errors.

I am not going anywhere near the jargon and complexities of what the code is actually doing behind the scenes.

First, install the Python libraries that do all the heavy lifting. You only need install them one time per session on Google Colab. After the first successful run you can comment out the installations by inserting a # , i.e. #!pip install neuralprophet

!pip install neuralprophet
!pip install --upgrade pandas-datareader
!pip install --upgrade pandas

Next import library sections that we need.

from neuralprophet import NeuralProphet
import pandas as pd
import pandas_datareader as pdr
import datetime
from dateutil.relativedelta import relativedelta
import matplotlib.pyplot as plt

Set up the variables. You can change the number of days of stock history to process, the stock ticker, and the number of days to forecast by changing the value in the cell.

end_date = datetime.date.today()
start_date = end_date-relativedelta(days=2500)
ticker = 'SPY'
forecast_days_ahead = 50

This section downloads the stock data. How easy is that!

df = pdr.DataReader(name=ticker, data_source='yahoo', start=start_date, end=end_date)

This section cleans up the data and shapes it the way the neural net wants it. Data prep is almost always the biggest pain in the ass part. Pandas Datareader makes this one easy.

df = df.reset_index()
df = pd.DataFrame(df, columns = [‘Date’,’Close’])
df.rename(columns = {‘Date’:’ds’}, inplace = True)
df.rename(columns = {‘Close’:’y’}, inplace = True)

This section is the feed-forward neural network. Shockingly simple to use. Because this is a stock forecast there is a an extra line of code to remove weekends from the forecast period.

# Fire up the Neural Prohet engine
m = NeuralProphet()
metrics = m.fit(df)
future = m.make_future_dataframe(df=df, periods=forecast_days_ahead)
df_no_weekends = future[future['ds'].dt.dayofweek < 5]
forecast = m.predict(df=df_no_weekends)

Lastly, we plot the result so we can admire all our hard work.

# Plot the forecasted stock prices
plt.plot(forecast['ds'],forecast['yhat1'])
plt.rcParams['figure.figsize'] = [16, 8]
plt.grid()
plt.title("Forecasted Stock Prices")
plt.xlabel("Future Dates")
plt.ylabel("Closing Price")

This is what it looks like it Google Colab.

In 15 minutes or so you have coded a result that would have taken a busload of PhDs hours and hours to produce a few scant years ago.

I acknowledge that this exercise barely skims the surface of developing any understanding of what’s involved in time series forecasting, or in how to get the most out of Neural Prophet. But that is not the point.

I cannot overestimate the sophistication and power of the data-mining and scientific libraries that are readily available to anybody with even a little Python programming ability. If you want to up your game, this is where you start.

References:

Google Caboratory

FreeCodeCamp Google CoLab in Your Google Drive

Python Tutorial W3 Schools

Neural Prophet

New to trading? Try crypto trading bots or copy trading



Source link

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments