forked from tevgeniou/BuybacksIssuers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
777 lines (631 loc) · 36.4 KB
/
index.Rmd
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
---
title: "Volatility and the Buyback Anomaly: Interactive Tool"
author: "[Theodoros Evgeniou](http://faculty.insead.edu/theodoros-evgeniou/), [Enric Junqué de Fortuny](http://ciri.be/), [Nick Nassuphis](https://www.linkedin.com/in/nick-nassuphis-8029372), and [Theo Vermaelen](http://faculty.insead.edu/theo-vermaelen/)"
output:
html_document:
fig_width: 6
fig_height: 2.5
fig_align: center
in_header: header.html
runtime: shiny
runtime: shiny
---
```{r, eval=TRUE, echo = FALSE,message=FALSE}
# Copyright 2015, INSEAD
# by T. Evgeniou, Enric Junque de Fortuny, Nick Nassuphis, Theo Vermaelen
# Dual licensed under the MIT or GPL Version 2 licenses.
```
```{r, eval=TRUE, echo = FALSE,message=FALSE}
# need this to avoid loading the R libraries when the tool is deployed on shinyapps (needs to be 0 when run localy, 1 when deployed on a shinyapps server)
run_shiny_tool = 1
```
```{r, eval=TRUE, echo = FALSE,message=FALSE}
# rm(list=ls()) # Clean up the memory, if we want to rerun from scratch
load("bb_issuersTOOL.Rdata")
if(run_shiny_tool) suppressPackageStartupMessages({
library(htmlwidgets)
library(shiny)
suppressWarnings(library(shinyjs))
library(shinysky) # devtools::install_github("AnalytixWare/ShinySky")
library(dygraphs)
library(Rcpp)
library(RcppArmadillo)
library(stringr)
library(gtools)
library(timeDate)
})
div(
style = "width:32px; height:32px; position:fixed; top:0; bottom:0; left:0; right:0; margin: auto; z-index:9999",
busyIndicator("", wait=111)
)
source("lib_helpers.R", local = TRUE)
source("latex_code.R")
source("ff_industries_sic.R")
source("Paper_global_parameters.R")
source("heatmapOutput.R")
source("ff_industries_sic.R")
useShinyjs(rmd=TRUE)
report_months_cal = c(as.numeric(reported_times[1:(length(reported_times)-1)]),1)
BUYBACK_DATA_TOOL$None <- 1:length(BUYBACK_DATA_TOOL$Prior.Returns.Score)
value.weights = rep(1,length(BUYBACK_DATA_TOOL$Prior.Returns.Score))
acceptaple_features = setdiff(names(BUYBACK_DATA_TOOL),c("Event.Date", "Industry_name","Event.Size"))
```
<br>
This is an interactive tool for the article [Volatility and the Buyback Anomaly](http://tevgeniou.github.io/BuybacksIssuers/). Users can explore the effects of various parameters as well as data filtering choices. Every time you change the parameters below, you can click on the **"Update Results"** button to see the new results. You may **need to wait a few seconds** until all results of this tool are updated (all tables/figures "fade in").
```{r, fig.width=6, fig.height=5,echo=FALSE}
fluidPage(shiny::actionButton("computeButtonALL","Update Results",icon=icon("spinner")) )
```
<br>
For any given choices of parameters, you can also download a pdf version of the results for the data sample you selected by clicking on the **Compile Report** button. **Note that it takes a few minutes (possibly more than five) to compile the new paper. Please wait until the option to download the paper, becomes available.**
```{r, fig.width=6, fig.height=5,echo=FALSE}
useShinyjs(rmd=TRUE)
fluidPage(
shiny::actionButton("compileReport","Compile Report",icon=icon("spinner")),
shiny::downloadButton("downloadReport", "Download Report")
)
```
<hr>
### Dataset Filtering
You can select some filters for the dataset. All analyses below will be done only for the events that are selected.
<br>
Select the time period, the minimum and maximum market capitalization of the firms (in $millions - the maximum selected should be larger than the minimum, else the maximum is automatically set to infinity) for which you would like to do the analyses below. You can also see the effects of removing some industries by selecting also any industries to remove (make sure there are enough data left for the analysis)
```{r, fig.width=6, fig.height=5,echo=FALSE}
report.data <- paste0("session.", session$token, ".report.data.Rdata")
report.script <- paste0("session.", session$token, ".report.script.R")
report.source <- paste0("session.", session$token, ".report.Rnw")
report.file <- paste0("session.", session$token, ".report.pdf")
observeEvent(input$compileReport, {
disable("compileReport")
with(report.list <- new.env(), {
startdate <- isolate(input$startdate)
enddate <- isolate(input$enddate)
market_cap_min <- isolate(input$market_cap_min)
market_cap_max <- isolate(input$market_cap_max)
characteristic <- isolate(input$characteristic)
characteristic_single_analysis <- isolate(input$characteristic_single_analysis)
quantile_used <- isolate(input$quantile_used)
characteristic_single_analysis_sign <- isolate(input$characteristic_single_analysis_sign)
high_EU_index_thres <- isolate(input$high_EU_index_thres)
low_EU_index_thres <- isolate(input$low_EU_index_thres)
quantile_used_ind <- isolate(input$quantile_used_ind)
quantile_used_all <- isolate(input$quantile_used_all)
characteristic_irats1 <- isolate(input$characteristic_irats1)
characteristic_irats2 <- isolate(input$characteristic_irats2)
characteristic_irats3 <- isolate(input$characteristic_irats3)
characteristic_irats4 <- isolate(input$characteristic_irats4)
characteristic_irats5 <- isolate(input$characteristic_irats5)
characteristic_irats6 <- isolate(input$characteristic_irats6)
characteristic_irats1_sign <- isolate(input$characteristic_irats1_sign)
characteristic_irats2_sign <- isolate(input$characteristic_irats2_sign)
characteristic_irats3_sign <- isolate(input$characteristic_irats3_sign)
characteristic_irats4_sign <- isolate(input$characteristic_irats4_sign)
characteristic_irats5_sign <- isolate(input$characteristic_irats5_sign)
characteristic_irats6_sign <- isolate(input$characteristic_irats6_sign)
industry <- isolate(input$industry)
})
for (x in ls(report.list)) if (is.null(get(x, report.list))) warning(paste0("parameter '", x, "' is NULL"), call.=FALSE, immediate.=TRUE)
save(report.list, file=report.data)
file.copy("toolreport.Rnw", report.source)
cat(paste0("load ('", report.data, "')\n"), file=report.script)
cat(paste0("knitr::knit2pdf('", report.source,"', quiet=TRUE)\n"), file=report.script, append=TRUE)
system(paste0("Rscript --vanilla ", report.script), wait=FALSE)
})
observe({
invalidateLater(1000, session)
toggleState("downloadReport", condition=file.exists(report.file))
})
dateInput("startdate", "Starting Date:",
value = min(BUYBACK_DATA_TOOL$Event.Date) - 10, min = min(BUYBACK_DATA_TOOL$Event.Date), max = max(BUYBACK_DATA_TOOL$Event.Date)-3*370,
startview = "year",
width='100%')
dateInput("enddate", "End Date (allow at least 3 years from the starting day you selected - else it will automatically use data up to 3 years after your start date):",
value = max(BUYBACK_DATA_TOOL$Event.Date) + 10,
min = min(BUYBACK_DATA_TOOL$Event.Date)+3*370,
max = max(BUYBACK_DATA_TOOL$Event.Date)+10,startview = "year",
width='100%')
selectInput("market_cap_min","Enter the Minimum Market Cap allowed (in millions):", choices = as.character(c(0,50*(1:20), 500*(1:20))), selected = "0", width = "1000px")
selectInput("market_cap_max","Enter the Maximum Market Cap allowed (in millions):", choices = as.character(c(0,50*(1:20), 500*(1:20), 10e10)), selected = as.character(10e10), width = "1000px")
selectInput("industry", "Select Industries to remove:", choices = unique(BUYBACK_DATA_TOOL$Industry_name),selected = NULL,multiple=TRUE,width="100%")
output$downloadReport <- downloadHandler(
filename = "report.pdf",
content = function(file) {
file.copy(report.file, file)
file.remove(list.files(pattern=paste0("session.", session$token)))
enable("compileReport")
disable("downloadReport")
}
)
```
```{r, eval=TRUE, echo = FALSE}
DATASET_NEW <- reactive({
input$computeButtonALL
input$computeButtonALL2
isolate({
starting = input$startdate
ending = input$enddate
if (ending - starting < 3*365)
ending = starting + 3*365
market_cap_min = as.numeric(input$market_cap_min)
market_cap_max = as.numeric(input$market_cap_max)
if (market_cap_max < market_cap_min)
market_cap_max = ceiling(max(BUYBACK_DATA_TOOL$Market.Cap))
useonly_industry = !(BUYBACK_DATA_TOOL$Industry_name %in% input$industry)
useonly_report = which(BUYBACK_DATA_TOOL$Event.Date >= starting & BUYBACK_DATA_TOOL$Event.Date <= ending &
scrub(BUYBACK_DATA_TOOL$Market.Cap) >= market_cap_min &
scrub(BUYBACK_DATA_TOOL$Market.Cap) <= market_cap_max &
useonly_industry)
# shiny seems to change the class of this matrix. needs investigation.
tmp = apply(returns_by_event_monthly[,useonly_report,drop=F], 2, function(r) as.numeric(r))
colnames(tmp) <- colnames(returns_by_event_monthly[,useonly_report,drop=F])
rownames(tmp) <- rownames(returns_by_event_monthly[,useonly_report,drop=F])
list(
BUYBACK_DATA_TOOL=BUYBACK_DATA_TOOL[useonly_report,],
returns_by_event_monthly = tmp,
DatesMonth = DatesMonth[,useonly_report],
value.weights = value.weights[useonly_report],
subset = useonly_report
)
})
})
```
```{r, fig.width=6, fig.height=5,echo=FALSE}
fluidPage(shiny::actionButton("computeButtonALL2","Update Results",icon=icon("spinner")) )
```
<hr>
### Descriptive Statistics
This tool allows the user to explore descriptive statistics of some of the key firm characteristics. When the name of the firm characteristics ends with ".Score" it is the percentile (0 to 1) relative to all firms in the CRSP universe at the time of the buyback announcement, as discussed in the paper. Otherwise it is the raw value of the firm characteristic.
<br>
```{r, eval=TRUE, echo = FALSE}
fluidPage(
selectInput("characteristic", "Select Firm Characteristic:", choices = acceptaple_features,selected = "EU.Index"),
mainPanel(
navlistPanel(
tabPanel("Histogram",
renderPlot({
feature = DATASET_NEW()$BUYBACK_DATA_TOOL[,which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic)]
feature = feature[!is.na(feature)]
if (!is.numeric(feature))
feature = 1
hist(feature, density = 100, breaks = 100)
})),
tabPanel("Summary Statistics",
renderDataTable({
feature = DATASET_NEW()$BUYBACK_DATA_TOOL[,which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic)]
feature = feature[!is.na(feature)]
if (length(unique(feature)) > 20 & is.numeric(feature)){
res = t(round(as.matrix(summary(feature)),2))
colnames(res) <- c("Minimum", "1st Quantile", "Median", "Mean", "3rd Quantile", "Max")
}
if (is.character(feature) | length(unique(feature)) <= 20){
tmp = table(feature)
res = t(as.matrix(tmp))
}
as.data.frame(res)
#m1<-gvisTable(show_data,options=list(showRowNumber=TRUE,width=1220, height=min(400,27*(nrow(show_data)+1)),allowHTML=TRUE,page='disable'))
#print(m1,'chart')
})
),
widths = c(3, 9)),
style='width: 100%;'))
```
<hr>
### Buybacks and Firm Characteristics
The article relates 5 firm characteristics (pre-buyback-announcement returns, idiosyncratic volatility, and volatility, as well as BE/ME and Firm Size). This tool allows the user to study the effects of combining any of these firm characteristics, as well as others not discussed in the paper. We consider here high/low events defined using the quantiles of the selected event charactetistic.
```{r, eval=TRUE, echo = FALSE}
selectInput("characteristic_single_analysis", "Select Firm Characteristic to Define High/Low Firms:", choices = acceptaple_features,selected = "EU.Index", width = "1000px")
selectInput("quantile_used","Enter the quantile to use to define High (>=) and Low (<=) Firms:", choices = 0.02*(1:20), selected = "0.1", width = "1000px")
checkboxInput("characteristic_single_analysis_sign", "If you would like to change the sign of the firm characteristic (Low will be High and vice versa), select here:", value = FALSE, width = "1000px")
feature_IRATStable <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonindi
isolate({
thesign = ifelse(input$characteristic_single_analysis_sign, -1, +1)
thefeature = thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
thefeatureQ = thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
quantile_used_ind = as.numeric(input$quantile_used)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),1-quantile_used_ind)
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),quantile_used_ind)
res = round(cbind(
car_table(DATASET_NEW()$returns_by_event_monthly[, Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[ Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results,
car_table(DATASET_NEW()$returns_by_event_monthly[, High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results
),2)[reported_times,]
colnames(res) <- c("Low: CAR", "t-stat","p-value", "High: CAR", "t-stat","p-value")
as.data.frame(res)
})
})
feature_CALtable <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonindi
isolate({
thesign = ifelse(input$characteristic_single_analysis_sign, -1, +1)
thefeature = thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
thefeatureQ = thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
quantile_used_ind = as.numeric(input$quantile_used)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),1-quantile_used_ind)
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),quantile_used_ind)
res = round(cbind(
calendar_table(DATASET_NEW()$returns_by_event_monthly[, Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[Low_feature_events])$results,
calendar_table(DATASET_NEW()$returns_by_event_monthly[,High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[High_feature_events])$results
),2)[reported_times,]
colnames(res) <- c("Low: CAL", "t-stat","p-value", "High: CAL", "t-stat","p-value")
as.data.frame(res)
})
})
High_feature_Hedged_react <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonindi
isolate({
thesign = ifelse(input$characteristic_single_analysis_sign, -1, +1)
thefeature = thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
thefeatureQ = thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
quantile_used_ind = as.numeric(input$quantile_used)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),1-quantile_used_ind)
High_feature <- apply(PNL_matrix_BB(start_date_event,"One.Year.After", High_feature_events, DATASET_NEW()$DatesMonth, DATASET_NEW()$returns_by_event_monthly,event=1),1,non_zero_mean)
remove_initialization_time(suppressWarnings(scrub(alpha_lm(High_feature,Risk_Factors_Monthly[,pnl_hedge_factors],hedge_months,trade=1))),min_date=FirstTrade)
})
})
Low_feature_Hedged_react <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonindi
isolate({
thesign = ifelse(input$characteristic_single_analysis_sign, -1, +1)
thefeature = thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
thefeatureQ = thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_single_analysis)]]
quantile_used_ind = as.numeric(input$quantile_used)
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= quantile(scrub(thefeatureQ[!is.na(thefeatureQ)]),quantile_used_ind)
Low_feature <- apply(PNL_matrix_BB(start_date_event,"One.Year.After", Low_feature_events, DATASET_NEW()$DatesMonth, DATASET_NEW()$returns_by_event_monthly,event=1),1,non_zero_mean)
remove_initialization_time(suppressWarnings(scrub(alpha_lm(Low_feature,Risk_Factors_Monthly[,pnl_hedge_factors],hedge_months,trade=1))),min_date=FirstTrade)
})
})
```
<br>
```{r, fig.width=6, fig.height=5,echo=FALSE}
fluidPage(shiny::actionButton("computeButtonindi","Update Results",icon=icon("spinner")) )
```
<br>
```{r, eval=TRUE, echo = FALSE}
fluidPage(
mainPanel(
navlistPanel(
tabPanel("Five-Factor IRATS Cumulative Abnormal Returns",
renderTable({
feature_IRATStable()
})),
tabPanel("Five-Factor Calendar Method Monthly Abnormal Returns",
renderTable({
feature_CALtable()
})),
tabPanel("Cumulative Abnormal Returns,High, 12m hold",
renderPlot({
pnl_plot(High_feature_Hedged_react())
})),
tabPanel("Cumulative Abnormal Returns,Low, 12m hold",
renderPlot({
pnl_plot(Low_feature_Hedged_react())
})),
tabPanel("Monthly and Yearly Returns, High, 12m hold",
renderUI(
HTML(renderHeatmapX(pnl_matrix(High_feature_Hedged_react())))
)),
tabPanel("Monthly and Yearly Returns, Low, 12m hold",
renderUI(
HTML(renderHeatmapX(pnl_matrix(Low_feature_Hedged_react())))
)),
widths = c(3, 9)),style='width: 100%;'))
```
<hr>
### The EU-Index
For the subset of events selected the High/Low EU index events (for the selected EU thresholds below - you may need to change them depending on the sample of events used) have these abnormal returns:
<br>
```{r, eval=TRUE, echo = FALSE}
selectInput("high_EU_index_thres","Enter the EU index threshold above which (>=) we define the High EU-Index firms (need minimum 10 firms High EU firms):", choices = sort(unique(BUYBACK_DATA_TOOL$EU.Index)), selected = "5", width = "1000px")
```
```{r, eval=TRUE, echo = FALSE}
selectInput("low_EU_index_thres","Enter the EU index threshold below which (<=) we define the Low EU-Index firms (need minimum 10 firms Low EU firms):", choices = sort(unique(BUYBACK_DATA_TOOL$EU.Index)), selected = "1", width = "1000px")
```
<br>
```{r, fig.width=6, fig.height=5,echo=FALSE}
fluidPage(shiny::actionButton("computeButtonEU","Update Results",icon=icon("spinner")) )
```
<br>
```{r, eval=TRUE, echo = FALSE}
EU_index_table <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonEU
isolate({
thefeature = DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == "EU.Index")]]
res = matrix(table(thefeature),nrow=1)
colnames(res) <- paste("EU Index", names(table(thefeature)), sep=": ")
rownames(res) <- "# of Events"
res
})
})
feature_IRATStable_industry <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonEU
isolate({
thefeature = DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == "EU.Index")]]
high_EU_index_thres = as.numeric(input$high_EU_index_thres)
low_EU_index_thres = as.numeric(input$low_EU_index_thres)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= high_EU_index_thres
if (sum(High_feature_events) < 10)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= high_EU_index_thres-1
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= low_EU_index_thres
if (sum(Low_feature_events) < 10)
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= Low_feature_events+1
res = round(cbind(
car_table(DATASET_NEW()$returns_by_event_monthly[,Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results,
car_table(DATASET_NEW()$returns_by_event_monthly[,High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results
),2)[reported_times,]
colnames(res) <- c("Low EU: CAR", "t-stat","p-value", "High EU: CAR", "t-stat","p-value")
as.data.frame(res)
})
})
feature_CALtable_industry <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonEU
isolate({
thefeature = DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == "EU.Index")]]
high_EU_index_thres = as.numeric(input$high_EU_index_thres)
low_EU_index_thres = as.numeric(input$low_EU_index_thres)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= high_EU_index_thres
if (sum(High_feature_events) < 10)
High_feature_events = !is.na(thefeature) & scrub(thefeature) >= high_EU_index_thres-1
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= low_EU_index_thres
if (sum(Low_feature_events) < 10)
Low_feature_events = !is.na(thefeature) & scrub(thefeature) <= Low_feature_events+1
res = round(cbind(
calendar_table(DATASET_NEW()$returns_by_event_monthly[,Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[Low_feature_events])$results,
calendar_table(DATASET_NEW()$returns_by_event_monthly[,High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[High_feature_events])$results
),2)[reported_times,]
colnames(res) <- c("Low EU: CAL", "t-stat","p-value", "High EU: CAL", "t-stat","p-value")
as.data.frame(res)
})
})
fluidPage(
mainPanel(
navlistPanel(
tabPanel("Number of Firms per EU Index Value",
renderTable({
EU_index_table()
})),
tabPanel("Five-Factor IRATS Cumulative Abnormal Returns",
renderTable({
feature_IRATStable_industry()
})),
tabPanel("Five-Factor Calendar Method Monthly Abnormal Returns",
renderTable({
feature_CALtable_industry()
})),
widths = c(3, 9)),style='width: 100%;'))
```
<hr>
### Customized Buyback Indices
Much like the EU-index in the paper, one can create other indices by combining different firm characteristics as needed. You can select your own firm characteristics below and also indicate whether you would like to reverse the sign of this firm characteristic (Low will be High and vice versa).
<br>
```{r, eval=TRUE, echo = FALSE}
fluidPage(
h4("Firm Characteristics of the new index"),
fluidRow(
column(6,
selectInput("characteristic_irats1", "First Firm Characteristic:", choices = acceptaple_features,selected = "EU.Index", width = "425px"),
checkboxInput("characteristic_irats1_sign", "Reverse", value = FALSE),
selectInput("characteristic_irats2", "Second Firm Characteristic:", choices = acceptaple_features,selected ="None", width = "425px"),
checkboxInput("characteristic_irats2_sign", "Reverse", value = FALSE),
selectInput("characteristic_irats3", "Third Firm Characteristic:", choices = acceptaple_features,selected = "None", width = "425px"),
checkboxInput("characteristic_irats3_sign", "Reverse", value = FALSE)
),
column(6,
selectInput("characteristic_irats4", "Fourth Firm Characteristic:", choices = acceptaple_features,selected = "None", width = "425px"),
checkboxInput("characteristic_irats4_sign", "Reverse", value = FALSE),
selectInput("characteristic_irats5", "Fifth Firm Characteristic:", choices = acceptaple_features,selected = "None", width = "425px"),
checkboxInput("characteristic_irats5_sign", "Reverse", value = FALSE),
selectInput("characteristic_irats6", "Sixth Firm Characteristic:", choices = acceptaple_features,selected = "None", width = "425px"),
checkboxInput("characteristic_irats6_sign", "Reverse", value = FALSE)
)
)
)
```
<br>
```{r, eval=TRUE, echo = FALSE}
selectInput("quantile_used_ind","Enter the quantile to use to define the 0 (Low, <=), 1 (middle), 2 (High, >=) scores for each of the selected characteristics:", choices = 0.02*(1:20), selected = "0.1", width = "1000px")
```
<br>
```{r, eval=TRUE, echo = FALSE}
selectInput("quantile_used_all","Enter the quantile to use to define High (>=) and Low (<=) Firms for the total index created (sum of the scores of the firm characteristics selected):", choices = 0.02*(1:20), selected = "0.1", width = "1000px")
```
<br>
```{r, fig.width=6, fig.height=5,echo=FALSE}
fluidPage(shiny::actionButton("computeButtonCU","Update Results",icon=icon("spinner")) )
```
<br>
```{r, eval=TRUE, echo = FALSE}
selected_features = reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
paste(setdiff(unique(c(input$characteristic_irats1,input$characteristic_irats2,input$characteristic_irats3,input$characteristic_irats4,input$characteristic_irats5,input$characteristic_irats6)), "None"), sep=",")
})
})
```
<br>
<br>
Here are the results for your new customized index:
<br>
```{r, eval=TRUE, echo = FALSE}
Index_Score_rect <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
thesign = ifelse(input$characteristic_irats1_sign, -1, +1)
thefeature1 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats1)]]
thefeature1Q = (thesign==-1) + thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_irats1)]]
High_feature_events1 = (scrub(thefeature1) >= quantile(thefeature1Q[!is.na(thefeature1Q)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature1))
Low_feature_events1 = (scrub(thefeature1) <= quantile(thefeature1Q[!is.na(thefeature1Q)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature1))
thefeature2 <- thefeature3 <- thefeature4 <- thefeature5 <- thefeature6 <- rep(0,length(High_feature_events1))
High_feature_events2 <- High_feature_events3 <- High_feature_events4 <- High_feature_events5 <- High_feature_events6 <- rep(FALSE,length(High_feature_events1))
Low_feature_events2 <- Low_feature_events3 <- Low_feature_events4 <- Low_feature_events5 <- Low_feature_events6 <-
rep(FALSE,length(Low_feature_events1))
if (input$characteristic_irats2 != "None"){
thesign = ifelse(input$characteristic_irats2_sign, -1, +1)
thefeature2 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats2)]]
thefeature2Q = (thesign==-1) + thesign*BUYBACK_DATA_TOOL[[which(names(BUYBACK_DATA_TOOL) == input$characteristic_irats2)]]
High_feature_events2 = (scrub(thefeature2) >= quantile(thefeature2Q[!is.na(thefeature2Q)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature2))
Low_feature_events2 = (scrub(thefeature2) <= quantile(thefeature2Q[!is.na(thefeature2Q)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature2))
}
if (input$characteristic_irats3 != "None"){
thesign = ifelse(input$characteristic_irats3_sign, -1, +1)
thefeature3 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats3)]]
High_feature_events3 = (scrub(thefeature3) >= quantile(thefeature3[!is.na(thefeature3)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature3))
Low_feature_events3 = (scrub(thefeature3) <= quantile(thefeature3[!is.na(thefeature3)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature3))
}
if (input$characteristic_irats4 != "None"){
thesign = ifelse(input$characteristic_irats4_sign, -1, +1)
thefeature4 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats4)]]
High_feature_events4 = (scrub(thefeature4) >= quantile(thefeature4[!is.na(thefeature4)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature4))
Low_feature_events4 = (scrub(thefeature4) <= quantile(thefeature4[!is.na(thefeature4)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature4))
}
if (input$characteristic_irats5 != "None"){
thesign = ifelse(input$characteristic_irats5_sign, -1, +1)
thefeature5 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats5)]]
High_feature_events5 = (scrub(thefeature5) >= quantile(thefeature5[!is.na(thefeature5)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature5))
Low_feature_events5 = (scrub(thefeature5) <= quantile(thefeature5[!is.na(thefeature5)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature5))
}
if (input$characteristic_irats6 != "None"){
thesign = ifelse(input$characteristic_irats6_sign, -1, +1)
thefeature6 = (thesign==-1) + thesign*DATASET_NEW()$BUYBACK_DATA_TOOL[[which(names(DATASET_NEW()$BUYBACK_DATA_TOOL) == input$characteristic_irats6)]]
High_feature_events6 = (scrub(thefeature5) >= quantile(thefeature5[!is.na(thefeature5)],1-as.numeric(input$quantile_used_ind)) & !is.na(thefeature5))
Low_feature_events6 = (scrub(thefeature5) <= quantile(thefeature5[!is.na(thefeature5)],as.numeric(input$quantile_used_ind)) & !is.na(thefeature5))
}
Index_score =
2*High_feature_events1 + 1*(!High_feature_events1 & !Low_feature_events1) +
(input$characteristic_irats2 != "None")*(2*High_feature_events2 + 1*(!High_feature_events2 & !Low_feature_events2) ) +
(input$characteristic_irats3 != "None")*(2*High_feature_events3 + 1*(!High_feature_events3 & !Low_feature_events3) ) +
(input$characteristic_irats4 != "None")*(2*High_feature_events4 + 1*(!High_feature_events4 & !Low_feature_events4) ) +
(input$characteristic_irats5 != "None")*(2*High_feature_events5 + 1*(!High_feature_events5 & !Low_feature_events5) ) +
(input$characteristic_irats6 != "None")*(2*High_feature_events6 + 1*(!High_feature_events6 & !Low_feature_events6) )
Index_score
})
})
feature_IRATStable_index <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
thefeature = Index_Score_rect()
High_feature_events = (scrub(thefeature) >= quantile(thefeature[!is.na(thefeature)],1-as.numeric(input$quantile_used_all)) & !is.na(thefeature))
Low_feature_events = (scrub(thefeature) <= quantile(thefeature[!is.na(thefeature)],as.numeric(input$quantile_used_all)) & !is.na(thefeature))
res = round(cbind(
car_table(DATASET_NEW()$returns_by_event_monthly[, Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[ Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results,
car_table(DATASET_NEW()$returns_by_event_monthly[, High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model)$results
),2)[reported_times,]
colnames(res) <- c("Low: CAR", "t-stat","p-value", "High: CAR", "t-stat","p-value")
res
})
})
feature_CALtable_index <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
thefeature = Index_Score_rect()
High_feature_events = (scrub(thefeature) >= quantile(thefeature[!is.na(thefeature)],1-as.numeric(input$quantile_used_all)) & !is.na(thefeature))
Low_feature_events = (scrub(thefeature) <= quantile(thefeature[!is.na(thefeature)],as.numeric(input$quantile_used_all)) & !is.na(thefeature))
res = round(cbind(
calendar_table(DATASET_NEW()$returns_by_event_monthly[, Low_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[Low_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[Low_feature_events])$results,
calendar_table(DATASET_NEW()$returns_by_event_monthly[,High_feature_events],
DATASET_NEW()$BUYBACK_DATA_TOOL$Event.Date[High_feature_events],Risk_Factors_Monthly,formula_used = five_factor_model, value.weights = DATASET_NEW()$value.weights[High_feature_events])$results
),2)[reported_times,]
colnames(res) <- c("Low: CAL", "t-stat","p-value", "High: CAL", "t-stat","p-value")
res
})
})
High_feature_Hedged_react_index <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
thefeature = Index_Score_rect()
High_feature_events = which(scrub(thefeature) >= quantile(thefeature[!is.na(thefeature)],1-as.numeric(input$quantile_used_all)) & !is.na(thefeature))
High_feature <- apply(PNL_matrix_BB(start_date_event,"One.Year.After", High_feature_events, DATASET_NEW()$DatesMonth, DATASET_NEW()$returns_by_event_monthly,event=1),1,non_zero_mean)
remove_initialization_time(suppressWarnings(scrub(alpha_lm(High_feature,Risk_Factors_Monthly[,pnl_hedge_factors],hedge_months,trade=1))),min_date=FirstTrade)
})
})
Low_feature_Hedged_react_index <- reactive({
input$computeButtonALL
input$computeButtonALL2
input$computeButtonCU
isolate({
thefeature = Index_Score_rect()
Low_feature_events = which(scrub(thefeature) <= quantile(thefeature[!is.na(thefeature)],as.numeric(input$quantile_used_all)) & !is.na(thefeature))
Low_feature <- apply(PNL_matrix_BB(start_date_event,"One.Year.After", Low_feature_events, DATASET_NEW()$DatesMonth, DATASET_NEW()$returns_by_event_monthly,event=1),1,non_zero_mean)
remove_initialization_time(suppressWarnings(scrub(alpha_lm(Low_feature,Risk_Factors_Monthly[,pnl_hedge_factors],hedge_months,trade=1))),min_date=FirstTrade)
})
})
```
```{r, eval=TRUE, echo = FALSE}
fluidPage(
mainPanel(
navlistPanel(
tabPanel("Histogram of the New Index",
renderPlot({
feature = Index_Score_rect()
feature = feature[!is.na(feature)]
if (!is.numeric(feature))
feature = 1
hist(feature, density = 100, breaks = 20,main="Index Histogram",xlab="Score")
})),
tabPanel("Five-Factor IRATS Cumulative Abnormal Returns",
renderTable({
feature_IRATStable_index()
})),
tabPanel("Five-Factor Calendar Method Monthly Abnormal Returns",
renderTable({
feature_CALtable_index()
})),
tabPanel("Cumulative Abnormal Returns,High, 12m hold",
renderPlot({
pnl_plot(High_feature_Hedged_react_index())
})),
tabPanel("Cumulative Abnormal Returns,Low, 12m hold",
renderPlot({
pnl_plot(Low_feature_Hedged_react_index())
})),
tabPanel("Monthly and Yearly Returns, High, 12m hold",
renderUI(
HTML(renderHeatmapX(pnl_matrix(High_feature_Hedged_react_index())))
)),
tabPanel("Monthly and Yearly Returns, Low, 12m hold",
renderUI(
HTML(renderHeatmapX(pnl_matrix(Low_feature_Hedged_react_index())))
)),
widths = c(3, 9)),style='width: 100%;'))
```
<br>
<hr>
As noted above **you can interactively change various report parameters throughout this tool, and for any of your choices create a customized paper using the button at the begining of this page at any time.**
<br>
<hr>
<br>
<br>
<br>