Reliance stock price forcasting 2022

How to get reliance data from yahoo finance in Python?

df= yf.download('RELIANCE.NS',start='2012-01-01',end='2021-09-04',
progress =False)

What is alternative sources to get financial data?

There are number of alternative sources like Quandal,intrinio,google others.

df.reset_index(drop=False, inplace=True)
df.rename(columns={'Date''ds''Adj Close''y'}, inplace=True)
df=DataFrame(df)
df
indexdsOpenHighLowCloseyVolume
002012-01-02345.128540351.542725340.348846349.957764323.0367748679938
112012-01-03352.780975360.037201351.839905358.922760331.3121039455771
222012-01-04360.284851362.043182353.325836354.712677327.4259348557084
332012-01-05354.143066359.071350343.791199346.465851319.81347713364666
442012-01-06345.252350358.600830345.054230355.406097328.0659489495456
...........................
237723772021-08-302250.0000002275.8500982236.8000492270.2500002270.2500006473487
237823782021-08-312276.8999022283.7500002242.2500002258.1499022258.14990212223037
237923792021-09-012273.0000002292.8999022263.0000002267.1000982267.1000985143640
238023802021-09-022255.0000002307.8000492255.0000002294.3999022294.3999024595048
238123812021-09-032310.0000002395.0000002302.5000002388.5000002388.50000014151629

2382 rows × 8 columns


train_indices = df.ds.apply(lambda x: x.year) < 2021
df_train = df.loc[train_indices].dropna()
df_test = df.loc[~train_indices].reset_index(drop=True)
model_prophet = Prophet(seasonality_mode='additive')
model_prophet.add_seasonality(name='monthly', period=30.5,
 fourier_order=5)

How to plot close price of 2022 reliance?

model_prophet.fit(df_train)
df_future = model_prophet.make_future_dataframe(periods=365)
df_pred = model_prophet.predict(df_future)
model_prophet.plot(df_pred)
reliance stock price 2022
model_prophet.plot_components(df_pred)
reliance monthly, weekly stock price
df_yah= yf.download('RELIANCE.NS',start='2012-01-01',end='2021-09-04',
progress =False)
import pandas as pd
import numpy as np
from pandas import Series, DataFrame
data=DataFrame(df_yah)
data

OpenHighLowCloseAdj CloseVolume
Date
2012-01-02345.128540351.542725340.348846349.957764323.0367748679938
2012-01-03352.780975360.037201351.839905358.922760331.3121039455771
2012-01-04360.284851362.043182353.325836354.712677327.4259348557084
2012-01-05354.143066359.071350343.791199346.465851319.81347713364666
2012-01-06345.252350358.600830345.054230355.406097328.0659489495456
.....................
2021-08-302250.0000002275.8500982236.8000492270.2500002270.2500006473487
2021-08-312276.8999022283.7500002242.2500002258.1499022258.14990212223037
2021-09-012273.0000002292.8999022263.0000002267.1000982267.1000985143640
2021-09-022255.0000002307.8000492255.0000002294.3999022294.3999024595048
2021-09-032310.0000002395.0000002302.5000002388.5000002388.50000014151629

2382 rows × 6 columns

DataFrame(data, columns=['Close''Volume'])

CloseVolume
Date
2012-01-02349.9577648679938
2012-01-03358.9227609455771
2012-01-04354.7126778557084
2012-01-05346.46585113364666
2012-01-06355.4060979495456
.........
2021-08-302270.2500006473487
2021-08-312258.14990212223037
2021-09-012267.1000985143640
2021-09-022294.3999024595048
2021-09-032388.50000014151629

2382 rows × 2 columns

frame2=DataFrame(data,columns=['Close'])
frame2

Close
Date
2012-01-02349.957764
2012-01-03358.922760
2012-01-04354.712677
2012-01-05346.465851
2012-01-06355.406097
......
2021-08-302270.250000
2021-08-312258.149902
2021-09-012267.100098
2021-09-022294.399902
2021-09-032388.500000

2382 rows × 1 columns

import cufflinks as cf
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
goog = data.resample('M') \
 .last() \
 .rename(columns={'Adj Close''adj_close'}) \
 .adj_close
goog  # convert daily into monthly goog(RIL)
Date 2012-01-31 373.580566 2012-02-29 375.249329 2012-03-31 343.176544 2012-04-30 340.661957 2012-05-31 326.532379 ... 2021-05-31 2153.372803 2021-06-30 2110.649902 2021-07-31 2035.300049 2021-08-31 2258.149902 2021-09-30 2388.500000 Freq: M, Name: adj_close, Length: 117, dtype: float64
train_indices = goog.index.year < 2021
goog_train = goog[train_indices]
goog_test = goog[~train_indices]
test_length = len(goog_test)
goog.plot(title="Relian's Stock Price");

How to plot daily stock return?

reliance daily stock price
ses_1 = SimpleExpSmoothing(goog_train).fit(smoothing_level=0.2)
ses_forecast_1 = ses_1.forecast(test_length)
ses_2 = SimpleExpSmoothing(goog_train).fit(smoothing_level=0.5)
ses_forecast_2 = ses_2.forecast(test_length)
ses_3 = SimpleExpSmoothing(goog_train).fit()
alpha = ses_3.model.params['smoothing_level']
ses_forecast_3 = ses_3.forecast(test_length)

goog.plot(color="g",
 title='Simple Exponential Smoothing',
 label='Actual',
 legend=True)
ses_forecast_1.plot(color="r", legend=True,
 label=r'$\alpha=0.2$')
ses_1.fittedvalues.plot(color="r")
ses_forecast_2.plot(color="k", legend=True,
 label=r'$\alpha=0.5$')
ses_2.fittedvalues.plot(color="k")
ses_forecast_3.plot(color="b", legend=True,
 label=r'$\alpha={0:.4f}$'.format(alpha))
ses_3.fittedvalues.plot(color="b")

How to plot simple exponential smoothing daily stock return?

<matplotlib.axes._subplots.AxesSubplot at 0x7f9fc58b0150>
reliance simple exponential smoothing price

Fit three variants of Holt's smoothing model and create forecasts:

Holt's model with linear trend

hs_1 = Holt(goog_train).fit()
hs_forecast_1 = hs_1.forecast(test_length)
hs_2 = Holt(goog_train, exponential=True).fit()  # Holt's model with exponential trend
hs_forecast_2 = hs_2.forecast(test_length)
hs_3 = Holt(goog_train, exponential=False,      # Holt's model with exponential trend and damping
 damped=True).fit(damping_slope=0.99)
hs_forecast_3 = hs_3.forecast(test_length)
goog.plot(color="g",
 title="Holt's Smoothing models",
 label='Actual',
 legend=True)
hs_1.fittedvalues.plot(color="r")
hs_forecast_1.plot(color="r", legend=True,
 label='Linear trend')
hs_2.fittedvalues.plot(color="k")
hs_forecast_2.plot(color="k", legend=True,
 label='Exponential trend')
hs_3.fittedvalues.plot(color="b")
hs_forecast_3.plot(color="b", legend=True,
 label='Exponential trend (damped)')

how to plot reliance holt's smoothing model?

<matplotlib.axes._subplots.AxesSubplot at 0x7f9fc6231dd0>














Post a Comment

0 Comments