Dear Friends
I attempted to examine the impact of an event on stock return using python library ":eventstudy". But I got the error. Here I shared the python code.
To view the code in colab.research use the following link
https://colab.research.google.com/drive/1BgRWMDSq5wq7dUB5xBQAkqlKZFi0L58B?usp=sharing
=========
pip install eventstudy
pip install yfinance
==========================
import eventstudy as es
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import datetime
import yfinance as yf
ITC = yf.download('ITC.NS', '2020-01-01', '2020-12-31')['Close']
BSE = yf.download('^BSESN', '2020-01-01', '2020-12-31')['Close']
# to calcualte the return fo teh ITC and BSE sensex
ITC = ITC.pct_change()
BSE = BSE.pct_change()
ITC= pd.DataFrame(ITC)
BSE = pd.DataFrame(BSE)
BSE =BSE.dropna(axis=0)
ITC =ITC.dropna(axis=0)
# To have equal counts in ITC & BSE
df = ITC['Close'],BSE['Close']
df1 = pd.DataFrame(df)
df2 = df1.T
df2.columns = ['ITC','BSE']
df3 = df2.dropna()
print (df3.count())
# to save in csv file
df3.to_csv('df3.csv',index =True, sep=",")
# to get back from csv
Ret =pd.read_csv ('df3.csv')
print (Ret.info()) # date is an object but it should be datetimme **********
print (Ret.head())
from eventstudy import Single, models
event = Single (
models.market_model,
{'security_returns':df3['ITC'], 'market_returns': df3['BSE'], '*': True,
'event_date': np.datetime64('2020-05-05'),
'event_window':[-2,+10]}
)
result= event.plot()
event.results(decimals =[3,5,3,5,2,2])
# what ever the date I change, it gives the same result for 216th row to 236th row
# if datetime as index for my data then i got the error as foollows
#TypeError: Addition/subtraction of integers and integer arrays with DatetimeArray is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`