finmodeling 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. data/.gitignore +0 -0
  2. data/Gemfile +2 -0
  3. data/README.md +289 -269
  4. data/Rakefile +12 -0
  5. data/TODO.txt +113 -20
  6. data/examples/{dump_report.rb → dump_latest_10k.rb} +1 -1
  7. data/examples/list_disclosures.rb +50 -0
  8. data/examples/lists/nasdaq-mid-to-mega-tech-symbols.txt +0 -0
  9. data/examples/show_report.rb +112 -32
  10. data/examples/show_reports.rb +162 -33
  11. data/finmodeling.gemspec +4 -1
  12. data/lib/finmodeling/annual_report_filing.rb +97 -18
  13. data/lib/finmodeling/array_with_stats.rb +0 -0
  14. data/lib/finmodeling/assets_calculation.rb +12 -3
  15. data/lib/finmodeling/assets_item.rb +0 -0
  16. data/lib/finmodeling/assets_item_vectors.rb +0 -0
  17. data/lib/finmodeling/balance_sheet_analyses.rb +19 -4
  18. data/lib/finmodeling/balance_sheet_calculation.rb +52 -37
  19. data/lib/finmodeling/calculation_summary.rb +119 -14
  20. data/lib/finmodeling/can_cache_classifications.rb +0 -0
  21. data/lib/finmodeling/can_cache_summaries.rb +0 -0
  22. data/lib/finmodeling/can_choose_successive_periods.rb +15 -0
  23. data/lib/finmodeling/can_classify_rows.rb +0 -0
  24. data/lib/finmodeling/capm.rb +80 -0
  25. data/lib/finmodeling/cash_change_calculation.rb +3 -3
  26. data/lib/finmodeling/cash_change_item.rb +0 -0
  27. data/lib/finmodeling/cash_change_item_vectors.rb +0 -0
  28. data/lib/finmodeling/cash_change_summary_from_differences.rb +36 -0
  29. data/lib/finmodeling/cash_flow_statement_analyses.rb +36 -0
  30. data/lib/finmodeling/cash_flow_statement_calculation.rb +28 -52
  31. data/lib/finmodeling/classifiers.rb +2 -0
  32. data/lib/finmodeling/company.rb +0 -0
  33. data/lib/finmodeling/company_filing.rb +30 -7
  34. data/lib/finmodeling/company_filing_calculation.rb +16 -6
  35. data/lib/finmodeling/company_filings.rb +112 -46
  36. data/lib/finmodeling/comprehensive_income_calculation.rb +60 -0
  37. data/lib/finmodeling/comprehensive_income_statement_calculation.rb +74 -0
  38. data/lib/finmodeling/comprehensive_income_statement_item.rb +20 -0
  39. data/lib/finmodeling/comprehensive_income_statement_item_vectors.rb +235 -0
  40. data/lib/finmodeling/config.rb +0 -0
  41. data/lib/finmodeling/debt_cost_of_capital.rb +14 -0
  42. data/lib/finmodeling/equity_change_calculation.rb +43 -0
  43. data/lib/finmodeling/equity_change_item.rb +25 -0
  44. data/lib/finmodeling/equity_change_item_vectors.rb +156 -0
  45. data/lib/finmodeling/factory.rb +0 -0
  46. data/lib/finmodeling/fama_french_cost_of_equity.rb +119 -0
  47. data/lib/finmodeling/float_helpers.rb +14 -8
  48. data/lib/finmodeling/forecasted_reformulated_balance_sheet.rb +55 -0
  49. data/lib/finmodeling/forecasted_reformulated_income_statement.rb +110 -0
  50. data/lib/finmodeling/forecasts.rb +4 -4
  51. data/lib/finmodeling/has_string_classifer.rb +0 -0
  52. data/lib/finmodeling/income_statement_analyses.rb +23 -17
  53. data/lib/finmodeling/income_statement_calculation.rb +46 -43
  54. data/lib/finmodeling/income_statement_item.rb +1 -1
  55. data/lib/finmodeling/income_statement_item_vectors.rb +24 -13
  56. data/lib/finmodeling/invalid_filing_error.rb +4 -0
  57. data/lib/finmodeling/liabs_and_equity_calculation.rb +18 -8
  58. data/lib/finmodeling/liabs_and_equity_item.rb +1 -1
  59. data/lib/finmodeling/liabs_and_equity_item_vectors.rb +24 -24
  60. data/lib/finmodeling/linear_trend_forecasting_policy.rb +23 -0
  61. data/lib/finmodeling/net_income_calculation.rb +23 -10
  62. data/lib/finmodeling/net_income_summary_from_differences.rb +51 -0
  63. data/lib/finmodeling/paths.rb +0 -0
  64. data/lib/finmodeling/period_array.rb +8 -4
  65. data/lib/finmodeling/quarterly_report_filing.rb +9 -4
  66. data/lib/finmodeling/rate.rb +8 -0
  67. data/lib/finmodeling/ratio.rb +0 -0
  68. data/lib/finmodeling/reformulated_balance_sheet.rb +47 -88
  69. data/lib/finmodeling/reformulated_cash_flow_statement.rb +18 -41
  70. data/lib/finmodeling/reformulated_income_statement.rb +44 -206
  71. data/lib/finmodeling/reformulated_shareholder_equity_statement.rb +50 -0
  72. data/lib/finmodeling/reoi_valuation.rb +104 -0
  73. data/lib/finmodeling/shareholder_equity_statement_calculation.rb +34 -0
  74. data/lib/finmodeling/string_helpers.rb +18 -1
  75. data/lib/finmodeling/time_series_estimator.rb +25 -0
  76. data/lib/finmodeling/trailing_avg_forecasting_policy.rb +23 -0
  77. data/lib/finmodeling/version.rb +1 -1
  78. data/lib/finmodeling/weighted_avg_cost_of_capital.rb +35 -0
  79. data/lib/finmodeling/yahoo_finance_helpers.rb +20 -0
  80. data/lib/finmodeling.rb +33 -2
  81. data/spec/annual_report_filing_spec.rb +81 -45
  82. data/spec/assets_calculation_spec.rb +7 -4
  83. data/spec/assets_item_spec.rb +9 -14
  84. data/spec/balance_sheet_analyses_spec.rb +13 -13
  85. data/spec/balance_sheet_calculation_spec.rb +45 -51
  86. data/spec/calculation_summary_spec.rb +113 -21
  87. data/spec/can_classify_rows_spec.rb +0 -0
  88. data/spec/cash_change_calculation_spec.rb +1 -10
  89. data/spec/cash_change_item_spec.rb +10 -18
  90. data/spec/cash_flow_statement_calculation_spec.rb +10 -24
  91. data/spec/company_beta_spec.rb +53 -0
  92. data/spec/company_filing_calculation_spec.rb +39 -49
  93. data/spec/company_filing_spec.rb +0 -0
  94. data/spec/company_filings_spec.rb +75 -25
  95. data/spec/company_spec.rb +37 -47
  96. data/spec/comprehensive_income_statement_calculation_spec.rb +54 -0
  97. data/spec/comprehensive_income_statement_item_spec.rb +56 -0
  98. data/spec/debt_cost_of_capital_spec.rb +19 -0
  99. data/spec/equity_change_calculation_spec.rb +33 -0
  100. data/spec/equity_change_item_spec.rb +58 -0
  101. data/spec/factory_spec.rb +2 -2
  102. data/spec/forecasts_spec.rb +2 -2
  103. data/spec/income_statement_analyses_spec.rb +23 -21
  104. data/spec/income_statement_calculation_spec.rb +17 -49
  105. data/spec/income_statement_item_spec.rb +17 -29
  106. data/spec/liabs_and_equity_calculation_spec.rb +6 -3
  107. data/spec/liabs_and_equity_item_spec.rb +14 -22
  108. data/spec/linear_trend_forecasting_policy_spec.rb +37 -0
  109. data/spec/matchers/custom_matchers.rb +79 -0
  110. data/spec/mocks/calculation.rb +0 -0
  111. data/spec/mocks/income_statement_analyses.rb +0 -0
  112. data/spec/mocks/sec_query.rb +0 -0
  113. data/spec/net_income_calculation_spec.rb +16 -10
  114. data/spec/period_array.rb +0 -0
  115. data/spec/quarterly_report_filing_spec.rb +21 -38
  116. data/spec/rate_spec.rb +0 -0
  117. data/spec/ratio_spec.rb +0 -0
  118. data/spec/reformulated_balance_sheet_spec.rb +56 -33
  119. data/spec/reformulated_cash_flow_statement_spec.rb +18 -10
  120. data/spec/reformulated_income_statement_spec.rb +16 -15
  121. data/spec/reformulated_shareholder_equity_statement_spec.rb +43 -0
  122. data/spec/reoi_valuation_spec.rb +146 -0
  123. data/spec/shareholder_equity_statement_calculation_spec.rb +59 -0
  124. data/spec/spec_helper.rb +4 -1
  125. data/spec/string_helpers_spec.rb +15 -13
  126. data/spec/time_series_estimator_spec.rb +61 -0
  127. data/spec/trailing_avg_forecasting_policy_spec.rb +37 -0
  128. data/spec/weighted_avg_cost_of_capital_spec.rb +32 -0
  129. data/tools/create_equity_change_training_vectors.rb +49 -0
  130. data/tools/time_specs.sh +7 -0
  131. metadata +182 -36
  132. data/lib/finmodeling/constant_forecasting_policy.rb +0 -23
  133. data/lib/finmodeling/generic_forecasting_policy.rb +0 -19
  134. data/spec/constant_forecasting_policy_spec.rb +0 -37
  135. data/spec/generic_forecasting_policy_spec.rb +0 -33
@@ -0,0 +1,235 @@
1
+ module FinModeling
2
+ class ComprehensiveIncomeStatementItem < String
3
+ TRAINING_VECTORS = [
4
+
5
+ # Fake: made up to show an example of FIAT. Need to pull in more real examples..
6
+ {:klass=>:or, :item_string=>"Advertising Revenue"},
7
+ {:klass=>:cogs, :item_string=>"Advertising Revenue Cost"},
8
+ {:klass=>:oe, :item_string=>"General And Administrative Expense"},
9
+ {:klass=>:oe, :item_string=>"Other General And Administrative Expense"},
10
+ {:klass=>:oe, :item_string=>"Depreciation Amortization And Accretion Net"},
11
+ {:klass=>:fibt, :item_string=>"Gain Loss On Disposition Of Assets"},
12
+ {:klass=>:fibt, :item_string=>"Gains Losses On Extinguishment Of Debt"},
13
+ {:klass=>:fibt, :item_string=>"Investment Income Interest"},
14
+ {:klass=>:fibt, :item_string=>"Interest Expense"},
15
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
16
+ {:klass=>:fiat, :item_string=>"Dividends Preferred Stock"},
17
+ {:klass=>:ooci_nci, :item_string=>"Comprehensive Income Net Of Tax Attributable To Noncontrolling Interest"},
18
+
19
+ # ALTR
20
+ {:klass=>:or, :item_string=>"Sales Revenue Net"},
21
+ {:klass=>:cogs, :item_string=>"Cost Of Goods And Services Sold"},
22
+ {:klass=>:oe, :item_string=>"Research And Development Expense"},
23
+ {:klass=>:oe, :item_string=>"Selling General And Administrative Expense"},
24
+ {:klass=>:oe, :item_string=>"Loss Gain On Deferred Compensation Plan Securities"},
25
+ {:klass=>:fibt, :item_string=>"Investment Income Interest"},
26
+ {:klass=>:fibt, :item_string=>"Foreign Currency Cash Flow Hedge Gain Loss Reclassified To Earnings Net"},
27
+ {:klass=>:fibt, :item_string=>"Interest Expense"},
28
+ {:klass=>:oibt, :item_string=>"Deferred Compensation Arrangement With Individual Compensation Expense"},
29
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
30
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
31
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment On Derivatives Included In Net Income Net Of Tax"},
32
+
33
+ # This comes from ALTR. It was getting misclassified as foci, so I'm retraining it a bunch of times.
34
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
35
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
36
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
37
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
38
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
39
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
40
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
41
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
42
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
43
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
44
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
45
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
46
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
47
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
48
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
49
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
50
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
51
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
52
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
53
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
54
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
55
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
56
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
57
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
58
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
59
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
60
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
61
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
62
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
63
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
64
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
65
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
66
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
67
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
68
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
69
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
70
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
71
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
72
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
73
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
74
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
75
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
76
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
77
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
78
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
79
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
80
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
81
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
82
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
83
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
84
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
85
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
86
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
87
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
88
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
89
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
90
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
91
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
92
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
93
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
94
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
95
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
96
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
97
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income (Loss), Net of Tax"},
98
+
99
+ # BMC
100
+ {:klass=>:or, :item_string=>"Licenses Revenue"},
101
+ {:klass=>:or, :item_string=>"Maintenance Revenue"},
102
+ {:klass=>:or, :item_string=>"Technology Services Revenue"},
103
+ {:klass=>:cogs, :item_string=>"License Costs"},
104
+ {:klass=>:cogs, :item_string=>"Maintenance Costs"},
105
+ {:klass=>:cogs, :item_string=>"Technology Services Costs"},
106
+ {:klass=>:oe, :item_string=>"Selling And Marketing Expense"},
107
+ {:klass=>:oe, :item_string=>"Research And Development Expense Software Excluding Acquired In Process Cost"},
108
+ {:klass=>:oe, :item_string=>"General And Administrative Expense"},
109
+ {:klass=>:oe, :item_string=>"Amortization Of Intangible Assets"},
110
+ {:klass=>:fibt, :item_string=>"Other Interest And Dividend Income"},
111
+ {:klass=>:fibt, :item_string=>"Interest Expense"},
112
+ {:klass=>:fibt, :item_string=>"Gain Loss On Investments"},
113
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
114
+
115
+ # CHRW
116
+ {:klass=>:or, :item_string=>"Transportation Services Revenue"},
117
+ {:klass=>:or, :item_string=>"Sales Revenue Goods Net"},
118
+ {:klass=>:or, :item_string=>"Sales Revenue Services Net"},
119
+ {:klass=>:cogs, :item_string=>"Cost Of Purchased Transportation And Related Services"},
120
+ {:klass=>:cogs, :item_string=>"Cost Of Goods Sold"},
121
+ {:klass=>:oe, :item_string=>"Labor And Related Expense"},
122
+ {:klass=>:oe, :item_string=>"Other Selling General And Administrative Expense"},
123
+ {:klass=>:fibt, :item_string=>"Total Nonoperating Interest And Other Income Expense"},
124
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
125
+
126
+ # SIRI
127
+ {:klass=>:or, :item_string=>"Other Sales Revenue Net"},
128
+ {:klass=>:or, :item_string=>"Equipment Revenue"},
129
+ {:klass=>:or, :item_string=>"Advertising Revenue"},
130
+ {:klass=>:or, :item_string=>"Subscription Revenue"},
131
+ {:klass=>:cogs, :item_string=>"Revenue Share And Royalties"},
132
+ {:klass=>:cogs, :item_string=>"Programming And Content"},
133
+ {:klass=>:cogs, :item_string=>"Customer Service And Billing"},
134
+ {:klass=>:cogs, :item_string=>"Satellite And Transmission"},
135
+ {:klass=>:cogs, :item_string=>"Cost Of Goods Sold"},
136
+ {:klass=>:oe, :item_string=>"Subscriber Acquisition Costs"},
137
+ {:klass=>:oe, :item_string=>"Selling And Marketing Expense"},
138
+ {:klass=>:oe, :item_string=>"Technology Services Costs"},
139
+ {:klass=>:oe, :item_string=>"General And Administrative Expense"},
140
+ {:klass=>:oe, :item_string=>"Depreciation And Amortization"},
141
+ {:klass=>:fibt, :item_string=>"Interest And Investment Income Loss"},
142
+ {:klass=>:fibt, :item_string=>"Interest Expense"},
143
+ {:klass=>:fibt, :item_string=>"Gains Losses On Extinguishment Of Debt"},
144
+ {:klass=>:fibt, :item_string=>"Other Nonoperating Income Expense"},
145
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
146
+ {:klass=>:unkoci, :item_string=>"Realized Loss On Investment Foreign Currency Translation Adjustment"},
147
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
148
+
149
+ # VRSN
150
+ {:klass=>:or, :item_string=>"Revenues"},
151
+ {:klass=>:cogs, :item_string=>"Cost Of Revenue"},
152
+ {:klass=>:oe, :item_string=>"Selling And Marketing Expense"},
153
+ {:klass=>:oe, :item_string=>"Research And Development Expense"},
154
+ {:klass=>:oe, :item_string=>"General And Administrative Expense"},
155
+ {:klass=>:oibt, :item_string=>"Restructuring Settlement And Impairment Provisions"},
156
+ {:klass=>:fibt, :item_string=>"Interest Expense"},
157
+ {:klass=>:fibt, :item_string=>"Nonoperating Gains Losses"},
158
+ {:klass=>:tax, :item_string=>"Income Tax Expense Benefit"},
159
+ {:klass=>:ooiat, :item_string=>"Income Loss From Discontinued Operations Net Of Tax"},
160
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
161
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax"},
162
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment For Sale Of Securities Included In Net Income Net Of Tax"},
163
+
164
+ # ATVI
165
+ {:klass=>:ni, :item_string=>"Net Income Loss"},
166
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease"},
167
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax"},
168
+
169
+ # CTXS
170
+ {:klass=>:ni, :item_string=>"Profit Loss"},
171
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
172
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax"},
173
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment For Sale Of Securities Included In Net Income Net Of Tax"},
174
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
175
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment On Derivatives Included In Net Income Net Of Tax"},
176
+ {:klass=>:ooci_nci, :item_string=>"Comprehensive Income Net Of Tax Attributable To Noncontrolling Interest"},
177
+
178
+ # EXPE
179
+ {:klass=>:ni, :item_string=>"Profit Loss"},
180
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Gain Loss Arising During Period Net Of Tax"},
181
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Available For Sale Securities Adjustment Net Of Tax"},
182
+ {:klass=>:ooci_nci, :item_string=>"Comprehensive Income Net Of Tax Attributable To Noncontrolling Interest"},
183
+
184
+ # GILD
185
+ {:klass=>:ni, :item_string=>"Profit Loss"},
186
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax"},
187
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment For Sale Of Securities Included In Net Income Net Of Tax"},
188
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
189
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment On Derivatives Included In Net Income Net Of Tax"},
190
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
191
+ {:klass=>:ooci_nci, :item_string=>"Net Income Loss Attributable To Noncontrolling Interest"},
192
+
193
+ # GMCR
194
+ {:klass=>:ni, :item_string=>"Profit Loss"},
195
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
196
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment On Derivatives Included In Net Income Net Of Tax"},
197
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
198
+
199
+ # INTC
200
+ {:klass=>:ni, :item_string=>"Net Income Loss"},
201
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Available For Sale Securities Adjustment Including Other Than Temporary Impairments Net Of Tax"},
202
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Change In Deferred Tax Asset Valuation Allowance Net Of Tax Before Reclassification Adjustments"},
203
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Derivatives Qualifying As Hedges Net Of Tax"},
204
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Change In Prior Service Cost Net Of Tax"},
205
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Change In Actuarial Gain Loss Net Of Tax"},
206
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Gain Loss Arising During Period Net Of Tax"},
207
+
208
+ # ISRG
209
+ {:klass=>:ni, :item_string=>"Net Income Loss"},
210
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
211
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Available For Sale Securities Adjustment Before Reclassification Adjustments Net Of Tax"},
212
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment For Sale Of Securities Included In Net Income Net Of Tax"},
213
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
214
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Reclassification Adjustment On Derivatives Included In Net Income Net Of Tax"},
215
+
216
+ # LIFE (10-k)
217
+ {:klass=>:ni, :item_string=>"Profit Loss"},
218
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Defined Benefit Plans Net Unamortized Gain Loss Arising During Period Net Of Tax"},
219
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Defined Benefit Plan Net Prior Service Costs Credit Arising During Period Net Of Tax"},
220
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Loss Finalization Of Pension And Non Pension Postretirement Plan Valuation Net Of Tax"},
221
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Loss Amortization Pension And Other Postretirement Benefit Plans Net Prior Service Cost Recognized In Net Periodic Pension Cost Net Of Tax"},
222
+ {:klass=>:unkoci, :item_string=>"Cash Flow Hedge Gain Loss Reclassified To Earnings Net"},
223
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Loss Foreign Currency Transaction And Translation Adjustment Net Of Tax"},
224
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Portion Attributable To Noncontrolling Interest"},
225
+ {:klass=>:ooci_nci, :item_string=>"Net Income Loss Attributable To Noncontrolling Interest"},
226
+
227
+ # XRAY
228
+ {:klass=>:ni, :item_string=>"Profit Loss"},
229
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease"},
230
+ {:klass=>:unkoci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax"},
231
+ {:klass=>:foci, :item_string=>"Other Comprehensive Income Available For Sale Securities Adjustment Net Of Tax Period Increase Decrease"},
232
+ {:klass=>:ooci, :item_string=>"Other Comprehensive Income Minimum Pension Liability Net Adjustment Net Of Tax"},
233
+ {:klass=>:ooci_nci, :item_string=>"Comprehensive Income Net Of Tax Attributable To Noncontrolling Interest"} ]
234
+ end
235
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ module FinModeling
2
+ class DebtCostOfCapital
3
+ def self.calculate(opts)
4
+ case
5
+ when opts[:after_tax_cost] && !opts[:before_tax_cost] && !opts[:marginal_tax_rate]
6
+ Rate.new(opts[:after_tax_cost].value)
7
+ when !opts[:after_tax_cost] && opts[:before_tax_cost] && opts[:marginal_tax_rate]
8
+ Rate.new(opts[:before_tax_cost].value * (1.0 - (opts[:marginal_tax_rate].value)))
9
+ else
10
+ raise ArgumentError
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ module FinModeling
2
+
3
+ class EquityChangeCalculation < CompanyFilingCalculation
4
+ include CanCacheClassifications
5
+ include CanCacheSummaries
6
+ include CanClassifyRows
7
+
8
+ BASE_FILENAME = File.join(FinModeling::BASE_PATH, "summaries/equity_change_")
9
+
10
+ ALL_STATES = [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ]
11
+ NEXT_STATES = { nil => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
12
+ :share_issue => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
13
+ :share_repurch => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
14
+ :minority_int => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
15
+ :common_div => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
16
+ :net_income => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
17
+ :oci => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ],
18
+ :preferred_div => [ :share_issue, :share_repurch, :minority_int, :common_div, :net_income, :oci, :preferred_div ] }
19
+
20
+ def summary(args)
21
+ summary_cache_key = args[:period].to_pretty_s
22
+ summary = lookup_cached_summary(summary_cache_key)
23
+ return summary if !summary.nil? && false # FIXME: get rid of "and false"
24
+
25
+ mapping = Xbrlware::ValueMapping.new
26
+ mapping.policy[:unknown] = :no_action
27
+ mapping.policy[:credit] = :no_action
28
+ mapping.policy[:debit] = :flip
29
+
30
+ summary = super(:period => args[:period], :mapping => mapping)
31
+ if !lookup_cached_classifications(BASE_FILENAME, summary.rows) || true # FIXME: get rid of "or true"
32
+ lookahead = [2, summary.rows.length-1].min
33
+ classify_rows(ALL_STATES, NEXT_STATES, summary.rows, FinModeling::EquityChangeItem, lookahead)
34
+ save_cached_classifications(BASE_FILENAME, summary.rows)
35
+ end
36
+
37
+ save_cached_summary(summary_cache_key, summary)
38
+
39
+ return summary
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module FinModeling
2
+ class EquityChangeItem < String
3
+ include HasStringClassifier
4
+
5
+ BASE_FILENAME = File.join(FinModeling::BASE_PATH, "classifiers/eci_")
6
+ TYPES = [ :share_issue, :minority_int, :share_repurch, :common_div, # transactions with shareholders
7
+ :net_income, :oci, :preferred_div ] # comprehensive income
8
+
9
+ # Notes:
10
+ # 1. I need to go back to the EquityChangeCalculation and make sure that it's value mapping policy is accurate
11
+
12
+ # Questions:
13
+ # 1. what about transactions involving options, warrants, convertible debt?
14
+ # 2. what about transactions involving restricted stock?
15
+ # 3. what do I do with the stock-based compensation items?
16
+ # 4. I'm not tagging dividends here. Should I be?
17
+ # 5. None of these items has preferred stock. ... Find an example, so the classifier knows.
18
+
19
+ has_string_classifier(TYPES, EquityChangeItem)
20
+
21
+ def self.load_vectors_and_train
22
+ self._load_vectors_and_train(BASE_FILENAME, FinModeling::EquityChangeItem::TRAINING_VECTORS)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,156 @@
1
+ module FinModeling
2
+ class EquityChangeItem < String
3
+ TRAINING_VECTORS = [ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan Options Exercised And Benefit Plans" },
4
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
5
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
6
+ { :klass=>:oci, :item_string=>"Noncontrolling Interest Increase From Business Combination" },
7
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Acquisitions" },
8
+ { :klass=>:share_repurch, :item_string=>"Treasury Stock Value Acquired Cost Method" },
9
+ { :klass=>:minority_int, :item_string=>"Minority Interest Increase From Stock Issuance" },
10
+ { :klass=>:common_div, :item_string=>"Dividends Common Stock" },
11
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease" },
12
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax" },
13
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
14
+ { :klass=>:net_income, :item_string=>"Profit Loss" },
15
+
16
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
17
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased And Retired During Period Value" },
18
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan" },
19
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
20
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Income Tax Deficiency From Share Based Compensation" },
21
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
22
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Other" },
23
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
24
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Availableforsale Securities Adjustment Net Of Tax Portion Attributable To Parent" },
25
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Portion Attributable To Parent" },
26
+
27
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
28
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Defined Benefit Plans Net Unamortized Gain Loss Arising During Period Net Of Tax" },
29
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
30
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Recognition Of Cumulative Foreign Currency Translation Adjustment Net Of Tax Period Increase Decrease" },
31
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Portion Attributable To Parent" },
32
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
33
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
34
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
35
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan" },
36
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Dividend" },
37
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Restricted Stock Award Net Of Forfeitures" },
38
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Performance Based Restricted Stock Award Net Of Forfeitures" },
39
+ { :klass=>:share_issue, :item_string=>"Stock Withheld For Employee Taxes Value Related To Vested Restricted Stock Units" },
40
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
41
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased During Period Value" },
42
+
43
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
44
+ { :klass=>:share_issue, :item_string=>"Adjustments Related To Tax Withholding For Share Based Compensation" },
45
+ { :klass=>:common_div, :item_string=>"Adjustments To Additional Paid In Capital Dividends In Excess Of Retained Earnings" },
46
+ { :klass=>:common_div, :item_string=>"Adjustments To Additional Paid In Capital Dividends Payable On Restricted Stock" },
47
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
48
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Acquisitions" },
49
+ { :klass=>:oci, :item_string=>"Return Of Escrow Value" },
50
+ { :klass=>:share_repurch, :item_string=>"Restricted Stock Units Assumed And Converted" },
51
+ { :klass=>:oci, :item_string=>"Debt Instrument Decrease Repayments" },
52
+ { :klass=>:oci, :item_string=>"Change In Deferred Tax Asset" },
53
+ { :klass=>:share_repurch, :item_string=>"Treasury Stock Value Acquired Cost Method" },
54
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Reclassification Adjustment For Sale Of Securities Included In Net Income Net Of Tax" },
55
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
56
+
57
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
58
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease" },
59
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
60
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
61
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
62
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased During Period Value" },
63
+ { :klass=>:share_issue, :item_string=>"Adjustments Related To Tax Withholding For Share Based Compensation" },
64
+
65
+ { :klass=>:net_income, :item_string=>"Net Income Loss" },
66
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
67
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease" },
68
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Defined Benefit Plans Adjustment Net Of Tax Period Increase Decrease" },
69
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
70
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased And Retired During Period Value" },
71
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
72
+ { :klass=>:oci, :item_string=>"New Accounting Pronouncement Or Change In Accounting Principle Cumulative Effect Of Change On Equity Or Net Assets" },
73
+
74
+ { :klass=>:net_income, :item_string=>"Profit Loss" },
75
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Defined Benefit Plans Adjustment Net Of Tax Period Increase Decrease" },
76
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax" },
77
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease" },
78
+ { :klass=>:common_div, :item_string=>"Dividends Common Stock Cash" },
79
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
80
+ { :klass=>:minority_int, :item_string=>"Minority Interest Decrease From Redemptions" },
81
+ { :klass=>:share_repurch, :item_string=>"Treasury Stock Value Acquired Cost Method" },
82
+
83
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
84
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
85
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax" },
86
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
87
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
88
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
89
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan" },
90
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value New Issues" },
91
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Share Based Compensation Stock Options Requisite Service Period Recognition" },
92
+ { :klass=>:share_issue, :item_string=>"Adjustment To Additional Paid In Capital Income Tax Effect From Share Based Compensation Net" },
93
+
94
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
95
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Loss Net Of Tax Portion Attributable To Parent" },
96
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased During Period Value" },
97
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
98
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
99
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan" },
100
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
101
+
102
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
103
+ { :klass=>:oci, :item_string=>"Marketable Securities Unrealized Gain Loss" },
104
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
105
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value New Issues" },
106
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Equity Component Of Convertible Debt" },
107
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Acquisitions" },
108
+ { :klass=>:share_repurch, :item_string=>"Adjustments To Additional Paid In Capital Increase In Carrying Amount Of Redeemable Common Stock" },
109
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased And Retired During Period Value" },
110
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
111
+
112
+ { :klass=>:net_income, :item_string=>"Net Income Loss Available To Common Stockholders Basic" },
113
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
114
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Gain Loss On Derivatives Arising During Period Net Of Tax" },
115
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Share Based Compensation" },
116
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
117
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased And Retired During Period Value" },
118
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
119
+
120
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
121
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Restricted Stock Award Net Of Forfeitures" },
122
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
123
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Acquisitions" },
124
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value New Issues" },
125
+ { :klass=>:share_issue, :item_string=>"Earn Out Shares Value Issuable" },
126
+ { :klass=>:share_issue, :item_string=>"Issuance Value Of Earn Out Shares" },
127
+ { :klass=>:share_repurch, :item_string=>"Stock Repurchased During Period Value" },
128
+ { :klass=>:net_income, :item_string=>"Net Income Loss" },
129
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Gain Loss Arising During Period Net Of Tax" },
130
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Unrealized Holding Gain Loss On Securities Arising During Period Net Of Tax" },
131
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
132
+
133
+ { :klass=>:net_income, :item_string=>"Profit Loss" },
134
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Period Increase Decrease" },
135
+ { :klass=>:oci, :item_string=>"Cumulative Effect Of Initial Adoption Of FIN48" },
136
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
137
+ { :klass=>:oci, :item_string=>"Purchase Of Call Options" },
138
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Warrant Issued" },
139
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
140
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Equity Component Of Convertible Debt" },
141
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Acquisitions" },
142
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Restricted Stock Award Net Of Forfeitures" },
143
+ { :klass=>:share_issue, :item_string=>"Tax Effect Of Share Based Compensation Cancellation And Forfeiture" },
144
+
145
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Stock Options Exercised" },
146
+ { :klass=>:share_issue, :item_string=>"Stock Issued During Period Value Employee Stock Purchase Plan" },
147
+ { :klass=>:share_repurch, :item_string=>"Repurchase And Retirement Of Common Stock" },
148
+ { :klass=>:common_div, :item_string=>"Dividends And Dividend Equivalents Paid On Shares Outstanding And Restricted Stock Units" },
149
+ { :klass=>:common_div, :item_string=>"Dividend Equivalents Payable On Restricted Stock Units" },
150
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Sharebased Compensation Requisite Service Period Recognition Value" },
151
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Derivatives Qualifying As Cash Flow Hedges And Derivatives Qualifying As Net Investment Hedges Net Of Tax Portion Attributable To Parent" },
152
+ { :klass=>:oci, :item_string=>"Other Comprehensive Income Foreign Currency Transaction And Translation Adjustment Net Of Tax Portion Attributable To Parent" },
153
+ { :klass=>:share_issue, :item_string=>"Adjustments To Additional Paid In Capital Tax Effect From Share Based Compensation" },
154
+ { :klass=>:net_income, :item_string=>"Net Income Loss" } ]
155
+ end
156
+ end
File without changes
@@ -0,0 +1,119 @@
1
+ module FinModeling
2
+ module FamaFrench
3
+ class MarketHistoricalData
4
+ URL = "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors.zip"
5
+ DATA_PATH = File.join(FinModeling::BASE_PATH, "fama-french/")
6
+ ZIP_FILE = File.join(DATA_PATH, "F-F_Research_Data_Factors.zip")
7
+ TXT_FILE = File.join(DATA_PATH, "F-F_Research_Data_Factors.txt")
8
+ CSV_FILE = File.join(DATA_PATH, "F-F_Research_Data_Factors.csv")
9
+
10
+ def self.download_data!
11
+ FileUtils.mkdir_p(DATA_PATH) if !File.exists?(DATA_PATH)
12
+ `rm #{ZIP_FILE} #{TXT_FILE} #{CSV_FILE} > /dev/null 2>&1`
13
+ `curl -s -o "#{ZIP_FILE}" "#{URL}"`
14
+ prev_pwd=`pwd`
15
+ ` cd #{DATA_PATH};
16
+ unzip -q #{ZIP_FILE};
17
+ rm #{ZIP_FILE};
18
+ echo "date,RmRf,SMB,HML,Rf" > #{CSV_FILE};
19
+ grep '^[0-9][0-9][0-9][0-9][0-9][0-9]' #{TXT_FILE} | sed -e 's/ */,/g' | sed -e 's/
20
+ rm #{TXT_FILE};
21
+ cd #{prev_pwd} `
22
+ end
23
+
24
+ def initialize
25
+ MarketHistoricalData.download_data! if !File.exists?(CSV_FILE)
26
+ @rows = CSV.read(CSV_FILE, headers: true)
27
+ raise RuntimeError.new("couldn't read fama-french data. try deleting #{CSV_FILE} and re-running") if @rows.length < 10
28
+ end
29
+
30
+ def year_and_month_strings
31
+ @rows.map{ |x| x["date"] }
32
+ end
33
+
34
+ def filter_by_date!(dates_to_keep)
35
+ @rows = @rows.select{ |x| dates_to_keep.include?(x["date"]) }
36
+ end
37
+
38
+ def rm_rf # mkt return - risk free rate
39
+ @rows.map{ |x| x["RmRf"].to_f / 100.0 }
40
+ end
41
+
42
+ def smb
43
+ @rows.map{ |x| x["SMB"].to_f / 100.0 }
44
+ end
45
+
46
+ def hml
47
+ @rows.map{ |x| x["HML"].to_f / 100.0 }
48
+ end
49
+
50
+ def rf
51
+ @rows.map{ |x| x["Rf"].to_f / 100.0 }
52
+ end
53
+ end
54
+
55
+ class EquityHistoricalData
56
+ def initialize(company_ticker, num_days)
57
+ daily_quotes = YahooFinance::get_HistoricalQuotes_days(URI::encode(company_ticker), num_days)
58
+ @monthly_quotes = daily_quotes.group_by{ |x| x.date.gsub(/-[0-9][0-9]$/, "") }
59
+ .values
60
+ .map{ |x| x.sort{ |x,y| x.date <=> y.date }.first }
61
+ .sort{ |x,y| x.date <=> y.date }[1..-1]
62
+ end
63
+
64
+ def year_and_month_strings
65
+ @monthly_quotes.map{ |x| x.date.gsub(/-[0-9][0-9]$/, "").gsub(/-/, "") }
66
+ end
67
+
68
+ def filter_by_date!(dates_to_keep)
69
+ @monthly_quotes = @monthly_quotes.select{ |x| dates_to_keep.include?(x.date.gsub(/-[0-9][0-9]$/, "").gsub(/-/, "")) }
70
+ end
71
+
72
+ def monthly_returns(dividends=[])
73
+ @monthly_quotes.each_cons(2)
74
+ .map { |pair|
75
+ div_entry = dividends.find{ |d| d[:ex_eff_date].strftime("%Y-%m") == pair[1].date.gsub(/-[0-9][0-9]$/, "") }
76
+ dividend = div_entry ? div_entry[:cash_amt] : 0.0
77
+ (pair[1].adjClose - pair[0].adjClose + dividend) / pair[0].adjClose
78
+ }
79
+ end
80
+
81
+ def monthly_excess_returns(rf, dividends=[])
82
+ @monthly_quotes.each_cons(2)
83
+ .map { |pair|
84
+ div_entry = dividends.find{ |d| d[:ex_eff_date].strftime("%Y-%m") == pair[1].date.gsub(/-[0-9][0-9]$/, "") }
85
+ dividend = div_entry ? div_entry[:cash_amt] : 0.0
86
+ (pair[1].adjClose - pair[0].adjClose + dividend) / pair[0].adjClose
87
+ }
88
+ .zip(rf).map{ |pair| pair[0] - pair[1] }
89
+ end
90
+ end
91
+
92
+ class EquityCostOfCapital
93
+ def self.from_ticker(company_ticker, num_days=6*365)
94
+ company_historical_data = EquityHistoricalData.new(company_ticker, num_days)
95
+ mkt_historical_data = MarketHistoricalData.new
96
+
97
+ common_dates = company_historical_data.year_and_month_strings & mkt_historical_data.year_and_month_strings
98
+ mkt_historical_data.filter_by_date!(common_dates)
99
+ company_historical_data.filter_by_date!(common_dates)
100
+
101
+ monthly_excess_returns = company_historical_data.monthly_excess_returns(mkt_historical_data.rf)
102
+ y = GSL::Vector.alloc(monthly_excess_returns)
103
+ x = GSL::Matrix.alloc([1.0]*y.length,
104
+ mkt_historical_data.rm_rf.first(y.length),
105
+ mkt_historical_data.smb .first(y.length),
106
+ mkt_historical_data.hml .first(y.length)).transpose
107
+ c, cov, chisq, status = GSL::MultiFit.linear(x, y)
108
+
109
+ avg_rm_rf = mkt_historical_data.rm_rf.inject(:+) / mkt_historical_data.rm_rf.length.to_f
110
+ avg_smb = mkt_historical_data.smb.inject(:+) / mkt_historical_data.smb.length.to_f
111
+ avg_hml = mkt_historical_data.hml.inject(:+) / mkt_historical_data.hml.length.to_f
112
+
113
+ monthly_cost_of_equity = mkt_historical_data.rf.last + (c[1] * avg_rm_rf) + (c[2] * avg_smb) + (c[3] * avg_hml)
114
+ annual_cost_of_equity = ((monthly_cost_of_equity+1.0)**12)-1.0
115
+ Rate.new(annual_cost_of_equity)
116
+ end
117
+ end
118
+ end
119
+ end