<jupyter_start><jupyter_text>Importing data from yahoo Finance<jupyter_code>Gold = yf.Ticker("GC=F")
Gold_info=Gold.info
Gold_data = Gold.history(period="5Y")
Gold_data.reset_index(inplace=True)
Gold_data.tail()
Gold_data.drop(['Dividends','Stock Splits'],inplace = True, axis =1)<jupyter_output><empty_output><jupyter_text>Gold Data info of 5 years<jupyter_code>Gold_data.info()
Gold_data.describe()<jupyter_output><empty_output><jupyter_text>How Gold Data Varied in 5 years<jupyter_code>Gold_data['Close'].plot(figsize=(12,5))
Gold_data.dropna()
best_order = auto_arima(Gold_data['Close'],trace = True)
Close_gold_data = pd.DataFrame(Gold_data['Close'])
Close_gold_data<jupyter_output><empty_output><jupyter_text>Spliting Training and Testing dataset in the model<jupyter_code>Train, Test = Close_gold_data[0:int(len(Close_gold_data)*0.80)], Close_gold_data[int(len(Close_gold_data)*0.80):]
Train
Test<jupyter_output><empty_output><jupyter_text>Preparation of Model<jupyter_code>model = ARIMA(Train, order=(0,1,0))
model = model.fit()
model.summary()<jupyter_output>/opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages/statsmodels/tsa/arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)<jupyter_text>Prediction via Data Visualization<jupyter_code>start = len(Train)
end = len(Train)+len(Test)-1
prediction = model.predict(start = start, end = end, typ='levels').rename("ARIMA Predictions")
prediction.plot(legend = True, figsize=(15,7))
Test['Close'].plot(legend = True)
rmse = sqrt(mean_squared_error(Test, prediction))
rmse
average = Test.mean()
Percentage_error = (rmse/average)*100
print('Error is', round(Percentage_error[0]), '%')
start = 1
end = 1245
prediction = model.predict(start = start, end = end, typ='levels').rename("ARIMA Predictions")
prediction.plot(legend = True, figsize=(15,7))
Test['Close'].plot(legend = True)
start = 1
end = 1245
prediction = model.predict(start = start, end = end, typ='levels')
prediction.plot(legend = True, color = 'red', linestyle = 'dashed',marker = 'o', label = 'Predicted Price', figsize=(15,7))
Test['Close'].plot(legend = True, color = 'blue', label = 'Tested Data')
Train['Close'].plot(legend = True, color = 'orange', label = 'Trained Data')<jupyter_output><empty_output><jupyter_text>Price Predication for next 30 days<jupyter_code>start = 1
end = 1275
prediction = model.predict(start = start, end = end, typ='levels')
prediction.plot(legend = True, color = 'red', linestyle = 'dashed',marker = 'o', label = 'Predicted Price', figsize=(15,7))
Test['Close'].plot(legend = True, color = 'blue', label = 'Tested Data')
Train['Close'].plot(legend = True, color = 'orange', label = 'Trained Data')<jupyter_output><empty_output><jupyter_text>If we see the graph there is a fall in graph from data index 1000 to 1200 and the reason behind it is COVID 19 impact on world economy. We can see from here that the start date is september 2017 when covid 19 impact was on its peak thus we can also analyse a data too<jupyter_code>Gold_data[1000:1200]<jupyter_output><empty_output><jupyter_text>Importing silver data from yahoo finance and plotting its prediction<jupyter_code>Silver = yf.Ticker("SI=F")
Silver_info=Silver.info
Silver_data = Silver.history(period="5Y")
Silver_data.reset_index(inplace=True)
Silver_data.tail()
Silver_data.drop(['Dividends','Stock Splits'],inplace = True, axis =1)
Silver_data['Close'].plot(figsize=(12,5))
Silver_data.dropna()
best_order = auto_arima(Silver_data['Close'],trace = True)
Close_silver_data = pd.DataFrame(Silver_data['Close'])
Train1, Test1 = Close_silver_data[0:int(len(Close_silver_data)*0.80)], Close_silver_data[int(len(Close_silver_data)*0.80):]
model = ARIMA(Train1, order=(3,1,2))
model = model.fit()
model.summary()
start = 1
end = 1245
prediction = model.predict(start = start, end = end, typ='levels')
prediction.plot(legend = True, color = 'red', linestyle = 'dashed',marker = 'o', label = 'Predicted Price', figsize=(15,7))
Test1['Close'].plot(legend = True, color = 'blue', label = 'Tested Data')
Train1['Close'].plot(legend = True, color = 'orange', label = 'Trained Data')
start = len(Train)
end = len(Train)+len(Test)-1
prediction = model.predict(start = start, end = end, typ='levels').rename("ARIMA Predictions")
prediction.plot(legend = True, figsize=(15,7))
Test1['Close'].plot(legend = True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14265982636148383, 'fraction_numerical': 0.023283346487766376, 'mean_word_length': 7.007898894154819, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '62061', 'license': 'Apache-2.0', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1728, 'n_words': 383, 'path': 'Gold & Silver Price Prediction using Python(ARIMA).ipynb', 'repo_name': 'Alexiso03/Projects', 'size': '5068'}