Cointegration test bad results

Course Name: Statistical Arbitrage Trading, Section No: 2, Unit No: 6, Unit type: Notebook

Hello, for this notebook I'm using the same code as you to replicate the test for the correlated series but not cointegrated and for me the result is:

Cointegration Test: Pair is cointegrated
Correlation: 0.9990875623592367

Why is this? This is my code:

https://i.imgur.com/kgEZLEz.png

https://i.imgur.com/Yw4gpjn.png

Imgur: The magic of the Internet



It shouldn't say both series are cointegrated as the spread is not stationary.



What's wrong? Any other way to conduct a cointegration test in a easy manner? Maybe performing the following ADFuller test to the spread and checking if the spread is stationary?

Hi, We will check this and get back to you. Mean while since this code is not used in Section 2 unit 6 of the course, can you please tell us which notebook you are referring to?



Thanks

Rushda

Hey Daniel,



This code will not generate the same series every time due to the random noise added to both X and Y. The np.random.normal() function generates random numbers from a normal distribution with the specified mean and standard deviation. Since it's based on random numbers, the noise added to X and Y will be different each time you run the code.



Because the series is not the same every time, even the result will not be the same. If you want to ensure reproducibility and generate the same series every time, you can set a random seed before generating the random noise. This will make the random number generation process deterministic.



Here's how you can do it:

# Set random seed for reproducibility
np.random.seed(42)

Hope this helps!

Thanks
Rushda

Hello Rushda,



After fixing the seed of the pseudo-random series now it says it's not stationary, you're right!



Thank you very much for the clarification.

Glad to hear that! If there's anything else I'd be happy to help :slight_smile: