Is there a solution for finding cointegrated pairs in an automated fashion without having to manually input trading symbols, and then perform trial and error testing with the Johansen model within the Python code?
There are thousands of stocks, I strongly believe creating/coding an automated scanner would be very beneficial for going about seeing which pairs are cointegrated or not.
Maybe a scanner based on exchange, sector, or even all Forex symbols.
Hello Joshua,
I would suggest that you download data for all SP500 stocks using a tool like this:
sp_assets = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0]
assets = sp_assets.Symbol.tolist()
And then created a nested loop with the Johansen test like:
for a in asset:
for b in asset:
df = pd.DataFrame({'x':a,'y':b})
coint_ johansen(df,0,1)
With this, you'll be able to generate the trace stats to identify cointegration.
Thank you so much! This is very helpful, would the same also apply to Forex?
You're welcome.
Yes, absolutely. This works like a charm: pd.read_html('https://www.instaforex.com/trading_symbols')