Two-Sample t-Test
Calculate a two-sample t-test for a difference in mean column between every unordered pair of tickers in the Toolkit instance.
Also known as: independent samples t-test, Welch’s t-test (default), Student’s t-test (equal_variance=True).
For more information about the method, see hypothesis_testing_model.get_two_sample_t_test.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Two-Sample t-Test for you. Just ask in plain English.
Calculate the Two-Sample t-Test in Python
The Two-Sample t-Test is available in the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_two_sample_t_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.econometrics.get_two_sample_t_test(period="weekly")
Which returns:
| Ticker A | Ticker B | T-Statistic | Degrees of Freedom | P-Value | Mean A | Mean B |
|---|---|---|---|---|---|---|
| AAPL | MSFT | 0.2318 | 306.6549 | 0.8168 | 0.0047 | 0.0036 |
Parameters
get_two_sample_t_test accepts the following parameters:
- period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- column (str, optional): The historical data column to compare. Defaults to “Return”.
- equal_variance (bool, optional): Whether to assume the two samples share a common variance (Student’s pooled t-test) instead of Welch’s (unequal-variance) t-test. Defaults to False.
- include_benchmark (bool, optional): Whether to include “Benchmark” among the tickers paired up. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Related Hypothesis Tests
The Econometrics module page introduces the module, and the sidebar lists all of its functions.