At the base level I am trying to determine if two stocks are cointegrated. To that end I take the adjusted close data of two stocks and call coint on this data. However I am unsure if the coint test considers residuals (for stationarity) as the documentation may suggest or not. Can someone clarify this for me?
From docs:
coint_t: float
The t-statistic of unit-root test on residuals.
I have looked at various sources and tried multiple approaches. I am inclined to believe that the coint test within itself either checks for stationarity or uses stationary residuals as examples dont appear to have a step of passing stationary data. However alot of articles suggest using stationary data, though these are not specifically using coint so perhaps thats handled. I have put in a minimal example of self contained code below.
import yfinance as yf
from statsmodels.tsa.stattools import coint
data = yf.download(['MSFT', 'AAPL'], period='max')['Adj Close']
data = data.dropna()
print(coint(data['MSFT'], data['AAPL']))
import yfinance as yf
from statsmodels.tsa.stattools import coint
data = yf.download(['MSFT', 'AAPL'], period='max')['Adj Close']
data = data.dropna()
print(coint(data['MSFT'], data['AAPL']))
Output:
(-4.137743980432671, 0.0045239767434935236, array([-3.89757492, -3.33676305, -3.0448894 ]))
Some mini questions:
Would this correctly indicate correlation at 5% cutoff and is there any other steps needed?
What if I wanted to use returns?