-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession4A_talk2.html
439 lines (328 loc) · 18.7 KB
/
session4A_talk2.html
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
433
434
435
436
437
438
439
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Computing Disposition Effect on Financial Market Data</title>
<meta charset="utf-8" />
<meta name="author" content="Lorenzo Mazzucchelli - Marco Zanotti" />
<script src="libs/header-attrs-2.7/header-attrs.js"></script>
<link href="libs/remark-css-0.0.1/useR.css" rel="stylesheet" />
<link href="libs/remark-css-0.0.1/useR-fonts.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.5.2/htmlwidgets.js"></script>
<script src="libs/jquery-1.12.4/jquery.min.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.16/datatables.js"></script>
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk-1.1.0.1/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.1.0.1/js/crosstalk.min.js"></script>
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# Computing Disposition Effect <br> on Financial Market Data
### Lorenzo Mazzucchelli - Marco Zanotti
### University of Milan - Triboo
### 2021/07/06
---
class: center, top
# The Speakers
&nbsp;
.pull-left[
<img src="figures/lm.jpeg" title="Lorenzo Mazzucchelli pic" alt="Lorenzo Mazzucchelli pic" width="85%" />
**Lorenzo Mazzucchelli**
*Phd, University of Milan*
[*Linkedin*](https://www.linkedin.com/in/lorenzo-mazzucchelli-72a661122/)
]
.pull-right[
<img src="figures/mz.jpeg" title="Marco Zanotti pic" alt="Marco Zanotti pic" width="85%" />
**Marco Zanotti**
*Data Scientist, Triboo*
[*Linkedin*](https://www.linkedin.com/in/marco-zanotti-a6a978124/),
[*Website*](https://marcozanotti.netlify.app/)
]
---
class: chapter-slide, left, middle
# The Disposition Effect
---
# Definition
&nbsp;
.center[
### Disposition Effect (DE)
**the realization that investors are more likely to sell an asset
when it is gaining value compared to when it is losing value.**
]
&nbsp;
An irrational phenomenon which is closely related to sunk costs’ bias,
diminishing sensitivity, and loss aversion.
It is observed on financial and real stock markets.
---
# History
From **1985**, the disposition effect has been documented in US
retail stock investors, as well as in foreign retail investors,
and even among professionals and institutions.
&nbsp;
* Discovered by Shefrin and Statman (1985)
* Empirically studied by Odean (1998) on the US financial market.
He developed a method to measure it.
* Grinblatt and Keloharju (2001) showed that financial institutions
have a smalle DE, but they still behave according to it.
* Nowadays the focus has turned from single stocks in the portfolio
to the so-called *Portfolio Driven Disposition Effect*,
Engelberg et al (2019).
---
# Computation
Difference between the ratio of unrealized gains (losses) over
the total opportunity, realized or not, of gains (losses).
`$$DE = \bigg(\frac{RG}{RG + PG}\bigg) - \bigg(\frac{RL}{RL + PL}\bigg)$$`
*where RG/RL = realized gains/losses, PG/PL = paper gains/losses*
**After each investor’s trade**, one needs to **record the number
of different stocks in the investor’s portfolio** that are
**sold for a gain** [1], **sold for a loss** [2],
**not sold at a gain** [3], and **not sold at a loss** [4] <sup>*</sup>.
Gains and losses of the stocks are computed by comparing the actual
market price with the original purchasing price.
&nbsp;
.right[
.footnote[
<sup>\*</sup>*Realized gains [1] and losses [2] are actual
trades in which the investor realizes a profit or a loss.
Stocks not sold are called paper gains [3] and paper losses [4].*
]
]
---
# Why is DE important?
1. DE can be found in variety of contexts. Past researches
have shown DE in auctions, house markets, financial markets,
etc. DE could be also found in policy contexts, such as
Vietnam War.
2. Mutual funds that are "DE-prone" have inferior
performance by 4-6% with respect to "non-DE-prone" funds,
as shown by Singal and Xu (2011).
3. Understanding DE could help financial authorities
managing regulations and intervention on the markets.
4. DE is another relevant case of irrationality of agents.
Its presence leads to further evidence of the inconsistency of
classical economic theory, based on the rational agent hypothesis.
Hence, being able to correctly and timely capture these
irrational behaviours is very important, especially in periods
of high uncertainty and crisis.
---
class: center, middle
<img src="figures/logo.png" title="dispositionEffect Logo" alt="dispositionEffect Logo" width="50%" style="display: block; margin: auto;" />
.pull-left[
###[**Github repo**](https://github.com/marcozanotti/dispositionEffect)
]
.pull-right[
###[**Website**](https://marcozanotti.github.io/dispositionEffect/)
]
<img src="figures/badges.png" title="Badges" alt="Badges" width="70%" style="display: block; margin: auto;" />
---
class: chapter-slide, left, middle
# dispositionEffect Package
---
# Package Functions
&nbsp;
* `gains_losses`
the core function of the package, it performs all the calculations
of realized and paper gains and losses, and it can be used for
stream-data calculations.
It is intended for advanced users only.
* `portfolio_compute`
a user-friendly interface to compute realized and paper gains and losses
from the investor’s transactions and the market prices of the traded assets.
It also updates the investor’s portfolio.
* `disposition_compute`, `disposition_summary`
the two interfaces to easily compute the disposition effect
and summary statistics, based on *portfolio_compute* output.
---
# Input Data
&nbsp;
.pull-left[
.center[
###**Transactions**]
All the financial transactions an investor did during a specific
period of time.
A single transaction is made up of 6 features: the investor id,
the asset id, the type of the transaction (buy or sell),
the traded quantity, the traded price, and the trading datetime.
]
.pull-right[
.center[
### **Market Prices**]
.right[
The actual prices found on the stock markets for each traded
asset on each transaction datetime.
A single observation is made up of 3 features: the asset id,
the datetime, and the market value of the asset.]
]
---
# Investor's Transactions
<div id="htmlwidget-b0d236c669c511ad83ff" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-b0d236c669c511ad83ff">{"x":{"filter":"none","fillContainer":false,"data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],["4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N","4273N"],["B","B","S","B","S","B","S","B","S","B","S","B","B","B","B","B","B","B","B"],["ACO","LSUG","ACO","IT3S","IT3S","LSUG","LSUG","AST","AST","LSUG","LSUG","ACO","ACO","ACO","ACO","ACO","TFI","TFI","TFI"],[45,450,45,230,230,90,540,430,430,450,450,70,100,1,1,50,300,590,510],[3.94,2.0515,4.18,1.098,1.03,2.53,2.18,2.294,1.95,2.175,2.24,2.84,2.84,2.84,2.84,2.84,0.284,0.284,0.284],["2018-04-09T11:17:00Z","2018-05-17T15:06:00Z","2018-05-22T17:11:00Z","2018-05-28T14:30:00Z","2018-06-01T15:27:00Z","2018-06-01T15:43:00Z","2018-06-05T14:06:00Z","2018-06-07T14:49:00Z","2018-06-25T11:56:00Z","2018-06-28T15:19:00Z","2018-10-30T14:56:00Z","2018-10-31T11:51:00Z","2018-10-31T15:29:00Z","2018-10-31T16:14:00Z","2018-10-31T16:19:00Z","2018-10-31T17:15:00Z","2018-11-05T09:07:00Z","2018-11-05T09:30:00Z","2018-11-05T09:52:00Z"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>investor<\/th>\n <th>type<\/th>\n <th>asset<\/th>\n <th>quantity<\/th>\n <th>price<\/th>\n <th>datetime<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":6,"columnDefs":[{"className":"dt-right","targets":[4,5]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[6,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# Market Prices
<div id="htmlwidget-82f56c89243abef5e19f" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-82f56c89243abef5e19f">{"x":{"filter":"none","fillContainer":false,"data":[["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"],["ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI","ACO","AST","IT3S","LSUG","TFI"],["2018-04-09T11:17:00Z","2018-04-09T11:17:00Z","2018-04-09T11:17:00Z","2018-04-09T11:17:00Z","2018-04-09T11:17:00Z","2018-05-17T15:06:00Z","2018-05-17T15:06:00Z","2018-05-17T15:06:00Z","2018-05-17T15:06:00Z","2018-05-17T15:06:00Z","2018-05-22T17:11:00Z","2018-05-22T17:11:00Z","2018-05-22T17:11:00Z","2018-05-22T17:11:00Z","2018-05-22T17:11:00Z","2018-05-28T14:30:00Z","2018-05-28T14:30:00Z","2018-05-28T14:30:00Z","2018-05-28T14:30:00Z","2018-05-28T14:30:00Z","2018-06-01T15:27:00Z","2018-06-01T15:27:00Z","2018-06-01T15:27:00Z","2018-06-01T15:27:00Z","2018-06-01T15:27:00Z","2018-06-01T15:43:00Z","2018-06-01T15:43:00Z","2018-06-01T15:43:00Z","2018-06-01T15:43:00Z","2018-06-01T15:43:00Z","2018-06-05T14:06:00Z","2018-06-05T14:06:00Z","2018-06-05T14:06:00Z","2018-06-05T14:06:00Z","2018-06-05T14:06:00Z","2018-06-07T14:49:00Z","2018-06-07T14:49:00Z","2018-06-07T14:49:00Z","2018-06-07T14:49:00Z","2018-06-07T14:49:00Z","2018-06-25T11:56:00Z","2018-06-25T11:56:00Z","2018-06-25T11:56:00Z","2018-06-25T11:56:00Z","2018-06-25T11:56:00Z","2018-06-28T15:19:00Z","2018-06-28T15:19:00Z","2018-06-28T15:19:00Z","2018-06-28T15:19:00Z","2018-06-28T15:19:00Z","2018-10-30T14:56:00Z","2018-10-30T14:56:00Z","2018-10-30T14:56:00Z","2018-10-30T14:56:00Z","2018-10-30T14:56:00Z","2018-10-31T11:51:00Z","2018-10-31T11:51:00Z","2018-10-31T11:51:00Z","2018-10-31T11:51:00Z","2018-10-31T11:51:00Z","2018-10-31T15:29:00Z","2018-10-31T15:29:00Z","2018-10-31T15:29:00Z","2018-10-31T15:29:00Z","2018-10-31T15:29:00Z","2018-10-31T16:14:00Z","2018-10-31T16:14:00Z","2018-10-31T16:14:00Z","2018-10-31T16:14:00Z","2018-10-31T16:14:00Z","2018-10-31T16:19:00Z","2018-10-31T16:19:00Z","2018-10-31T16:19:00Z","2018-10-31T16:19:00Z","2018-10-31T16:19:00Z","2018-10-31T17:15:00Z","2018-10-31T17:15:00Z","2018-10-31T17:15:00Z","2018-10-31T17:15:00Z","2018-10-31T17:15:00Z","2018-11-05T09:07:00Z","2018-11-05T09:07:00Z","2018-11-05T09:07:00Z","2018-11-05T09:07:00Z","2018-11-05T09:07:00Z","2018-11-05T09:30:00Z","2018-11-05T09:30:00Z","2018-11-05T09:30:00Z","2018-11-05T09:30:00Z","2018-11-05T09:30:00Z","2018-11-05T09:52:00Z","2018-11-05T09:52:00Z","2018-11-05T09:52:00Z","2018-11-05T09:52:00Z","2018-11-05T09:52:00Z"],[3.94,2.196,1.0184,2.2495,0.40575,4.56,2.38,0.9122,2.0515,0.409,4.18,2.264,0.9462,2.19,0.4045,4.24,2.12,1.098,2.32,0.4105,4.04,2.15,1.031,2.55,0.413,4.04,2.15,1.032,2.53,0.413,4.31,2.19,1.054,2.18,0.4105,4.17,2.294,1.0914,2.18,0.407,4.23,1.95,1.104,2.22,0.37075,4.23,2,1.134,2.175,0.3085,2.88,0.595,1.4542,2.24,0.263666666666667,2.84,0.59,1.4364,2.24,0.2705,2.84,0.573,1.434,2.24,0.2705,2.84,0.573,1.434,2.24,0.2705,2.84,0.573,1.434,2.24,0.2705,2.84,0.573,1.451,2.24,0.2705,2.89,0.537,1.387,2.24,0.284,2.89,0.537,1.387,2.24,0.284,2.89,0.537,1.374,2.24,0.284]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>asset<\/th>\n <th>datetime<\/th>\n <th>price<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":6,"columnDefs":[{"className":"dt-right","targets":3},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[6,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
background-image: url("figures/diagram.png")
background-size: 95%
background-position: 50% 80%
class: left, top
# How to compute DE?
---
# Main Function: `portfolio_compute`
```r
portfolio_compute(
portfolio_transactions, market_prices,
* method = "count",
* allow_short = TRUE,
time_threshold = "0 mins",
exact_market_prices = TRUE,
* portfolio_driven_DE = FALSE,
* time_series_DE = FALSE, assets_time_series_DE = NULL,
verbose = c(0, 0), progress = FALSE
)
```
Highly flexible, different methods implemented, few different analysis.
&nbsp;
&nbsp;
.right[.footnote[
See vignette [The Analysis of Disposition Effect](https://marcozanotti.github.io/dispositionEffect/articles/de-analysis.html)
]]
---
# Computational Efficiency
On **stream data**, computation is **instantaneous**.
On **batch data**, the **number of transactions** and the
**number of traded assets** impact on `portfolio_compute`.
`disposition_compute` is **instantaneous**.
<img src="figures/efficiency.png" title="Table of computational efficiency results for portfolio_compute and disposition_compute" alt="Table of computational efficiency results for portfolio_compute and disposition_compute" width="70%" style="display: block; margin: auto;" />
.right[.footnote[
See vignette [Disposition Effect in Parallel](https://marcozanotti.github.io/dispositionEffect/articles/de-parallel.html)
]]
---
class: center, middle
# Thanks!
<a href='https://marcozanotti.github.io/dispositionEffect/'><img src="figures/logo.png", alt="dispositionEffect Logo", width="20%"/></a>
Lorenzo Mazzucchelli, Marco Zanotti
[download presentation](https://github.com/marcozanotti/dispostionEffect-useR2021)
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>