-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error #2
Comments
Hello, I want to say thank you so much for spend your time and patience in interview this file, and I believe that you did a fantistic job in correcting code. You provide a great idea in scaling raw data, and correct my error in present variance as volitatility. Your methology is not only suitable for the current code, but also can be used to correct rest of volitatility prediction files. Thank you again for your amazing work. |
Bro do you mind providing me a Read.txt or guide to run the project. |
Hello,
Thanks for putting the code to the excellent book up in Github. I notice a very small error in the code - I don't know if it is local of whether the error is common to all of the AR model codes but I'm considering the file: Volatility_prediction_GARCH.py:
Do let me know if you disagree with my reasoning regarding the square root!
plt.plot(np.sqrt(forecast.variance.iloc[-len(split_date):]), label='Volatility Prediction-GARCH')
where one should take the square root of the arch_model forecat since this model actually forecasts variance, not volatility in order to plot it against the realised volatility.
My revised code:
def load_raw_data(ticker, start_date, end_date):
price = yf.download(ticker, start_date, end_date)['Adj Close']
ret = price.pct_change()[1:] # take the scaling out here
ret.dropna(inplace=True)
return ret
def model_train(ret):
global garch, q, best_param
bic_garch = []
for p in range(1, 5):
for q in range(1, 5):
garch = arch_model(ret, mean='zero', vol='GARCH', p=p, o=0, q=q, rescale=True).fit(disp='off') # add scaling here by adding rescale=True
bic_garch.append(garch.bic)
if garch.bic == np.min(bic_garch):
best_param = p, q
garch = arch_model(ret, mean='zero', vol='GARCH', p=best_param[0], o=0, q=best_param[1], rescale=True).fit(disp='off')
scale = garch.scale # take scale value here
print(garch.summary())
The text was updated successfully, but these errors were encountered: