State bank of india stock price analysis and forcasting of 2023

How to collect sbi historical price?

!pip install yfinance

How to install sbi data from yahoo in python?

import yfinance as yf
import numpy as np
import os
import random
import torch
import torch.optim as optim
import torch.nn as nn
from torch.utils.data import (Dataset, TensorDataset,
 DataLoader, Subset)
from collections import OrderedDict
from sklearn.metrics import mean_squared_error
import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose
df = yf.download('SBIN.NS',
 start='2010-01-01',
 end='2021-09-08',
 adjusted=True,
 progress=False)
df.tail()
df.describe()
df = df.loc[:, ['Adj Close']]
df.rename(columns={'Adj Close''price'}, inplace=True)
df = df.resample('M').last()
WINDOW_SIZE = 12
df['rolling_mean'] = df.price.rolling(window=WINDOW_SIZE).mean()
df['rolling_std'] = df.price.rolling(window=WINDOW_SIZE).std()
df.plot(title='State Bank Stock Price')
<matplotlib.axes._subplots.AxesSubplot at 0x7f92720ec250>

How to plot sbi historical price?

State Bank Stock Price, rolling mean and std

How to plot sbi Multiplicative Decomposition ?

decomposition_results = seasonal_decompose(df.price,
 model='multiplicative')
decomposition_results.plot() \
 .suptitle('Multiplicative Decomposition',
 fontsize=18);
sbi Multiplicative Decomposition

How to forcast sbi stock price in 2022?

import pandas as pd
import seaborn as sns
from fbprophet import Prophet
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)
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)
sbi stock price in 2022

How to forcast sbi seasonal stock price in python?

model_prophet.plot_components(df_pred)

sbi seasonal price
selected_columns = ['ds''yhat_lower''yhat_upper''yhat']
df_pred = df_pred.loc[:, selected_columns].reset_index(drop=True)
df_test = df_test.merge(df_pred, on=['ds'], how='left')
df_test.ds = pd.to_datetime(df_test.ds)
df_test.set_index('ds', inplace=True)
import matplotlib.pyplot as plt
fig, ax = plt.subplots(11)
ax = sns.lineplot(data=df_test[['y''yhat_lower''yhat_upper','yhat']])
ax.fill_between(df_test.index,
 df_test.yhat_lower,
 df_test.yhat_upper,
 alpha=0.3)
ax.set(title='Stock Price - actual vs. predicted',
 xlabel='Date',
 ylabel='Stock Price ')

How to predict sbi stock price in python?

sbi Stock Price - actual vs. predicted
import pandas as pd
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
from statsmodels.tsa.stattools import adfuller, kpss
def adf_test(x):
 indices = ['Test Statistic''p-value',
 '# of Lags Used''# of Observations Used']
 adf_test = adfuller(x, autolag='AIC')
 results = pd.Series(adf_test[0:4], index=indices)
 for key, value in adf_test[4].items():
  results[f'Critical Value ({key})'] = value
 return results

How to find sbi adf test in python?

adf_test(df.y)
Test Statistic -2.152640 p-value 0.223881 # of Lags Used 17.000000 # of Observations Used 2862.000000 Critical Value (1%) -3.432637 Critical Value (5%) -2.862550 Critical Value (10%) -2.567308 dtype: float64

How to forcast sbi stock price kpss test in python?

def kpss_test(xh0_type='c'):
 indices = ['Test Statistic''p-value''# of Lags']
 kpss_test = kpss(x, regression=h0_type)
 results = pd.Series(kpss_test[0:3], index=indices)
 for key, value in kpss_test[3].items():
  results[f'Critical Value ({key})'] = value
 return results
kpss_test(df.y)
Test Statistic 3.723934 p-value 0.010000 # of Lags 28.000000 Critical Value (10%) 0.347000 Critical Value (5%) 0.463000 Critical Value (2.5%) 0.574000 Critical Value (1%) 0.739000 dtype: float64
N_LAGS = 40
SIGNIFICANCE_LEVEL = 0.05
fig, ax = plt.subplots(21, figsize=(1612), sharex=True)
plot_acf(df.y, ax=ax[0], lags=N_LAGS,
 alpha=SIGNIFICANCE_LEVEL)
plot_pacf(df.y, ax=ax[1], lags=N_LAGS,
 alpha=SIGNIFICANCE_LEVEL)

How to plot sbi stock price in python?

sbi autocorrelation  and partial autocorrelation


New updates of sbi analysis

Post a Comment

0 Comments