Closed viniciusparede closed 5 months ago
@viniciusparede - Thoughts on starting smaller & scaling out? Maybe the initial implementation can be a Report that takes two tickers are the input & runs a cointegrated pair test on that pair?
Thank you for the comment, @joshuabuildsthings ! I believe this interaction with more experienced developers is crucial before starting to implement a potential new feature.
I agree with your idea. Do you think it's valid to start the development?
I started developing a feature
Preview:
For the initial tests, I implemented the idea described by @joshuabuildsthings. After the model runs, the result will graphically show the spread for a specific pair, half-life time (stop by time), and the proportional quantity of shares to execute the operation.
I still have several adjustments to make, but I believe that soon this feature can contribute to the project and future user analyses.
@viniciusparede - That looks awesome! Congratulations.
@viniciusparede - That looks awesome! Congratulations.
Thanks bro!
What's the problem of not having this feature?
The residual cointegration model of a linear regression serves as the foundation for pair trading operations (Long & Short). The concept is to display a list of pairs whose residuals are both cointegrated and stationary within a specific period of the sample space. This enables investors to identify assets that are likely suitable for buying or selling operations.
For example, let's suppose the user wants to perform a comparative analysis involving a selected asset, such as NVDA. This company belongs to the S&P500. Therefore, the user would like to verify if there are any cointegrated pairs in that index and determine on which side (Long Spread or Short Spread) they lie. Let's say that NVDA predominantly exhibits a Short Spread pattern during the sample period. This suggests a potential buying pressure for this asset by hedge funds, which can serve as additional information when making buying or selling decisions.
Describe the solution you would like
ca_controller.py
: Modify the menu to include the coint model below the tsne. It will display a list of cointegrated assets from the S&P500, and if the selected asset is from outside the index, it will attempt to identify the companies that are cointegrated with it. The user will have the option to input the sample period and the significance level of the test. By default, we will use a sample period of 180 days and a statistical significance level of 0.01.Create the following files:
coint_residual_model.py
: File responsible for finding cointegrated stocks, calculating residual stationarity, and half-life.coint_residual_view.py
: Display the graph of the selected pair spreads and the half-life.Input:
Output:
Additional information
START ├── Load target asset │ ├── Was the target asset loaded successfully? │ │ ├── Yes │ │ │ ├── Find cointegrated stocks from the S&P500 │ │ │ │ ├── Are there cointegrated stocks from the S&P500? │ │ │ │ │ ├── Yes │ │ │ │ │ │ ├── Identify pairs of assets that are both cointegrated, have stationary residuals, and positive beta │ │ │ │ │ │ │ ├── Are there pairs of assets with these characteristics? │ │ │ │ │ │ │ │ ├── Yes │ │ │ │ │ │ │ │ │ ├── Proceed with the analysis of these pairs of assets │ │ │ │ │ │ │ │ ├── No │ │ │ │ │ │ │ │ │ ├── There are no pairs of assets with these characteristics │ │ │ │ ├── No │ │ │ │ │ ├── There are no cointegrated stocks from the S&P500 │ ├── No │ │ ├── Failed to load the target asset ├── END
In this decision tree, the first point is to load the target asset. Then, it checks if the target asset was loaded successfully. If it was, the process proceeds to find cointegrated stocks from the S&P500. Next, it checks if there are any cointegrated stocks from the S&P500. If there are, the next step is to identify pairs of assets that are both cointegrated, have stationary residuals, and positive beta. It then checks if there are pairs of assets with these characteristics. If there are, the process proceeds with the analysis of these pairs of assets. Otherwise, there are no pairs of assets with these characteristics. If the target asset fails to load, there was a failure in loading the target asset.
References Performance Analysis of Statistical Arbitrage Portfolio Test for no-cointegration Calculate the autocorrelation function Augmented Dickey-Fuller unit root test Linear Regression