Repository navigation
Expand file tree
/
Copy pathindex.qmd
More file actions
432 lines (370 loc) · 15.4 KB
/
Copy pathindex.qmd
File metadata and controls
432 lines (370 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
---
aliases:
- r/index.html
- python/index.html
pagetitle: "Tidy Finance"
page-layout: custom
section-divs: false
toc: false
css: assets/css/index.css
editor: source
description: |
An opinionated approach on empirical research in financial economics.
hide-description: true
format:
html:
include-in-header: assets/html/swiper-header.html
include-after-body: assets/html/swiper-bottom.html
metadata:
pagetitle: Welcome to Tidy Finance
description-meta: An opinionated approach on empirical research in financial economics using the programming languages R and Python.
---
::: {.tf-landing}
<!-- ============================ HERO ============================ -->
::: {.tf-hero}
::: {.tf-hero__bg}
:::
::: {.tf-hero__inner}
::: {.tf-hero__copy}
[★ Open-source · R & Python · Reproducible]{.tf-badge}
# Empirical finance, [reproducible]{.tf-grad} in R and Python
[Tidy Finance takes an opinionated, fully transparent approach to empirical research in financial economics. One open-source code base now covers R and Python, side by side in every chapter.]{.tf-lead}
::: {.tf-cta-row}
[Start here](chapters/working-with-stock-returns.html){.tf-btn .tf-btn--primary}
<!-- [Factor Library](https://factors.tidy-finance.org){.tf-btn .tf-btn--ghost} -->
[Python Library](https://python.tidy-finance.org){.tf-btn .tf-btn--ghost}
[R Package](https://r.tidy-finance.org){.tf-btn .tf-btn--ghost}
:::
:::
::: {.tf-hero__visual}
::: {.tf-window}
::: {.tf-window__bar}
```{=html}
<span class="tf-dot tf-dot--r"></span><span class="tf-dot tf-dot--y"></span><span class="tf-dot tf-dot--g"></span><span class="tf-window__file">download & plot prices</span>
```
:::
::: {.panel-tabset .tf-no-margin-tabs group="language"}
### R
```r
library(tidyfinance)
library(ggplot2)
prices <- download_data(
domain = "Stock Prices",
symbols = "AAPL",
start_date = "2000-01-01",
end_date = "2024-12-31"
)
prices |>
ggplot(aes(date, adjusted_close)) +
geom_line()
```
### Python
```python
import tidyfinance as tf
from plotnine import ggplot, aes, geom_line
prices = tf.download_data(
domain="Stock Prices",
symbols="AAPL",
start_date="2000-01-01",
end_date="2024-12-31"
)
(ggplot(prices, aes("date", "adjusted_close"))
+ geom_line())
```
:::
:::
:::
:::
:::
<!-- ============================ STATS ============================ -->
::: {.tf-stats}
::: {.tf-stats__grid}
::: {.tf-stat}
[20+]{.tf-stat__num}
[Hands-on chapters]{.tf-stat__label}
:::
::: {.tf-stat}
[2]{.tf-stat__num}
[Languages, one code base]{.tf-stat__label}
:::
::: {.tf-stat}
[100%]{.tf-stat__num}
[Open source & reproducible]{.tf-stat__label}
:::
:::
:::
```{=html}
<script>
(function () {
function animate(el) {
var raw = el.getAttribute('data-target');
var m = raw.match(/^(\D*)(\d+(?:\.\d+)?)(\D*)$/);
if (!m) { el.textContent = raw; return; }
var prefix = m[1], target = parseFloat(m[2]), suffix = m[3];
var decimals = (m[2].split('.')[1] || '').length;
var dur = 1300, start = null, finished = false;
function ease(t) { return 1 - Math.pow(1 - t, 3); }
function finish() {
if (finished) return;
finished = true;
el.textContent = prefix + target.toFixed(decimals) + suffix;
}
function step(ts) {
if (finished) return;
if (start === null) start = ts;
var p = Math.min((ts - start) / dur, 1);
el.textContent = prefix + (ease(p) * target).toFixed(decimals) + suffix;
if (p < 1) { requestAnimationFrame(step); } else { finish(); }
}
// Safety net: if rAF is throttled/paused, still land on the final value.
setTimeout(finish, dur + 800);
requestAnimationFrame(step);
}
function init() {
var nums = document.querySelectorAll('.tf-stat__num');
if (!nums.length) return;
nums.forEach(function (el) { el.setAttribute('data-target', el.textContent.trim()); });
var reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (reduce || !('IntersectionObserver' in window)) return; // leave final values in place
nums.forEach(function (el) { el.textContent = el.textContent.replace(/\d+(\.\d+)?/, '0'); });
var band = document.querySelector('.tf-stats');
var fired = false;
function trigger() {
if (fired) return;
fired = true;
if (io) { io.disconnect(); }
nums.forEach(animate);
}
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (e) { if (e.isIntersecting) { trigger(); } });
}, { threshold: 0.4 });
if (band) { io.observe(band); }
// Fallback if IntersectionObserver does not deliver: animate once the band is on screen.
setTimeout(function () {
if (fired) { return; }
var r = (band || document.body).getBoundingClientRect();
if (r.top < window.innerHeight && r.bottom > 0) { trigger(); }
}, 1200);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
</script>
```
<!-- ============================ FEATURES ============================ -->
::: {.tf-section}
::: {.tf-section__head}
## Everything you need for reproducible research in finance
A single, transparent code base takes you from raw data to publication-quality results, in R and Python.
:::
::: {.tf-features}
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg></div>
```
### One code base, two languages
Every chapter ships R and Python side by side from a single source. Switch with a tab. Your choice follows you through the book.
:::
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg></div>
```
### Fully transparent & reproducible
Open code you can run end to end, from raw data to every figure and table, with no black boxes.
:::
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="16.5" y1="9.4" x2="7.5" y2="4.21"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg></div>
```
### Powered by `tidyfinance`
A companion package for R and Python that wraps data downloads and the routines we use throughout the book.
:::
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg></div>
```
### Real financial data
Work with the data professionals use, like CRSP, Compustat, and TRACE, through clean, documented access patterns.
:::
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/><polyline points="17 6 23 6 23 12"/></svg></div>
```
### From sorts to machine learning
Portfolio sorts, factor models, fixed effects, causal inference, and modern ML give you the full empirical toolkit.
:::
::: {.tf-feature}
```{=html}
<div class="tf-feature__icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/></svg></div>
```
### A free, open book
Read the whole book online for free or dive into the blog all in the open.
:::
:::
:::
<!-- ============================ CURRICULUM ============================ -->
::: {.tf-section .tf-section--quiet}
::: {.tf-section__head}
## Browse the book by topic
Five parts take you from your first stock return to constrained portfolio backtests.
:::
```{=html}
<div class="tf-tracks">
<a class="tf-track" href="chapters/working-with-stock-returns.html">
<div class="tf-track__no">PART 01</div>
<h3>Getting Started</h3>
<p>Stock returns, modern portfolio theory, the CAPM, and financial statement analysis.</p>
<div class="tf-track__cta">Start here →</div>
</a>
<a class="tf-track" href="chapters/accessing-and-managing-financial-data.html">
<div class="tf-track__no">PART 02</div>
<h3>Financial Data</h3>
<p>Access and manage WRDS, CRSP, Compustat, TRACE, and FISD with documented workflows.</p>
<div class="tf-track__cta">Explore data →</div>
</a>
<a class="tf-track" href="chapters/beta-estimation.html">
<div class="tf-track__no">PART 03</div>
<h3>Asset Pricing</h3>
<p>Beta estimation, univariate and bivariate sorts, Fama-French factors, and Fama-MacBeth.</p>
<div class="tf-track__cta">Price assets →</div>
</a>
<a class="tf-track" href="chapters/fixed-effects-and-clustered-standard-errors.html">
<div class="tf-track__no">PART 04</div>
<h3>Modeling & Machine Learning</h3>
<p>Fixed effects, difference-in-differences, factor selection, and option pricing via ML.</p>
<div class="tf-track__cta">Model it →</div>
</a>
<a class="tf-track" href="chapters/parametric-portfolio-policies.html">
<div class="tf-track__no">PART 05</div>
<h3>Portfolio Optimization</h3>
<p>Parametric portfolio policies and constrained optimization with realistic backtesting.</p>
<div class="tf-track__cta">Optimize →</div>
</a>
</div>
```
:::
<!-- ============================ TESTIMONIALS ============================ -->
::: {.tf-section}
::: {.tf-section__head}
[Praise]{.tf-eyebrow}
## What experts say about Tidy Finance
:::
```{=html}
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper" id="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/harald_lohre.jpg" alt="A portrait of Harald Lohre">
</div>
<p><i>A clean coding environment is a prerequisite for building a relevant investment platform and conducting meaningful factor research. Tidy Finance is the name of the game, giving aspiring academics and finance practitioners just what they need to perform clean and reproducible research. Highly recommended.</i></p>
<div class="quote-author">
<p><strong>Harald Lohre</strong></p>
<p>Executive Director at Robeco</p>
<p>Honorary Researcher at Lancaster University Management School</p>
</div>
</div>
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/albert_j_menkveld.jpeg" alt="A portrait of Albert J. Menkveld">
</div>
<p><i>From our crowd-sourced paper on non-standard errors, I learned how important clean coding is. Tidy Finance is a rich resource for empirical finance researchers, offering clean coding techniques that benefit both beginners and experts.</i></p>
<div class="quote-author">
<p><strong>Albert J. Menkveld</strong></p>
<p>Professor of Finance at Vrije Universiteit Amsterdam</p>
<p>Fellow at Tinbergen Institute</p>
</div>
</div>
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/nikolaus_hautsch.jpeg" alt="A portrait of Nikolaus Hautsch">
</div>
<p><i>A fantastic book bringing together financial theory, sound econometrics, thorough data processing and powerful programming techniques. An absolute must for every student and scholar in empirical finance.</i></p>
<div class="quote-author">
<p><strong>Nikolaus Hautsch</strong></p>
<p>Professor of Finance & Statistics at University of Vienna</p>
</div>
</div>
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/bjoern_hagstroemer.jpeg" alt="A portrait of Björn Hagströmer">
</div>
<p><i>Tidy Finance is a fantastic resource that lowers the threshold for entry into empirical finance, all in the spirit of open and reproducible science.</i></p>
<div class="quote-author">
<p><strong>Björn Hagströmer</strong></p>
<p>Professor of Finance at Stockholm Business School</p>
</div>
</div>
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/raman_uppal.jpeg" alt="A portrait of Raman Uppal">
</div>
<p><i>To have a deep understanding of empirical asset pricing, one needs to write code using actual data. To learn how to do this, there is no better starting point than Tidy Finance. [...] I strongly recommend Tidy Finance to both beginners and experts.</i></p>
<div class="quote-author">
<p><strong>Raman Uppal</strong></p>
<p>Professor of Finance at EDHEC Business School</p>
</div>
</div>
<div class="swiper-slide">
<div class="quote-image">
<img src="assets/img/quotes/mark_salmon.jpeg" alt="A portrait of Mark Salmon">
</div>
<p><i>Students and professionals alike are led step by step until they suddenly find themselves coding on their own. A brilliant and required resource!</i></p>
<div class="quote-author">
<p><strong>Mark Salmon</strong></p>
<p>Professor of Economics at University of Cambridge</p>
</div>
</div>
</div>
<!-- Pagination buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
```
:::
<!-- ============================ TEAM ============================ -->
::: {.tf-section}
::: {.tf-section__head}
[The team]{.tf-eyebrow}
## Who maintains Tidy Finance
:::
```{=html}
<div class="team-grid">
<div class="team-member" onclick="openInNewTab('https://www.linkedin.com/in/christophscheuch/');">
<img src="assets/img/christoph_scheuch.jpeg" alt="A portrait of Christoph Scheuch">
<h3>Christoph Scheuch</h3>
<p>Associate Researcher at HU Berlin</p>
<span class="team-member-cta">LinkedIn →</span>
</div>
<div class="team-member" onclick="openInNewTab('https://www.voigtstefan.me/');">
<img src="assets/img/stefan_voigt.jpeg" alt="A portrait of Stefan Voigt">
<h3>Stefan Voigt</h3>
<p>Assistant Professor of Finance at University of Copenhagen</p>
<span class="team-member-cta">Website →</span>
</div>
<div class="team-member" onclick="openInNewTab('https://sites.google.com/view/patrick-weiss');">
<img src="assets/img/patrick_weiss.jpeg" alt="A portrait of Patrick Weiss">
<h3>Patrick Weiss</h3>
<p>Assistant Professor of Finance at Reykjavik University </p>
<span class="team-member-cta">Website →</span>
</div>
<div class="team-member" onclick="openInNewTab('https://sites.google.com/site/christophfrey/');">
<img src="assets/img/christoph_frey.jpeg" alt="A portrait of Christoph Frey">
<h3>Christoph Frey</h3>
<p>Quantitative Researcher</p>
<span class="team-member-cta">Website →</span>
</div>
</div>
<script>
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
</script>
```
:::
:::