tidyfinance 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ name: Test Python Package
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ permissions: read-all
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ${{ matrix.os }}
14
+
15
+ name: ${{ matrix.os }} (Python ${{ matrix.python-version }})
16
+
17
+ strategy:
18
+ matrix:
19
+ os: [ubuntu-latest, macos-latest, windows-latest]
20
+ python-version: ['3.10', '3.11']
21
+
22
+ steps:
23
+ - name: Check out the repository
24
+ uses: actions/checkout@v3
25
+
26
+ - name: Install uv and set the python version
27
+ uses: astral-sh/setup-uv@v4
28
+ with:
29
+ python-version: ${{ matrix.python-version }}
30
+
31
+ - name: Sync dependencies
32
+ run: uv sync --all-extras --dev
33
+
34
+ - name: Run tests
35
+ run: uv run pytest tests
@@ -0,0 +1,7 @@
1
+ tests/__pycache__/
2
+ tidyfinance/__pycache__/
3
+ .pytest_cache/
4
+ .env
5
+ config.yaml
6
+ .ruff_cache
7
+ .venv
@@ -0,0 +1 @@
1
+ 3.10
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0 (development version)
4
+
5
+ - Initial PyPI release.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Christoph Scheuch, Christoph Frey, Stefan Voigt, and Patrick Weiss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: tidyfinance
3
+ Version: 0.1.1
4
+ Summary: Tidy Finance Helper Functions
5
+ Project-URL: Repository, https://github.com/tidy-finance/py-tidyfinance
6
+ Project-URL: Issues, https://github.com/tidy-finance/py-tidyfinance/issues
7
+ Project-URL: Changelog, https://github.com/tidy-finance/py-tidyfinance/blob/master/CHANGELOG.md
8
+ Author-email: Christoph Scheuch <christoph@tidy-intelligence.com>, Christoph Frey <christoph.frey@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: dotenv>=0.9.9
13
+ Requires-Dist: lxml>=5.3.1
14
+ Requires-Dist: numpy>=1.26.0
15
+ Requires-Dist: pandas-datareader>=0.10.0
16
+ Requires-Dist: pandas>=2.2.0
17
+ Requires-Dist: psycopg2-binary>=2.9.9
18
+ Requires-Dist: pyarrow>=19.0.1
19
+ Requires-Dist: pyyaml>=6.0.2
20
+ Requires-Dist: requests>=2.31.0
21
+ Requires-Dist: sqlalchemy>=2.0.21
22
+ Requires-Dist: statsmodels>=0.14.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # tidyfinance
26
+
27
+ ![PyPI](https://img.shields.io/pypi/v/tidyfinance?label=pypi%20package)
28
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/tidyfinance)
29
+ [![python-package.yml](https://github.com/tidy-finance/py-tidyfinance/actions/workflows/python-package.yml/badge.svg)](https://github.com/tidy-finance/py-tidyfinance/actions/workflows/python-package.yml)
30
+ <!-- [![codecov.yml](https://codecov.io/gh/tidy-finance/py-tidyfinance/graph/badge.svg)](https://app.codecov.io/gh/tidy-finance/py-tidyfinance) -->
31
+ [![License:
32
+ MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
33
+
34
+ Helper functions for empirical research in financial economics, addressing a variety of topics covered in [Scheuch, Frey, Voigt, and Weiss (2024)](https://doi.org/10.1201/9781032684307). The package is designed to provide shortcuts for issues extensively discussed in the book, facilitating easier application of its concepts. For more information and resources related to the book, visit [tidy-finance.org/python](https://tidy-finance.org/python).
35
+
36
+ ## Installation
37
+
38
+ You can install the release version from [PyPI](https://pypi.org/project/tidyfinance/):
39
+
40
+ ```
41
+ pip install tidyfinance
42
+ ```
43
+
44
+ You can install the development version from GitHub:
45
+
46
+ ```
47
+ pip install "git+https://github.com/tidy-finance/py-tidyfinance"
48
+ ```
49
+
50
+ ## Download Open Source Data
51
+
52
+ The main functionality of the `tidyfinance` package centers around data download. You can download most of the data that we used in Tidy Finance with R using the `download_data()` function or its children.
53
+
54
+ ```python
55
+ import tidyfinance as tf
56
+ ```
57
+
58
+ The function always requires a `domain` argument and depending on the domain typically also a `dataset`. For instance, to download monthly Fama-French factors, you have to provide the dataset name according to `pdr.famafrench.get_available_datasets()`:
59
+
60
+ ```python
61
+ tf.download_data(
62
+ domain="factors_ff",
63
+ dataset="F-F_Research_Data_5_Factors_2x3_daily",
64
+ start_date="2000-01-01",
65
+ end_date="2020-12-31"
66
+ )
67
+ ```
68
+
69
+ For q factors, you provide the relevant file name:
70
+
71
+ ```python
72
+ tf.download_data(
73
+ domain="factors_q",
74
+ dataset="q5_factors_monthly",
75
+ start_date="2000-01-01",
76
+ end_date="2020-12-31"
77
+ )
78
+ ```
79
+
80
+ To download the Welch and Goyal (2008) macroeconomic predictors for monthly, quarterly, or annual frequency:
81
+
82
+ ```python
83
+ tf.download_data(
84
+ domain="macro_predictors",
85
+ dataset="monthly",
86
+ start_date="2000-01-01",
87
+ end_date="2020-12-31"
88
+ )
89
+ ```
90
+
91
+ To download data from Open Source Asset Pricing (OSAP):
92
+
93
+ ```python
94
+ tf.download_data(
95
+ domain="osap",
96
+ start_date="2020-01-01",
97
+ end_date="2020-12-31"
98
+ )
99
+ ```
100
+
101
+ To download multiple series from the Federal Reserve Economic Data (FRED):
102
+
103
+ ```python
104
+ tf.download_data(
105
+ domain="fred",
106
+ series=["GDP", "CPIAUCNS"],
107
+ start_date="2020-01-01",
108
+ end_date="2020-12-31"
109
+ )
110
+ ```
111
+
112
+ To download stock prices from Yahoo Finance:
113
+
114
+ ```python
115
+ tf.download_data(
116
+ domain="stock_prices",
117
+ symbols=["AAPL", "MSFT"],
118
+ start_date="2020-01-01",
119
+ end_date="2020-12-31"
120
+ )
121
+ ```
122
+
123
+ To download index constituents from selected ETF holdings:
124
+
125
+ ```python
126
+ tf.download_data(
127
+ domain="constituents",
128
+ index="S&P 500"
129
+ )
130
+ ```
131
+
132
+ ## Download WRDS Data
133
+
134
+ To access data from the [Wharton Research Data Services (WRDS)](https://wrds-www.wharton.upenn.edu/), you need to set your credentials first:
135
+
136
+ ```python
137
+ tf.set_wrds_credentials()
138
+ ```
139
+
140
+ To download monthly CRSP data:
141
+
142
+ ```python
143
+ tf.download_data(
144
+ domain="wrds",
145
+ dataset="crsp_monthly",
146
+ start_date="2020-01-01",
147
+ end_date="2020-12-31"
148
+ )
149
+ ```
150
+
151
+ To download annual (or quaterly) Compustat data:
152
+
153
+ ```python
154
+ tf.download_data(
155
+ domain="wrds",
156
+ dataset="compustat_annual",
157
+ start_date="2020-01-01",
158
+ end_date="2020-12-31"
159
+ )
160
+ ```
161
+
162
+ To download the CRSP-Compustat linking table:
163
+
164
+ ```python
165
+ tf.download_data(
166
+ domain="wrds",
167
+ dataset="ccm_links"
168
+ )
169
+ ```
170
+
171
+ To download bond characteristics from Mergent FISD:
172
+
173
+ ```python
174
+ tf.download_data(
175
+ domain="wrds",
176
+ dataset="fisd"
177
+ )
178
+ ```
179
+
180
+ To download Enhanced TRACE data for selected bonds:
181
+
182
+ ```python
183
+ tf.download_data(
184
+ domain="wrds",
185
+ dataset="trace_enhanced",
186
+ cusips=["00101JAH9"],
187
+ start_date="2019-01-01",
188
+ end_date="2021-12-31"
189
+ )
190
+ ```
191
+
192
+ ## Other Helpers
193
+
194
+ We include functions to check out content from tidy-finance.org:
195
+
196
+ ```python
197
+ tf.list_tidy_finance_chapters()
198
+ tf.open_tidy_finance_website("capital-asset-pricing-model")
199
+ ```
200
+
201
+ We also include (experimental) functions that can be used for different applications, but note that they might heavily change in future package versions as we try to make them more general:
202
+
203
+ ```python
204
+ # Create summary statistics
205
+ help(tf.create_summary_statistics)
206
+
207
+ # Assign portfolios
208
+ help(tf.assign_portfolio)
209
+
210
+ # Estimate betas
211
+ help(tf.estimate_betas)
212
+
213
+ # Estimate Fama-MacBeth
214
+ help(tf.estimate_fama_macbeth)
215
+
216
+ # Add lag columns
217
+ help(tf.add_lag_columns)
218
+
219
+ # Winsorize or trim
220
+ help(tf.winsorize)
221
+ help(tf.trim)
222
+ ```
@@ -0,0 +1,198 @@
1
+ # tidyfinance
2
+
3
+ ![PyPI](https://img.shields.io/pypi/v/tidyfinance?label=pypi%20package)
4
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/tidyfinance)
5
+ [![python-package.yml](https://github.com/tidy-finance/py-tidyfinance/actions/workflows/python-package.yml/badge.svg)](https://github.com/tidy-finance/py-tidyfinance/actions/workflows/python-package.yml)
6
+ <!-- [![codecov.yml](https://codecov.io/gh/tidy-finance/py-tidyfinance/graph/badge.svg)](https://app.codecov.io/gh/tidy-finance/py-tidyfinance) -->
7
+ [![License:
8
+ MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ Helper functions for empirical research in financial economics, addressing a variety of topics covered in [Scheuch, Frey, Voigt, and Weiss (2024)](https://doi.org/10.1201/9781032684307). The package is designed to provide shortcuts for issues extensively discussed in the book, facilitating easier application of its concepts. For more information and resources related to the book, visit [tidy-finance.org/python](https://tidy-finance.org/python).
11
+
12
+ ## Installation
13
+
14
+ You can install the release version from [PyPI](https://pypi.org/project/tidyfinance/):
15
+
16
+ ```
17
+ pip install tidyfinance
18
+ ```
19
+
20
+ You can install the development version from GitHub:
21
+
22
+ ```
23
+ pip install "git+https://github.com/tidy-finance/py-tidyfinance"
24
+ ```
25
+
26
+ ## Download Open Source Data
27
+
28
+ The main functionality of the `tidyfinance` package centers around data download. You can download most of the data that we used in Tidy Finance with R using the `download_data()` function or its children.
29
+
30
+ ```python
31
+ import tidyfinance as tf
32
+ ```
33
+
34
+ The function always requires a `domain` argument and depending on the domain typically also a `dataset`. For instance, to download monthly Fama-French factors, you have to provide the dataset name according to `pdr.famafrench.get_available_datasets()`:
35
+
36
+ ```python
37
+ tf.download_data(
38
+ domain="factors_ff",
39
+ dataset="F-F_Research_Data_5_Factors_2x3_daily",
40
+ start_date="2000-01-01",
41
+ end_date="2020-12-31"
42
+ )
43
+ ```
44
+
45
+ For q factors, you provide the relevant file name:
46
+
47
+ ```python
48
+ tf.download_data(
49
+ domain="factors_q",
50
+ dataset="q5_factors_monthly",
51
+ start_date="2000-01-01",
52
+ end_date="2020-12-31"
53
+ )
54
+ ```
55
+
56
+ To download the Welch and Goyal (2008) macroeconomic predictors for monthly, quarterly, or annual frequency:
57
+
58
+ ```python
59
+ tf.download_data(
60
+ domain="macro_predictors",
61
+ dataset="monthly",
62
+ start_date="2000-01-01",
63
+ end_date="2020-12-31"
64
+ )
65
+ ```
66
+
67
+ To download data from Open Source Asset Pricing (OSAP):
68
+
69
+ ```python
70
+ tf.download_data(
71
+ domain="osap",
72
+ start_date="2020-01-01",
73
+ end_date="2020-12-31"
74
+ )
75
+ ```
76
+
77
+ To download multiple series from the Federal Reserve Economic Data (FRED):
78
+
79
+ ```python
80
+ tf.download_data(
81
+ domain="fred",
82
+ series=["GDP", "CPIAUCNS"],
83
+ start_date="2020-01-01",
84
+ end_date="2020-12-31"
85
+ )
86
+ ```
87
+
88
+ To download stock prices from Yahoo Finance:
89
+
90
+ ```python
91
+ tf.download_data(
92
+ domain="stock_prices",
93
+ symbols=["AAPL", "MSFT"],
94
+ start_date="2020-01-01",
95
+ end_date="2020-12-31"
96
+ )
97
+ ```
98
+
99
+ To download index constituents from selected ETF holdings:
100
+
101
+ ```python
102
+ tf.download_data(
103
+ domain="constituents",
104
+ index="S&P 500"
105
+ )
106
+ ```
107
+
108
+ ## Download WRDS Data
109
+
110
+ To access data from the [Wharton Research Data Services (WRDS)](https://wrds-www.wharton.upenn.edu/), you need to set your credentials first:
111
+
112
+ ```python
113
+ tf.set_wrds_credentials()
114
+ ```
115
+
116
+ To download monthly CRSP data:
117
+
118
+ ```python
119
+ tf.download_data(
120
+ domain="wrds",
121
+ dataset="crsp_monthly",
122
+ start_date="2020-01-01",
123
+ end_date="2020-12-31"
124
+ )
125
+ ```
126
+
127
+ To download annual (or quaterly) Compustat data:
128
+
129
+ ```python
130
+ tf.download_data(
131
+ domain="wrds",
132
+ dataset="compustat_annual",
133
+ start_date="2020-01-01",
134
+ end_date="2020-12-31"
135
+ )
136
+ ```
137
+
138
+ To download the CRSP-Compustat linking table:
139
+
140
+ ```python
141
+ tf.download_data(
142
+ domain="wrds",
143
+ dataset="ccm_links"
144
+ )
145
+ ```
146
+
147
+ To download bond characteristics from Mergent FISD:
148
+
149
+ ```python
150
+ tf.download_data(
151
+ domain="wrds",
152
+ dataset="fisd"
153
+ )
154
+ ```
155
+
156
+ To download Enhanced TRACE data for selected bonds:
157
+
158
+ ```python
159
+ tf.download_data(
160
+ domain="wrds",
161
+ dataset="trace_enhanced",
162
+ cusips=["00101JAH9"],
163
+ start_date="2019-01-01",
164
+ end_date="2021-12-31"
165
+ )
166
+ ```
167
+
168
+ ## Other Helpers
169
+
170
+ We include functions to check out content from tidy-finance.org:
171
+
172
+ ```python
173
+ tf.list_tidy_finance_chapters()
174
+ tf.open_tidy_finance_website("capital-asset-pricing-model")
175
+ ```
176
+
177
+ We also include (experimental) functions that can be used for different applications, but note that they might heavily change in future package versions as we try to make them more general:
178
+
179
+ ```python
180
+ # Create summary statistics
181
+ help(tf.create_summary_statistics)
182
+
183
+ # Assign portfolios
184
+ help(tf.assign_portfolio)
185
+
186
+ # Estimate betas
187
+ help(tf.estimate_betas)
188
+
189
+ # Estimate Fama-MacBeth
190
+ help(tf.estimate_fama_macbeth)
191
+
192
+ # Add lag columns
193
+ help(tf.add_lag_columns)
194
+
195
+ # Winsorize or trim
196
+ help(tf.winsorize)
197
+ help(tf.trim)
198
+ ```
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tidyfinance"
7
+ authors = [{name = "Christoph Scheuch", email = "christoph@tidy-intelligence.com"},
8
+ {name = "Christoph Frey", email = "christoph.frey@gmail.com"}]
9
+ version = "0.1.1"
10
+ description = "Tidy Finance Helper Functions"
11
+ readme = "README.md"
12
+ license = "MIT"
13
+ requires-python = ">=3.10"
14
+ dependencies = [
15
+ "pandas>=2.2.0",
16
+ "numpy>=1.26.0",
17
+ "sqlalchemy>=2.0.21",
18
+ "pyyaml>=6.0.2",
19
+ "pandas-datareader>=0.10.0",
20
+ "statsmodels>=0.14.0",
21
+ "requests>=2.31.0",
22
+ "pyarrow>=19.0.1",
23
+ "psycopg2-binary>=2.9.9",
24
+ "dotenv>=0.9.9",
25
+ "lxml>=5.3.1",
26
+ ]
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "pytest>=8.3.4",
31
+ "pytest-httpx>=0.35.0",
32
+ "pytest-cov>=6.0.0"
33
+ ]
34
+
35
+ [project.urls]
36
+ Repository = "https://github.com/tidy-finance/py-tidyfinance"
37
+ Issues = "https://github.com/tidy-finance/py-tidyfinance/issues"
38
+ Changelog = "https://github.com/tidy-finance/py-tidyfinance/blob/master/CHANGELOG.md"
39
+
40
+ [tool.pytest.ini_options]
41
+ filterwarnings = [
42
+ "ignore:distutils Version classes are deprecated:DeprecationWarning"
43
+ ]
44
+
45
+ [tool.ruff]
46
+ line-length = 80
@@ -0,0 +1,56 @@
1
+ arch==7.2.0
2
+ asttokens==3.0.0
3
+ certifi==2025.1.31
4
+ charset-normalizer==3.4.1
5
+ cloudpickle==3.1.0
6
+ colorama==0.4.6
7
+ comm==0.2.2
8
+ debugpy==1.8.11
9
+ decorator==5.1.1
10
+ exceptiongroup==1.2.2
11
+ executing==2.1.0
12
+ greenlet==3.1.1
13
+ idna==3.10
14
+ iniconfig==2.0.0
15
+ ipykernel==6.29.5
16
+ ipython==8.31.0
17
+ jedi==0.19.2
18
+ jupyter_client==8.6.3
19
+ jupyter_core==5.7.2
20
+ lxml==5.3.1
21
+ matplotlib-inline==0.1.7
22
+ nest-asyncio==1.6.0
23
+ numpy==2.2.1
24
+ packaging==24.2
25
+ pandas==2.2.3
26
+ pandas-datareader==0.10.0
27
+ parso==0.8.4
28
+ patsy==1.0.1
29
+ platformdirs==4.3.6
30
+ pluggy==1.5.0
31
+ prompt_toolkit==3.0.48
32
+ psutil==6.1.1
33
+ psycopg2==2.9.10
34
+ pure_eval==0.2.3
35
+ Pygments==2.18.0
36
+ pytest==8.3.4
37
+ python-dateutil==2.9.0.post0
38
+ pytz==2024.2
39
+ pywin32==308
40
+ PyYAML==6.0.2
41
+ pyzmq==26.2.0
42
+ requests==2.32.3
43
+ scipy==1.15.0
44
+ six==1.17.0
45
+ spyder-kernels==3.0.2
46
+ SQLAlchemy==2.0.38
47
+ stack-data==0.6.3
48
+ statsmodels==0.14.4
49
+ tomli==2.2.1
50
+ tornado==6.4.2
51
+ tqdm==4.67.1
52
+ traitlets==5.14.3
53
+ typing_extensions==4.12.2
54
+ tzdata==2024.2
55
+ urllib3==2.3.0
56
+ wcwidth==0.2.13
File without changes