Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Adding granger_causality_test() #1148

Merged
merged 36 commits into from
Nov 3, 2023
Merged

Conversation

Magnus167
Copy link
Member

Added a function that runs a Granger causality test with the following parameters and dosctrings.

Run Granger Causality Test on a standardized quantamental dataframe.
Since the Graner Causality Test is a pairwise test, only two tickers can be specified.
Specify either `tickers` or `cids` & `xcats`. When specifying `cids` & `xcats`, the
user may input one `cid` and two `xcats`; or two `cids` and one `xcat` to yield two
tickers. The function forms the list of tickers from the `cids` and `xcats` such that
the order of the formed tickers is preserved. The order of the tickers is important
as the first ticker is the one that is tested to Granger cause the second ticker.
The function tests whether the first ticker Granger causes the second ticker.

:param <pd.DataFrame> df: A standardized quantamental dataframe.
:param <List[str]> tickers: A list of tickers to run the test on. A maximum of two
    tickers can be specified.
:param <Union[str, List[str]]> cids: One or two cids to run the test on. If two cids
    are specified, then only one xcat can be specified. If one cid is specified, then
    two xcats can be specified.
:param <Union[str, List[str]]> xcats: One or two xcats to run the test on. If two
    xcats are specified, then only one cid can be specified. If one xcat is specified,
    then two cids can be specified.
:param <Union[int, List[int]]> max_lag: If `max_lag` is an integer, then the function
    computes the test for all lags up to `max_lag`. If `max_lag` is a list of integers,
    then the function computes the test only for lags specified in the list.
:param <bool> add_constant: Whether to add a constant to the regression.
:param <str> freq: The frequency to downsample the data to. Must be one of "D", "W",
    "M", "Q", "A". Default is "M".
:param <str> agg: The aggregation method to use when downsampling the data. Must be
    one of "mean" (default), "median", "min", "max", "first" or "last".
:param <str> start: The start date of the data. Must be a valid ISO date. If not
    specified, the earliest date in `df` is used.
:param <str> end: The end date of the data. Must be a valid ISO date. If not
    specified, the latest date in `df` is used.
:param <str> metric: The metric to run the test on. Must be a column in `df`.
    Default is "value".

@Magnus167 Magnus167 requested review from rsueppel and a team as code owners October 26, 2023 16:01
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #1148 (40a7a27) into develop (b8df38a) will increase coverage by 0.46%.
Report is 1 commits behind head on develop.
The diff coverage is 100.00%.

❗ Current head 40a7a27 differs from pull request most recent head 1c9cec1. Consider uploading reports for the commit 1c9cec1 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1148      +/-   ##
===========================================
+ Coverage    78.57%   79.03%   +0.46%     
===========================================
  Files           61       62       +1     
  Lines         5059     5157      +98     
===========================================
+ Hits          3975     4076     +101     
+ Misses        1084     1081       -3     
Files Coverage Δ
macrosynergy/panel/__init__.py 100.00% <100.00%> (ø)
macrosynergy/panel/granger_causality_test.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Impacted file tree graph

@Magnus167 Magnus167 linked an issue Oct 26, 2023 that may be closed by this pull request
Copy link
Contributor

@rsueppel rsueppel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an experimental internal-only function at this stage. I added an issue for a proper package class but it does not have top priority right now.

sandresen1
sandresen1 previously approved these changes Nov 3, 2023
@Magnus167 Magnus167 merged commit ededc7f into develop Nov 3, 2023
4 checks passed
@Magnus167 Magnus167 deleted the feature/granger_test branch November 3, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add granger causality tests
3 participants