-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprocess_data_for_paper.R
1253 lines (1059 loc) · 47.1 KB
/
process_data_for_paper.R
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
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2015, INSEAD
# by T. Evgeniou, Enric Junque de Fortuny, Nick Nassuphis, Theo Vermaelen
# Dual licensed under the MIT or GPL Version 2 licenses.
# NOTE: These data files need to be available:
# 1) GENERATED BY create_bbissuers_data.R:
# "../FinanceData/created_projects_datasets/BUYBACKS.Rdata"
# 2) from http://www.saif.sjtu.edu.cn/facultylist/yyuan/Misp_Score.csv
# "../FinanceData/rawdata_stambaugh_mispricing_index/Stambaugh_Mispricing_Score.csv"
# which (see below) generates "../FinanceData/created_projects_datasets/StambaughBUYBACKS.Rdata"
# ""../FinanceData/created_projects_datasets/Buybacks.Institutional.number.Rdata" created below
##########################################################################################
# These are all the tables used in the .Rnw for the paper
##########################################################################################
rm(list=ls()) # Clean up the memory, if we want to rerun from scratch
source("helpers/lib_helpers.R", chdir=TRUE)
source("helpers/latex_code.R")
source("helpers/ff_industries_sic.R")
source("Paper_global_parameters.R")
# takes time to save and load, so we save only what is needed at the end.
initial_vars = ls(all = TRUE)
##########################################################################################
# FILE LOCATIONS
##########################################################################################
buybacks_data_location = "../FinanceData/created_projects_datasets/BUYBACKS.Rdata"
Stambaugh_data_location = "../FinanceData/rawdata_stambaugh_mispricing_index/Stambaugh_Mispricing_Score.csv"
Stambaugh_buybacks_data_location = "../FinanceData/created_projects_datasets/StambaughBUYBACKS.Rdata"
mispricing_factors_data_location = "../FinanceData/rawdata_indices_and_factors/M4.csv"
q_factors_data_location = "../FinanceData/rawdata_indices_and_factors/qfactors.csv"
buybacks_institutional_data_location = "../FinanceData/created_projects_datasets/Buybacks.Institutional.number.Rdata"
##########################################################################################
# HELPER FUNCTIONS
##########################################################################################
# Assumes a date string formatted as yyyy-mm-dd
date_str_to_yyyy_mm <- function(date_str) {
return(str_sub(date_str, start=1, end=7))
}
##########################################################################################
# GET THE DATA THAT WAS GENERATED BY create_bbissuers_data.R
##########################################################################################
load(buybacks_data_location)
# All the data filters are done in here - in case we want to change them for the paper
source("filter_data_for_paper.R")
dataset_names = c("buybacks", "issuers")
dataset_codes = c("bb", "iss")
# dataset_name can be either "buybacks" or "issuers"
add_dates <- function(dataset_name) {
x = get_data(dataset_name)
# We don't need this any more, can simplify to only get the dates needed...
# it's ok for now, as it is now slow
x$DATASET$DatesMonth = create_dates_month(
x$DATASET$SDC$Event.Date, rownames(x$Risk_Factors_Monthly))
colnames(x$DATASET$DatesMonth) = x$DATASET$SDC$permno
return(x)
}
BUYBACK_DATA = add_dates("buybacks")
ISSUERS_DATA = add_dates("issuers")
##########################################################################################
value_weights = list()
for (dataset_code in dataset_codes) {
market_cap = get_data(dataset_code)$DATASET$CRSP$Market.Cap
if (do.value.weight) {
value_weights[[dataset_code]] = market_cap
} else {
value_weights[[dataset_code]] = rep(1, length(market_cap))
}
}
##########################################################################################
# GET THE STAMBAUGH-YUAN MISPRICING DATA
##########################################################################################
# This is slow
if (do_Stambaugh_calculation) {
Stambaugh_data = read.csv(Stambaugh_data_location, sep=",")
Stambaugh_data$yyyymm = paste(str_sub(Stambaugh_data$yyyymm, start=1, end=4),
str_sub(Stambaugh_data$yyyymm, start=5, end=6),
sep="-")
get_stambaugh_data_for_dataset <- function(dataset_name, last_month=FALSE) {
x = get_data(dataset_name)$DATASET$SDC
if (last_month) {
event_yyyymm = date_str_to_yyyy_mm(AddMonths(x$Event.Date[i], -1))
} else {
event_yyyymm = date_str_to_yyyy_mm(x$Event.Date[i])
}
sapply(seq_along(x$CUSIP), function(i) {
getid=which(Stambaugh_data$permno == x$permno[i] &
Stambaugh_data$yyyymm == event_yyyymm)
ifelse(length(getid)== 1, Stambaugh_data$MISP[getid], NA)
})
}
StambaughBB = get_stambaugh_data_for_dataset("buybacks", last_month=FALSE)
StambaughBB_lastmonth = get_stambaugh_data_for_dataset("buybacks", last_month=TRUE)
StambaughISS = get_stambaugh_data_for_dataset("issuers", last_month=FALSE)
StambaughISS_lastmonth = get_stambaugh_data_for_dataset("issuers", last_month=TRUE)
save(StambaughBB, StambaughISS, StambaughBB_lastmonth, StambaughISS_lastmonth,
file=Stambaugh_buybacks_data_location)
}
load(Stambaugh_buybacks_data_location)
BUYBACK_DATA$DATASET$Stambaugh = StambaughBB_lastmonth
ISSUERS_DATA$DATASET$Stambaugh = StambaughISS_lastmonth
##########################################################################################
# THE RISK FACTORS
##########################################################################################
Risk_Factors_Monthly = BUYBACK_DATA$Risk_Factors_Monthly
Market_Monthly = BUYBACK_DATA$Market_Monthly
# Mispricing factors
if (use_mispricing_factors) {
misprice_factors = read.csv(mispricing_factors_data_location, sep=",", dec=".")
factor_dates = as.Date(paste0(misprice_factors$YYYYMM, "01"), format="%Y%m%d")
rownames(misprice_factors) = as.character(factor_dates)
# Get only the factor columns, i.e. exclude the YYYYMM column
misprice_factors = misprice_factors[, c("MKTRF", "SMB", "MGMT", "PERF", "RF")]
use_only = which(date_str_to_yyyy_mm(rownames(misprice_factors)) %in%
date_str_to_yyyy_mm(rownames(Risk_Factors_Monthly)))
misprice_factors = misprice_factors[use_only,]
# This line does not seem to be doing anything
# sum(str_sub(rownames(misprice_factors), start=1, end=7) !=
# str_sub(rownames(Risk_Factors_Monthly), start=1, end=7))
rownames(misprice_factors) = rownames(Risk_Factors_Monthly)
# This line does not seem to be doing anything
# max(abs(misprice_factors$MKTRF[(misprice_factors$MKTRF != Risk_Factors_Monthly$Delta)]-
# Risk_Factors_Monthly$Delta[(misprice_factors$MKTRF != Risk_Factors_Monthly$Delta)]))
names(misprice_factors)[which(names(misprice_factors) == "SMB")] = "SMB2"
misprice_factors = cbind(misprice_factors,
Risk_Factors_Monthly[, c("HML", "RMW", "CMA", "SMB")])
names(misprice_factors)[which(names(misprice_factors) == "MKTRF")] = "Delta"
Risk_Factors_Monthly = misprice_factors
three_factor_model="(ri - RF) ~ Delta + SMB2 + MGMT + PERF"
five_factor_model = "(ri - RF) ~ Delta + SMB + HML + RMW + CMA"
misprice_factors_irats_MKT_HML_ME_IA_ROE = car_table(
BUYBACK_DATA$DATASET$returns_by_event_monthly,
BUYBACK_DATA$DATASET$SDC$Event.Date,
Risk_Factors_Monthly,
formula_used=three_factor_model)$results
misprice_factors_irats_MKT_HML_ME_IA_ROE =
misprice_factors_irats_MKT_HML_ME_IA_ROE[reported_times,]
} else {
three_factor_model="(ri - RF) ~ Delta + SMB + HML"
five_factor_model = "(ri - RF) ~ Delta + SMB + HML + RMW + CMA"
}
# q-factors test
if (use_q_factors) {
qfactors = read.csv(q_factors_data_location, sep=";", dec=",")
rownames(qfactors) = paste(qfactors[, "Year"], sprintf("%02d", qfactors[, "Month"]), sep="-")
use_only = which(rownames(qfactors) %in% date_str_to_yyyy_mm(rownames(Risk_Factors_Monthly)))
qfactors = qfactors[use_only,]
qfactors = qfactors[, c("MKT", "ME", "I.A", "ROE")]
# If read.csv is used with dec="," this line is not needed
# qfactors = apply(qfactors, 2, function(r) as.numeric(str_replace(r,",",".")))
qfactors = qfactors / 100
rownames(qfactors) = rownames(Risk_Factors_Monthly)[
match(rownames(qfactors), date_str_to_yyyy_mm(rownames(Risk_Factors_Monthly)))]
qfactors = cbind(qfactors,
Risk_Factors_Monthly[rownames(qfactors), c("SMB", "HML","RF","RMW","CMA")])
Risk_Factors_Monthly = qfactors
formula_used="(ri - RF) ~ MKT + HML + ME + I.A + ROE"
qfactors_irats_MKT_HML_ME_IA_ROE = car_table(
BUYBACK_DATA$DATASET$returns_by_event_monthly,
BUYBACK_DATA$DATASET$SDC$Event.Date,
qfactors,
formula_used=formula_used)$results
qfactors_irats_MKT_HML_ME_IA_ROE = qfactors_irats_MKT_HML_ME_IA_ROE[reported_times,]
}
##########################################################################################
# PREPARE ALL VARIABLES
# Some event categories (all T/F vectors)
# Common event catagories for both buybacks and issuers
eu_index = list()
Idiosyncr_events = list()
VOL_events = list()
company_subset = list()
stam_events = list()
for (code in c("bb", "iss")) {
data = get_data(code)
rsq_score = data$DATASET$CRSP$Rsq_score
Idiosyncr_events[[code]]$highidio = rsq_score < quantile(rsq_score, quantile_simple)
Idiosyncr_events[[code]]$lowidio = rsq_score > quantile(rsq_score, 1 - quantile_simple)
rm(rsq_score)
pre_vol_score = data$DATASET$CRSP$pre_vol_Score
VOL_events[[code]]$highvol = pre_vol_score > quantile(pre_vol_score, 1 - quantile_simple)
VOL_events[[code]]$lowvol = pre_vol_score < quantile(pre_vol_score, quantile_simple)
rm(pre_vol_score)
val_ind = data$Valuation_Index
company_subset[[code]]$undervalued = val_ind > quantile(val_ind, 1 - quantile_simple)
company_subset[[code]]$overvalued = val_ind < quantile(val_ind, quantile_simple)
rm(val_ind)
stam = data$DATASET$Stambaugh
stam_events[[code]]$high = !is.na(stam) & (stam > quantile(stam[!is.na(stam)], 1 - quantile_simple))
stam_events[[code]]$low = !is.na(stam) & (stam < quantile(stam[!is.na(stam)], quantile_simple))
rm(stam)
eu_index[[code]] = sapply(1:length(data$DATASET$SDC$Event.Date), function(i) {
ifelse(Idiosyncr_events[[code]]$highidio[i], 2, ifelse(Idiosyncr_events[[code]]$lowidio[i], 0, 1)) +
ifelse(VOL_events[[code]]$highvol[i], 2, ifelse(VOL_events[[code]]$lowvol[i], 0, 1)) +
ifelse(company_subset[[code]]$undervalued[i], 2, ifelse(company_subset[[code]]$overvalued[i], 0, 1))
})
}
lev_events = list()
lt_lte = BUYBACK_DATA$DATASET$CRSP$leverage_lt_over_lt_plus_e
lev_events$bb$high = scrub(lt_lte) > quantile(lt_lte[!is.na(lt_lte)], 1 - quantile_simple) & !is.na(lt_lte)
lev_events$bb$low = scrub(lt_lte) < quantile(lt_lte[!is.na(lt_lte)], quantile_simple) & !is.na(lt_lte)
rm(lt_lte)
eps_events = list()
rec_score = BUYBACK_DATA$DATASET$ibes$month_minus1$mean_rec_score
eps_events$bb$high = scrub(rec_score) > quantile(rec_score[!is.na(rec_score)], 1 - quantile_simple) & !is.na(rec_score)
eps_events$bb$low = scrub(rec_score) < quantile(rec_score[!is.na(rec_score)], quantile_simple) & !is.na(rec_score)
rm(rec_score)
BUYBACK_DATA$EU_index = sapply(1:length(BUYBACK_DATA$DATASET$SDC$Event.Date), function(i) {
ifelse(Idiosyncr_events$bb$highidio[i], 2, ifelse(Idiosyncr_events$bb$lowidio[i], 0, 1)) +
ifelse(VOL_events$bb$highvol[i], 2, ifelse(VOL_events$bb$lowvol[i], 0, 1)) +
ifelse(company_subset$bb$undervalued[i], 2, ifelse(company_subset$bb$overvalued[i], 0, 1))
})
high_EU_bb = BUYBACK_DATA$EU_index >= quantile(BUYBACK_DATA$EU_index,0.8)
low_EU_bb = BUYBACK_DATA$EU_index <= quantile(BUYBACK_DATA$EU_index,0.2)
buybacks.events.past2years = 1 * (BUYBACK_DATA$DATASET$CRSP$buybacks_events_past2years !=0)
# Recommendation score: 1. Strong Buy, 2. Buy, 3. Hold, 4. Underperform, 5. Sell
mm1 = BUYBACK_DATA$DATASET$ibes$month_minus1$mean_rec
mm2 = BUYBACK_DATA$DATASET$ibes$month_minus2$mean_rec
downgraded_events = !is.na(mm1) & !is.na(mm2) & scrub(mm1) > scrub(mm2)
not_downgraded_events = !is.na(mm1) & !is.na(mm2) & scrub(mm1) <= scrub(mm2)
upgraded_events = !is.na(mm1) & !is.na(mm2) & scrub(mm1) < scrub(mm2)
rm(mm1, mm2)
#### Continuous variables now
valuation_index_bb = BUYBACK_DATA$Valuation_Index
Firm_size = BUYBACK_DATA$DATASET$CRSP$Market.Cap
Firm_size_score = BUYBACK_DATA$DATASET$CRSP$Market.Cap_score
Prior_R = BUYBACK_DATA$DATASET$CRSP$recent_performance
Prior_R_score = BUYBACK_DATA$DATASET$CRSP$recent_performance_score
BEME = BUYBACK_DATA$DATASET$CRSP$BE.ME
BEME_score = BUYBACK_DATA$DATASET$CRSP$BE.ME_score
U_index = BUYBACK_DATA$Valuation_Index
EU_index = BUYBACK_DATA$EU_index
Vol_raw = BUYBACK_DATA$DATASET$CRSP$pre_vol
Vol_raw_score = BUYBACK_DATA$DATASET$CRSP$pre_vol_Score
Idiosyncratic = BUYBACK_DATA$DATASET$CRSP$IVOL
Idiosyncratic_score = BUYBACK_DATA$DATASET$CRSP$IVOL_score
One_m_Rsqr = 1 - BUYBACK_DATA$DATASET$CRSP$Rsq
One_m_Rsqr_score = 1 - BUYBACK_DATA$DATASET$CRSP$Rsq_score
StambaughBB = BUYBACK_DATA$DATASET$Stambaugh
Analyst_coverage = BUYBACK_DATA$DATASET$ibes$month_minus1$analyst_coverage
Event.Size = BUYBACK_DATA$DATASET$SDC$Event.Size
buybacks.events.past2years = 1 * (BUYBACK_DATA$DATASET$CRSP$buybacks_events_past2years !=0)
Total.Payout = (BUYBACK_DATA$DATASET$CRSP$Total_Payout)
lagged.dividend.payout.ratio = BUYBACK_DATA$DATASET$CRSP$divident_payout_ratio
lagged.dividend.payout.ratio[
scrub(lagged.dividend.payout.ratio) < 0 |
scrub(lagged.dividend.payout.ratio) > 100] = NA
lagged.dividend.payout.ratio = lagged.dividend.payout.ratio
Leverage = BUYBACK_DATA$DATASET$CRSP$leverage_d_over_d_plus_e
operating.income = BUYBACK_DATA$DATASET$CRSP$operating_income
std.operating.income = BUYBACK_DATA$DATASET$CRSP$std_operating_income
non.operating.income = BUYBACK_DATA$DATASET$CRSP$non_operating_income
liquid.assets = BUYBACK_DATA$DATASET$CRSP$liquid_assets
price.earnings.ratio = BUYBACK_DATA$DATASET$CRSP$price_earnings_ratio
capital.expenditures = BUYBACK_DATA$DATASET$CRSP$capital_expenditures
profitability = BUYBACK_DATA$DATASET$CRSP$profitability
net_debt = BUYBACK_DATA$DATASET$CRSP$net_debt
tax_rate = BUYBACK_DATA$DATASET$CRSP$tax_rate
if (0) {
# Institutional - still not standard across projects
Institutional = sapply(1:length(BUYBACK_DATA$DATASET$SDC$CUSIP), function(i) {
tmp = BUYBACK_DATA$DATASET$institutional$Institutional.Ownership.Ratio.1_score[[i]]
useonly = which(AddMonths(as.Date(paste(names(tmp),"01", sep="-")),1) < BUYBACK_DATA$DATASET$SDC$Event.Date[i])
tmp = tmp[useonly]
ifelse(sum(!is.na(tmp)), tail(tmp[!is.na(tmp)],1), NA)
})
Institutional[scrub(Institutional) >= 100] <- NA
Institutional.number = sapply(1:length(BUYBACK_DATA$DATASET$SDC$CUSIP), function(i) {
tmp = BUYBACK_DATA$DATASET$institutional$num.institutional.investors_score[[i]]
useonly = which(AddMonths(as.Date(paste(names(tmp),"01", sep="-")),1) < BUYBACK_DATA$DATASET$SDC$Event.Date[i])
tmp = tmp[useonly]
ifelse(sum(!is.na(tmp)), tail(tmp[!is.na(tmp)],1), NA)
})
Institutional.number[Institutional >= 100] <- NA
save(Institutional,Institutional.number, file=buybacks_institutional_data_location)
} else {
load(buybacks_institutional_data_location)
}
# THESE ARE THE VARIABLES WE USE IN THE DATA SUMMARY STATS
all_characteristics_continuous_summary = cbind(
buybacks.events.past2years,
Firm_size,
100 * Prior_R,
BEME,
U_index,
EU_index,
100 * Vol_raw,
One_m_Rsqr,
StambaughBB,
Event.Size,
Analyst_coverage,
Total.Payout,
lagged.dividend.payout.ratio,
Leverage,
profitability,
net_debt,
tax_rate,
operating.income,
std.operating.income,
non.operating.income,
liquid.assets,
price.earnings.ratio,
capital.expenditures,
Institutional,
Institutional.number
)
colnames(all_characteristics_continuous_summary) = c(
"Announced Repurchace in Previous 2 Years (0/1)",
"Market Cap. (Score)",
"Prior Returns (Score)",
"BE/ME (Score)",
"U-index",
"EU-index",
"Volatility (Score)",
"One minus Rsq (Score)",
"Mispricing Measure",
"Percent Shares",
"Analyst Coverage (Score)",
"Total Payout in Event Year before Event",
"Lag Dividend Payout Ratio",
"Leverage",
"Profitability (ROA)",
"Net Debt",
"Tax Rate",
"Operating Income (Percent assets)",
"std Operating Income",
"Non-Operating Income (Percent assets)",
"Liquid Assets (Percent assets)",
"Price/Earnings Ratio",
"Capital Expenditures (Percent assets)",
"Institutional Holdings (Score)",
"Number of Institutions (Score)"
)
##########################################################################################
# THIS IS WHERE THE VARIABLES FOR THE PAPER TABLES AND FIGURES ARE GENERATED
##########################################################################################
# Note: Groups of tables in terms of similarity:
# 1) II, III, IV, VI, and VII (VI and VII are almost identical)
# 2) V, XIII, XIV, and XV (XIII and XIV are almost identical)
# 3) XI and XII (almost identical)
##########################################################################################
# Data Summary
prepare_data_summary <- function(dataset_code) {
x = get_data(dataset_code)$DATASET
event_size = x$SDC$Event.Size
market_cap = x$CRSP$Market.Cap
be_me = x$CRSP$BE.ME
be_me[be_me >= 1e20] = NA
# The data summary is a named numeric vector with the following fields:
# min, median, mean, max, std, number of missing data points
summary_names = c("Min.", "Median", "Mean", "Max.")
data_summary_per_element <- function(x) {
round(c(summary(x[!is.na(x) & x != 0])[summary_names],
sd(x[!is.na(x) & x != 0]),
sum(is.na(x) | x == 0)), 1)
}
res = rbind(data_summary_per_element(event_size),
data_summary_per_element(market_cap),
data_summary_per_element(be_me)
)
rownames(res) = c("Percent authorized", "Market cap.", "BE/ME")
colnames(res) = c(summary_names, "std", "Missing")
return(res)
}
# Compute the data summary for both buybacks and issuers
data_summary = list()
for (dataset_code in dataset_codes) {
data_summary[[dataset_code]] = prepare_data_summary(dataset_code)
}
##########################################################################################
# Table I: Buyback and SEO announcements during 1985-2015: Descriptive Statistics
descriptive_stats_table <- function() {
non_na_functions = list()
non_na_functions$mean <- function(x) { mean(x[!is.na(x)]) }
non_na_functions$median <- function(x) { median(x[!is.na(x)]) }
non_na_functions$sd <- function(x) { sd(x[!is.na(x)]) }
non_na_functions$quantile <- function(x, q) { quantile(x[!is.na(x)], q) }
non_na_zero_functions = list()
non_na_zero_functions$mean <- function(x) { mean(x[!is.na(x) & scrub(x) != 0]) }
non_na_zero_functions$median <- function(x) { median(x[!is.na(x) & scrub(x) != 0]) }
non_na_zero_functions$sd <- function(x) { sd(x[!is.na(x) & scrub(x) != 0]) }
non_na_zero_functions$quantile <- function(x, q) { quantile(x[!is.na(x) & scrub(x) != 0], q) }
# Note: Difference between the two datasets:
# BB has: BUYBACK_DATA$Valuation_Index, eu_index$bb, and StambaughBB
# ISS has: - , - , and ISSUERS_DATA$DATASET$Stambaugh
prepare_descriptive_stats <- function(dataset_code) {
x = get_data(dataset_code)
events = x$DATASET
add_element <- function(the_list, name, data, non_zero, to_percentage) {
the_list[[name]] = list(data=data, non_zero=non_zero, to_percentage=to_percentage)
return(the_list)
}
rows_list = list()
rows_list = add_element(rows_list, "Market Cap.", events$CRSP$Market.Cap, TRUE, FALSE)
rows_list = add_element(rows_list, "Prior Returns", events$CRSP$recent_performance, TRUE, TRUE)
rows_list = add_element(rows_list, "BE/ME", events$CRSP$BE.ME, TRUE, FALSE)
rows_list = add_element(rows_list, "Volatility", events$CRSP$pre_vol, TRUE, TRUE)
rows_list = add_element(rows_list, "(1-R^2)", events$CRSP$Rsq, TRUE, FALSE)
# Dataset-specific elements
if (dataset_code == "bb") {
rows_list = add_element(rows_list, "U-index", x$Valuation_Index, FALSE, FALSE)
# TODO: Abstract this
rows_list = add_element(rows_list, "EU-index", eu_index$bb, FALSE, FALSE)
# TODO: Abstract this (see how it is abstracted for ISS below)
rows_list = add_element(rows_list, "Mispricing Measure", StambaughBB, FALSE, FALSE)
} else if (dataset_code == "iss") {
# Note: This removes zeros, while the Stambaugh for BB does not
rows_list = add_element(rows_list, "Mispricing Measure", events$Stambaugh, TRUE, FALSE)
}
rows_list = add_element(rows_list, "Percent Shares", events$SDC$Event.Size, TRUE, FALSE)
rows_list = add_element(rows_list, "Leverage", events$CRSP$leverage_lt_over_lt_plus_e, TRUE, FALSE)
# Each row contains:
# mean, median, std, 0.2 quantile, 0.8 quantile
res = c()
for (elem in rows_list) {
# Choose whether to use functions for non-zero elements
if (elem$non_zero) {
function_family = non_na_zero_functions
} else {
function_family = non_na_functions
}
single_row = c(
function_family$mean(elem$data),
function_family$median(elem$data),
function_family$sd(elem$data),
function_family$quantile(elem$data, 0.2),
function_family$quantile(elem$data, 0.8))
# Convert to percentage
if (elem$to_percentage) {
single_row = 100 * single_row
}
res = rbind(res, single_row)
}
rownames(res) = names(rows_list)
colnames(res) = c("Mean", "Median", "Standard Dev.",
"20^{th} Percentile", "80^{th} Percentile")
return(res)
}
# Compute the descriptive stats for both buybacks and issuers
descriptive_stats = list()
for (dataset_code in dataset_codes) {
descriptive_stats[[dataset_code]] = prepare_descriptive_stats(dataset_code)
}
return(descriptive_stats)
}
descriptive_stats = descriptive_stats_table()
##########################################################################################
# Helpers: Common to tables II, II, IV, VI, and VII
get_function <- function(method) {
if (method == "IRATS") {
return(car_table)
} else if (method == "CAL") {
return(calendar_table)
} else {
stop("invalid method")
}
}
# Method can be "IRATS" or "CAL"
# col_names is a list of two elements
single_panel_part <- function(x, useonly, weights, method, col_names) {
models = list(`3F`=three_factor_model, `5F`=five_factor_model)
func = get_function(method)
panel_part = c()
for (model_index in seq_along(models)) {
formula_used = models[[model_index]]
tmp = func(x$returns_by_event_monthly[, useonly],
x$SDC$Event.Date[useonly],
Risk_Factors_Monthly,
formula_used=formula_used,
value.weights=weights[useonly])$results
colnames(tmp)[1] = col_names[model_index]
panel_part = cbind(panel_part, tmp)
}
return(panel_part)
}
combine_panel_parts <- function(panel_part_1, panel_part_2) {
cbind(panel_part_1[, 1:3], panel_part_2[, 1:3],
panel_part_1[, 4:6], panel_part_2[, 4:6])
}
##########################################################################################
# Table II: Buyback announcements during 1985-2015
# buyback_announcements_table$<IRATS or CAL>$<all or undervaluation>
create_buyback_announcements_table <- function() {
x = BUYBACK_DATA$DATASET
res = list()
# Panel A: IRATS
# All
useonly = 1:length(x$SDC$CUSIP)
weights = 1
method = "IRATS"
col_names = c("CAR 3F", "CAR 5F")
res[[method]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Undervalued
useonly = which(company_subset$bb$undervalued)
col_names = c("U:CAR3F", "U:CAR5F")
tmp_top = single_panel_part(x, useonly, weights, method, col_names)
# Overvalued
useonly = which(company_subset$bb$overvalued)
col_names = c("O:CAR3F", "O:CAR5F")
tmp_bottom = single_panel_part(x, useonly, weights, method, col_names)
# Combine
res[[method]]$undervaluation = combine_panel_parts(tmp_top, tmp_bottom)
# Panel B: CAL
# All
useonly = 1:length(x$SDC$CUSIP)
weights = value_weights$bb
method = "CAL"
col_names = c("CAL 3F", "CAL 5F")
res[[method]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Undervalued
useonly = which(company_subset$bb$undervalued)
col_names = c("U:CAL3F", "U:CAL5F")
tmp_top = single_panel_part(x, useonly, weights, method, col_names)
# Overvalued
useonly = which(company_subset$bb$overvalued)
col_names = c("O:CAL3F", "O:CAL5F")
tmp_bottom = single_panel_part(x, useonly, weights, method, col_names)
# Combine
res[[method]]$undervaluation = combine_panel_parts(tmp_top, tmp_bottom)
return(res)
}
buyback_announcements_table = create_buyback_announcements_table()
##########################################################################################
# Table III: Buyback announcements during 1985-2015: Value Weighted Portfolios
# value_weighted_table$<all_firms or no_large_firms>$<all or undervaluation>
create_value_weighted_table <- function() {
x = BUYBACK_DATA$DATASET
res = list()
# Panel A: All firms
group = "all_firms"
# All
useonly = 1:length(x$SDC$CUSIP)
weights = x$CRSP$Market.Cap
method = "CAL"
col_names = c("CAL 3F", "CAL 5F")
res[[group]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Undervalued
useonly = which(company_subset$bb$undervalued)
col_names = c("U:CAL3F", "U:CAL5F")
tmp_top = single_panel_part(x, useonly, weights, method, col_names)
# Overvalued
useonly = which(company_subset$bb$overvalued)
col_names = c("O:CAL3F", "O:CAL5F")
tmp_bottom = single_panel_part(x, useonly, weights, method, col_names)
# Combine
res[[group]]$undervaluation = combine_panel_parts(tmp_top, tmp_bottom)
# Panel B: No large firms
group = "no_large_firms"
# All
useonly_valueL = which(x$CRSP$Market.Cap_score < 0.75)
useonly = useonly_valueL
col_names = c("CAL 3F", "CAL 5F")
res[[group]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Undervalued
b = BUYBACK_DATA$Valuation_Index[useonly_valueL] >
quantile(BUYBACK_DATA$Valuation_Index[useonly_valueL], 1-quantile_Uindex)
useonly = useonly_valueL[which(b)]
col_names = c("U:CAL3F", "U:CAL5F")
tmp_top = single_panel_part(x, useonly, weights, method, col_names)
# Overvalued
b = BUYBACK_DATA$Valuation_Index[useonly_valueL] <
quantile(BUYBACK_DATA$Valuation_Index[useonly_valueL], quantile_Uindex)
useonly = useonly_valueL[which(b)]
col_names = c("O:CAL3F", "O:CAL5F")
tmp_bottom = single_panel_part(x, useonly, weights, method, col_names)
# Combine
res[[group]]$undervaluation = combine_panel_parts(tmp_top, tmp_bottom)
return(res)
}
value_weighted_table = create_value_weighted_table()
##########################################################################################
# Table IV: SEO announcements during 1985-2015
# issuers_announcements_table$<IRATS or CAL>$<all or undervaluation>
create_issuers_announcements_table <- function() {
x = ISSUERS_DATA$DATASET
res = list()
# Panel A: IRATS
# All
useonly = 1:length(x$SDC$CUSIP)
weights = 1
method = "IRATS"
col_names = c("CAR 3F", "CAR 5F")
res[[method]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Low miscpricing measure
useonly = stam_events$iss$low
res[[method]]$lowMM = single_panel_part(x, useonly, weights, method, col_names)
# High Miscpricing measure
useonly = stam_events$iss$high
res[[method]]$highMM = single_panel_part(x, useonly, weights, method, col_names)
# Panel B: CAL
# All
useonly = 1:length(x$SDC$CUSIP)
weights = value_weights$iss
method = "CAL"
col_names = c("CAL 3F", "CAL 5F")
res[[method]]$all = single_panel_part(x, useonly, weights, method, col_names)
# Low miscpricing measure
useonly = stam_events$iss$low
res[[method]]$lowMM = single_panel_part(x, useonly, weights, method, col_names)
# High Miscpricing measure
useonly = stam_events$iss$high
res[[method]]$highMM = single_panel_part(x, useonly, weights, method, col_names)
return(res)
}
issuers_announcements_table = create_issuers_announcements_table()
##########################################################################################
# Table V: Buyback returns over different time periods
# buyback_returns_periods_table$<IRATS or CAL>
get_weights <- function(method, dataset_code, useonly) {
if (method == "IRATS") {
return(1)
} else if (method == "CAL") {
return(value_weights[[dataset_code]][useonly])
} else {
stop("invalid method")
}
}
create_buyback_returns_periods_table <- function() {
x = BUYBACK_DATA$DATASET
models = list(`3F`=three_factor_model, `5F`=five_factor_model)
# Method can be "IRATS" or "CAL"
create_buyback_returns_periods_panel <- function(method) {
func = get_function(method)
return(Reduce(cbind, lapply(1:nrow(periods_considered), function(i) {
useonly = (x$SDC$Event.Date >= periods_considered[i, 1] &
x$SDC$Event.Date <= periods_considered[i, 2])
# Loop through models
res = c()
for (model_index in seq_along(models)) {
formula_used = models[[model_index]]
weights = get_weights(method, "bb", useonly)
tmp = func(x$returns_by_event_monthly[, useonly],
x$SDC$Event.Date[useonly],
Risk_Factors_Monthly,
formula_used=formula_used,
value.weights=weights)$results
res = cbind(res, tmp)
}
# Pass col_names, one for each model
colnames(res) = c(paste(
paste(str_sub(periods_considered[i, 1],start=1, end=4),
str_sub(periods_considered[i, 2],start=1, end=4), sep= "-"),
"3FF", sep=" "), "t-stat", "p-value", "5FF", "t-stat", "p-value")
rownames(res)[nrow(res)] = "Observations"
return(res)
})))
}
res = list()
for (method in c("IRATS", "CAL")) {
res[[method]] = create_buyback_returns_periods_panel(method)
}
return(res)
}
buyback_returns_periods_table = create_buyback_returns_periods_table()
##########################################################################################
# Table VI: Buyback and SEOs for Low and High Volatility companies
# Table VII: Buyback and SEOs for Low and High Idiosyncratic companies
# buybacks_issuers_volatility_table$<IRATS or CAL>$<bb or iss>$<lowvol or highvol>
# buybacks_issuers_idiosyncratic_table$<IRATS or CAL>$<bb or iss>$<lowidio or highidio>
# vol_type can be "volatility" or "idiosyncratic"
create_buybacks_issuers_vol_table <- function(vol) {
if (vol == "volatility") {
events_data = VOL_events
vol_types = c("lowvol", "highvol")
} else if (vol == "idiosyncratic") {
events_data = Idiosyncr_events
vol_types = c("lowidio", "highidio")
} else {
stop('Invalid vol argument. Must be "volatility" or "idiosyncratic"')
}
res = list()
# Panel A: IRATS low-high volatility
method = "IRATS"
col_names = c("CAR 3F", "CAR 5F")
weights = 1
# Loop through datasets: buybacks and issuers
for (dataset_code in c("bb", "iss")) {
x = get_data(dataset_code)$DATASET
# Calculations for high volatility and low volatility
for (vol_type in vol_types) {
useonly = events_data[[dataset_code]][[vol_type]]
res[[method]][[dataset_code]][[vol_type]] = single_panel_part(
x, useonly, weights, method, col_names)
}
}
# Panel B: CAL low-high volatility
method = "CAL"
col_names = c("CAL 3F", "CAL 5F")
# Loop through datasets: buybacks and issuers
for (dataset_code in c("bb", "iss")) {
x = get_data(dataset_code)$DATASET
weights = value_weights[[dataset_code]]
# Calculations for high volatility and low volatility
for (vol_type in vol_types) {
useonly = events_data[[dataset_code]][[vol_type]]
res[[method]][[dataset_code]][[vol_type]] = single_panel_part(
x, useonly, weights, method, col_names)
}
}
return(res)
}
# Volatility
create_buybacks_issuers_volatility_table <- function() {
return(create_buybacks_issuers_vol_table(vol="volatility"))
}
buybacks_issuers_volatility_table = create_buybacks_issuers_volatility_table()
# Idiosyncratic volatility
create_buybacks_issuers_idiosyncratic_table <- function() {
return(create_buybacks_issuers_vol_table(vol="idiosyncratic"))
}
buybacks_issuers_idiosyncratic_table = create_buybacks_issuers_idiosyncratic_table()
##########################################################################################
# Table VIII: Relations across firm characteristics for Buybacks
create_buybacks_firm_characteristics_table <- function() {
cell_value <- function(row_vec, col_vec) {
return(100 * sum(row_vec & col_vec) / sum(row_vec))
}
row_vecs = list(
company_subset$bb$undervalued, company_subset$bb$overvalued,
Idiosyncr_events$bb$highidio, Idiosyncr_events$bb$lowidio,
VOL_events$bb$highvol, VOL_events$bb$lowvol,
stam_events$bb$high, stam_events$bb$low,
lev_events$bb$high, lev_events$bb$low)
col_vecs = list(
Idiosyncr_events$bb$highidio, Idiosyncr_events$bb$lowidio,
VOL_events$bb$highvol, VOL_events$bb$lowvol,
lev_events$bb$high, lev_events$bb$low,
eps_events$bb$high, eps_events$bb$low
)
res = NULL
for (row_vec in row_vecs) {
this_row = c()
for (col_vec in col_vecs) {
this_row = cbind(this_row, cell_value(row_vec, col_vec))
}
res = rbind(res, this_row)
}
rownames(res) = c("Undervalued", "Overvalued",
"High Idiosync.", "Low Idiosync.",
"High Vol.", "Low Vol.",
"High Mispr.", "Low Mispr.",
"High Lev.", "Low Lev.")
colnames(res) = c("H Idiosync.", "L Idiosync.",
"H Vol.", "L Vol.",
"H Lev.", "L Lev.",
"H EPS unc.", "L EPS unc.")
return (res)
}
buybacks_firm_characteristics_table = create_buybacks_firm_characteristics_table()
##########################################################################################
# Table IX: Correlations of Buybacks Characteristics
create_buybacks_correlations_table <- function() {
x = BUYBACK_DATA$DATASET
EU_index_features = scrub(cbind(1-x$CRSP$Rsq_score, x$CRSP$pre_vol_Score,
BUYBACK_DATA$Valuation_Index, x$Stambaugh))
colnames(EU_index_features) = c("Idiosyncratic Score", "Volatility Score",
"U-Index Score", "Mispricing Measure")
return(cor(EU_index_features))
}
buybacks_correlations_table = create_buybacks_correlations_table()
##########################################################################################
# Table X: EU relations with Firm Characteristics
create_eu_firm_characteristics_table <- function() {
x = BUYBACK_DATA$DATASET
str_parts <- function(str) {
return(unlist(str_split(str, "\\+")))
}
unique_str <- function(vec) {
return(unique(unlist(sapply(vec, function(i) str_parts(i)))))
}
length_of_intersection <- function(str, vec) {
return(length(intersect(str_parts(str), vec)))
}
all_fund_sources = unique_str(x$SDC$Source...of..Funds..Code)
cash_funds = c("CR")
credit_funds = c("BL", "BOR", "CF", "DS")
other_funds = setdiff(all_fund_sources,c(cash_funds,credit_funds))
all_purposes = unique_str(x$SDC$Purpose.Code)
good_purpose = c("ESV", "UVL", "STP", "ISV")
other_purpose = setdiff(all_purposes,c(good_purpose))
high_leverage = 0 * eu_index$bb
high_leverage[lev_events$bb$high] = 1
low_leverage = 0 * eu_index$bb
low_leverage[lev_events$bb$low] = 1
Missed_EPS = (x$ibes$mean_rec_last_month_score < x$ibes$mean_rec_last_last_month_score)
Beat_EPS = (x$ibes$mean_rec_last_month_score >= x$ibes$mean_rec_last_last_month_score)
low_epsunc = 0 * eu_index$bb
low_epsunc[eps_events$bb$low] = 1
ISS_Later = ifelse((x$SDC$OtherlaterEvent != 0), "Yes", "No")
Credit = sapply(x$SDC$Source...of..Funds..Code, function(i) {
length_of_intersection(i, credit_funds) != 0 &
length_of_intersection(i, c(cash_funds, other_funds)) == 0
})
Cash = sapply(x$SDC$Source...of..Funds..Code, function(i) {
length_of_intersection(i, cash_funds) != 0 &
length_of_intersection(i, c(credit_funds, other_funds)) == 0
})
Good_purpose = sapply(x$SDC$Purpose.Code, function(i) {
length_of_intersection(i, good_purpose) != 0 &
length_of_intersection(i, other_purpose) == 0
})
Stock_Option_Plan = sapply(x$SDC$Purpose.Code, function(i) {
length_of_intersection(i, "STP") != 0 &
length_of_intersection(i, c("ESV","ISV","UVL")) == 0
})
Undervalued = sapply(x$SDC$Purpose.Code, function(i) {
length_of_intersection(i, "UVL") != 0 &
length_of_intersection(i, "STP") == 0
})
Enhance_Shareholder_Value = sapply(x$SDC$Purpose.Code, function(i) {
length_of_intersection(i, c("ESV","ISV")) != 0
})
all_characteristics = cbind(low_leverage, high_leverage, Missed_EPS, Beat_EPS,
ISS_Later, Cash, Good_purpose, Undervalued,
Enhance_Shareholder_Value, Stock_Option_Plan)
EU_relations= t(apply(all_characteristics, 2, function(r) {
x = table(eu_index$bb, r)
x = matrix(round(100 * x[,2] / (x[,1] + x[,2]), 1), ncol=1)
return(x)
}))
colnames(EU_relations) = paste0("EU", 0:(ncol(EU_relations) - 1))
rownames(EU_relations) = gsub("_", " ", rownames(EU_relations))
all_characteristics_continuous = cbind(x$CRSP$Market.Cap, x$CRSP$BE.ME_score,
x$SDC$Event.Size, x$Stambaugh)
EU_relations_continuous = t(apply(all_characteristics_continuous, 2, function(r) {
sapply(sort(unique(eu_index$bb)), function(i) {
useonly = which(eu_index$bb == i)
mean(r[useonly][!is.na(r[useonly])])
})
}))
rownames(EU_relations_continuous) = c("Market Cap.", "BE/ME Score",
"Percentage Shares", "Mispricing Measure")
EU_relations = rbind(EU_relations, round(EU_relations_continuous, 2))
return(EU_relations)
}
eu_firm_characteristics_table = create_eu_firm_characteristics_table()
##########################################################################################
# Table XI: Buyback announcements IRATS for all EU-index Values
# Table XII: Buyback announcements Calendar Time for all EU-index Values
# buybacks_eu_tables$<long, hedged, long48, hedged48, IRATS, or CAL>
create_buybacks_eu_tables <- function() {
x = BUYBACK_DATA$DATASET
res = list()
res$long = NULL
res$hedged = NULL
res$long48 = NULL