<jupyter_start><jupyter_text>Real Time Stock Price Prediction   Stock  Market  Prediction,  the  aim  is  to predict  the  future value  of  the  financial stocks  of  a company. The recent trend in stock market prediction technologies  is  the  use  of  machine  learning  which makes predictions based on the values of current stock market  indices  by  training  on  their previous  values.<jupyter_code>#import the libraries




import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt 
import pandas_datareader.data as web 
from matplotlib import style
import statsmodels.api as sm
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.arima_model import ARIMA
from sklearn.metrics import mean_squared_error
from bokeh.plotting import figure, output_notebook, show 


df=web.DataReader('AAPL',data_source="yahoo",start="3-1-15",end="25-10-19")
df.reset_index()
df.isnull().sum()
df.info()
df.describe()
df.rename(columns={"Adj Close":"Adj_close"},inplace=True)
plt.figure(figsize=(16,8))
plt.subplot(1,2,1);
plt.plot(df.Open.values, color='red', label='Open')
plt.plot(df.Close.values, color='green', label='Close')
plt.plot(df.Low.values, color='blue', label='low')
plt.plot(df.High.values, color='black', label='high')
plt.plot(df.Adj_close.values,color='yellow',label="adj_close")
plt.title('stock price')
plt.xlabel('time [days]')
plt.ylabel('volume')
plt.legend(loc='best')
plt.subplot(1,2,2);
plt.plot(df.Volume.values, color='black', label='volume')
plt.title('stock volume')
plt.xlabel('time [days]')
plt.ylabel('volume')


sm.tsa.seasonal_decompose(df.Close.values,freq=30).plot()
result = sm.tsa.stattools.adfuller(df.Close)
plt.show()
#decomposition = seasonal_decompose(df.Close.values, freq=30)
df.shape
train = df[:900]
test = df[900:]

train_ar = train['Close'].values
test_ar = test['Close'].values

# https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/
history = [x for x in train_ar]
print(type(history))
predictions = list()
for t in range(len(test_ar)):
    model = ARIMA(history, order=(5,1,0))
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(yhat)
    obs = test_ar[t]
    history.append(obs)
error = mean_squared_error(test_ar, predictions)
print('Testing Mean Squared Error: %.3f' % error)

plt.figure(figsize=(12,5))
plt.plot(df['Close'], 'green', color='blue', label='Training Data')
plt.plot(test.index, predictions, color='green', marker='o', linestyle='dashed', 
         label='Predicted Price')
plt.plot(test.index, test['Close'], color='red', label='Actual Price')
plt.title('Close Prices Prediction')
plt.xlabel('Dates')
plt.ylabel('Prices')
plt.legend()
plt.figure(figsize=(12,7))
plt.plot(test.index, predictions, color='green', marker='.', linestyle='dashed', 
         label='Predicted Price')
plt.plot(test.index, test['Close'], color='red', label='Actual Price')
plt.title('Close Prices Prediction')
plt.xlabel('Dates')
plt.ylabel('Prices')
plt.legend()
plt.figure(figsize=(15, 7))
plt.plot(df.index,df["Close"])
output_notebook() 
  
# create figure 
p = figure(plot_width = 400, plot_height = 400)
p.line(df.index,df.Close, line_width = 2, color = "green")

show(p)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15664845173041894, 'fraction_numerical': 0.015482695810564663, 'mean_word_length': 5.9077568134171905, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '490139', 'license': 'MIT', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1137, 'n_words': 252, 'path': 'final stock price prediction.ipynb', 'repo_name': 'nimbalkar/stock-price-prediction', 'size': '3294'}