finrb 0.0.1 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/issue_template.md +15 -0
- data/.github/pull_request_template.md +17 -0
- data/.github/workflows/ci.yml +21 -0
- data/.github/workflows/codeql.yml +72 -0
- data/.github/workflows/rubocop.yml +24 -0
- data/.rubocop.yml +270 -5
- data/.semver +2 -2
- data/CHANGELOG.md +35 -26
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +5 -1
- data/Rakefile +10 -10
- data/docs/api.md +238 -256
- data/finrb.gemspec +24 -80
- data/lib/finrb/amortization.rb +7 -7
- data/lib/finrb/cashflows.rb +40 -41
- data/lib/finrb/config.rb +1 -1
- data/lib/finrb/decimal.rb +2 -2
- data/lib/finrb/rates.rb +5 -5
- data/lib/finrb/transaction.rb +1 -1
- data/lib/finrb/utils.rb +78 -77
- data/lib/finrb.rb +9 -9
- metadata +25 -63
- data/.travis.yml +0 -7
data/docs/api.md
CHANGED
@@ -8,121 +8,103 @@ Utils is based on R's [FinCal](https://github.com/felixfan/FinCal) library (port
|
|
8
8
|
|
9
9
|
Provides the following functions:
|
10
10
|
|
11
|
-
|
11
|
+
- Basic Earnings Per Share
|
12
12
|
|
13
|
-
|
13
|
+
- Bond-equivalent yield (BEY), 2 x the semiannual discount rate
|
14
14
|
|
15
|
-
|
15
|
+
- Calculate the net increase in common shares from the potential exercise of stock options or warrants
|
16
16
|
|
17
|
-
|
17
|
+
- Calculate weighted average shares - weighted average number of common shares
|
18
18
|
|
19
|
-
|
19
|
+
- Cash ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
20
20
|
|
21
|
-
|
21
|
+
- Computing Coefficient of variation
|
22
22
|
|
23
|
-
|
23
|
+
- Computing HPR, the holding period return
|
24
24
|
|
25
|
-
|
25
|
+
- Computing IRR, the internal rate of return
|
26
26
|
|
27
|
-
|
27
|
+
- Computing NPV, the PV of the cash flows less the initial (time = 0) outlay
|
28
28
|
|
29
|
-
|
29
|
+
- Computing Roy's safety-first ratio
|
30
30
|
|
31
|
-
|
31
|
+
- Computing Sampling error
|
32
32
|
|
33
|
-
|
33
|
+
- Computing Sharpe Ratio
|
34
34
|
|
35
|
-
|
35
|
+
- Computing TWRR, the time-weighted rate of return
|
36
36
|
|
37
|
-
|
37
|
+
- Computing bank discount yield (BDY) for a T-bill
|
38
38
|
|
39
|
-
|
39
|
+
- Computing money market yield (MMY) for a T-bill
|
40
40
|
|
41
|
-
|
41
|
+
- Computing the future value of an uneven cash flow series
|
42
42
|
|
43
|
-
|
43
|
+
- Computing the present value of an uneven cash flow series
|
44
44
|
|
45
|
-
|
45
|
+
- Computing the rate of return for each period
|
46
46
|
|
47
|
-
|
47
|
+
- Convert a given continuous compounded rate to a norminal rate
|
48
48
|
|
49
|
-
|
49
|
+
- Convert a given norminal rate to a continuous compounded rate
|
50
50
|
|
51
|
-
|
51
|
+
- Convert holding period return to the effective annual rate
|
52
52
|
|
53
|
-
|
53
|
+
- Convert stated annual rate to the effective annual rate (with continuous compounding)
|
54
54
|
|
55
|
-
|
55
|
+
- Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)
|
56
56
|
|
57
|
-
|
57
|
+
- Current ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
58
58
|
|
59
|
-
|
59
|
+
- Debt ratio - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
60
60
|
|
61
|
-
|
61
|
+
- Depreciation Expense Recognition - Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
|
62
62
|
|
63
|
-
|
63
|
+
- Depreciation Expense Recognition - double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance.
|
64
64
|
|
65
|
-
|
65
|
+
- Diluted Earnings Per Share
|
66
66
|
|
67
|
-
|
67
|
+
- Equivalent/proportional Interest Rates
|
68
68
|
|
69
|
-
|
69
|
+
- Estimate future value (fv) (of a single sum)
|
70
70
|
|
71
|
-
|
71
|
+
- Estimate future value of an annuity
|
72
72
|
|
73
|
-
|
73
|
+
- Estimate period payment
|
74
74
|
|
75
|
-
|
75
|
+
- Estimate present value (pv) (of a single sum) (of an annuity)
|
76
76
|
|
77
|
-
|
77
|
+
- Estimate present value of a perpetuity
|
78
78
|
|
79
|
-
|
79
|
+
- Estimate the number of periods
|
80
80
|
|
81
|
-
|
81
|
+
- Financial leverage - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
82
82
|
|
83
|
-
|
83
|
+
- Geometric mean return
|
84
84
|
|
85
|
-
|
85
|
+
- Gross profit margin - Evaluate a company's financial performance
|
86
86
|
|
87
|
-
|
87
|
+
- Harmonic mean, average price
|
88
88
|
|
89
|
-
|
89
|
+
- Long-term debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
90
90
|
|
91
|
-
|
91
|
+
- Net profit margin - Evaluate a company's financial performance
|
92
92
|
|
93
|
-
|
93
|
+
- Quick ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
94
94
|
|
95
|
-
|
95
|
+
- Rate of return for a perpetuity
|
96
96
|
|
97
|
-
|
97
|
+
- Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
* Rate of return for a perpetuity
|
102
|
-
|
103
|
-
* Computing Sampling error
|
104
|
-
|
105
|
-
* Computing Roy's safety-first ratio
|
106
|
-
|
107
|
-
* Computing Sharpe Ratio
|
108
|
-
|
109
|
-
* Depreciation Expense Recognition - Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
|
110
|
-
|
111
|
-
* Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
112
|
-
|
113
|
-
* Computing TWRR, the time-weighted rate of return
|
114
|
-
|
115
|
-
* Calculate weighted average shares - weighted average number of common shares
|
116
|
-
|
117
|
-
* Weighted mean as a portfolio return
|
99
|
+
- Weighted mean as a portfolio return
|
118
100
|
|
119
101
|
### Computing bank discount yield (BDY) for a T-bill
|
120
102
|
|
121
|
-
|
103
|
+
- Param - d - the dollar discount, which is equal to the difference between the face value of the bill and the purchase price
|
122
104
|
|
123
|
-
|
105
|
+
- Param - f - the face value (par value) of the bill
|
124
106
|
|
125
|
-
|
107
|
+
- Param - t - number of days remaining until maturity
|
126
108
|
|
127
109
|
Examples:
|
128
110
|
|
@@ -132,9 +114,9 @@ Finrb::Utils.bdy(d=1500,f=100000,t=120)
|
|
132
114
|
|
133
115
|
### Computing money market yield (MMY) for a T-bill
|
134
116
|
|
135
|
-
|
117
|
+
- Param - bdy - bank discount yield
|
136
118
|
|
137
|
-
|
119
|
+
- Param - t - number of days remaining until maturity
|
138
120
|
|
139
121
|
Examples:
|
140
122
|
|
@@ -142,13 +124,13 @@ Examples:
|
|
142
124
|
Finrb::Utils.bdy2mmy(bdy=0.045,t=120)
|
143
125
|
```
|
144
126
|
|
145
|
-
### Cash ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due
|
127
|
+
### Cash ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
146
128
|
|
147
|
-
|
129
|
+
- Param - cash - cash
|
148
130
|
|
149
|
-
|
131
|
+
- Param - ms - marketable securities
|
150
132
|
|
151
|
-
|
133
|
+
- Param - cl - current liabilities
|
152
134
|
|
153
135
|
Examples:
|
154
136
|
|
@@ -158,9 +140,9 @@ Finrb::Utils.cash_ratio(cash=3000,ms=2000,cl=2000)
|
|
158
140
|
|
159
141
|
### Computing Coefficient of variation
|
160
142
|
|
161
|
-
|
143
|
+
- Param - sd - standard deviation
|
162
144
|
|
163
|
-
|
145
|
+
- Param - avg - average value
|
164
146
|
|
165
147
|
Examples:
|
166
148
|
|
@@ -170,37 +152,37 @@ Finrb::Utils.coefficient_variation(sd=0.15,avg=0.39)
|
|
170
152
|
|
171
153
|
### Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)
|
172
154
|
|
173
|
-
|
155
|
+
- Param - uinv - units of beginning inventory
|
174
156
|
|
175
|
-
|
157
|
+
- Param - pinv - prince of beginning inventory
|
176
158
|
|
177
|
-
|
159
|
+
- Param - units - nx1 vector of inventory units. inventory purchased ordered by time (from first to last)
|
178
160
|
|
179
|
-
|
161
|
+
- Param - price - nx1 vector of inventory price. same order as units
|
180
162
|
|
181
|
-
|
163
|
+
- Param - sinv - units of sold inventory
|
182
164
|
|
183
|
-
|
165
|
+
- Param - method - inventory methods: FIFO (first in first out, permitted under both US and IFRS), LIFO (late in first out, US only), WAC (weighted average cost,US and IFRS)
|
184
166
|
|
185
167
|
Examples:
|
186
168
|
|
187
169
|
```ruby
|
188
|
-
Finrb::Utils.cogs(uinv=2,pinv=2,units=
|
170
|
+
Finrb::Utils.cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="FIFO")
|
189
171
|
```
|
190
172
|
|
191
173
|
```ruby
|
192
|
-
Finrb::Utils.cogs(uinv=2,pinv=2,units=
|
174
|
+
Finrb::Utils.cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="LIFO")
|
193
175
|
```
|
194
176
|
|
195
177
|
```ruby
|
196
|
-
Finrb::Utils.cogs(uinv=2,pinv=2,units=
|
178
|
+
Finrb::Utils.cogs(uinv=2,pinv=2,units=[3,5],price=[3,5],sinv=7,method="WAC")
|
197
179
|
```
|
198
180
|
|
199
|
-
### Current ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due
|
181
|
+
### Current ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
200
182
|
|
201
|
-
|
183
|
+
- Param - ca - current assets
|
202
184
|
|
203
|
-
|
185
|
+
- Param - cl - current liabilities
|
204
186
|
|
205
187
|
Examples:
|
206
188
|
|
@@ -208,13 +190,13 @@ Examples:
|
|
208
190
|
Finrb::Utils.current_ratio(ca=8000,cl=2000)
|
209
191
|
```
|
210
192
|
|
211
|
-
### Depreciation Expense Recognition - double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance
|
193
|
+
### Depreciation Expense Recognition - double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance.
|
212
194
|
|
213
|
-
|
195
|
+
- Param - cost - cost of long-lived assets
|
214
196
|
|
215
|
-
|
197
|
+
- Param - rv - residual value of the long-lived assets at the end of its useful life. DDB does not explicitly use the asset's residual value in the calculations, but depreciation ends once the estimated residual value has been reached. If the asset is expected to have no residual value, the DB method will never fully depreciate it, so the DB method is typically changed to straight-line at some point in the asset's life.
|
216
198
|
|
217
|
-
|
199
|
+
- Param - t - length of the useful life
|
218
200
|
|
219
201
|
Examples:
|
220
202
|
|
@@ -222,11 +204,11 @@ Examples:
|
|
222
204
|
Finrb::Utils.ddb(cost=1200,rv=200,t=5)
|
223
205
|
```
|
224
206
|
|
225
|
-
### Debt ratio - Solvency ratios measure the firm's ability to satisfy its long-term obligations
|
207
|
+
### Debt ratio - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
226
208
|
|
227
|
-
|
209
|
+
- Param - td - total debt
|
228
210
|
|
229
|
-
|
211
|
+
- Param - ta - total assets
|
230
212
|
|
231
213
|
Examples:
|
232
214
|
|
@@ -236,23 +218,23 @@ Finrb::Utils.debt_ratio(td=6000,ta=20000)
|
|
236
218
|
|
237
219
|
### Diluted Earnings Per Share
|
238
220
|
|
239
|
-
|
221
|
+
- Param - ni - net income
|
240
222
|
|
241
|
-
|
223
|
+
- Param - pd - preferred dividends
|
242
224
|
|
243
|
-
|
225
|
+
- Param - cpd - dividends on convertible preferred stock
|
244
226
|
|
245
|
-
|
227
|
+
- Param - cdi - interest on convertible debt
|
246
228
|
|
247
|
-
|
229
|
+
- Param - tax - tax rate
|
248
230
|
|
249
|
-
|
231
|
+
- Param - w - weighted average number of common shares outstanding
|
250
232
|
|
251
|
-
|
233
|
+
- Param - cps - shares from conversion of convertible preferred stock
|
252
234
|
|
253
|
-
|
235
|
+
- Param - cds - shares from conversion of convertible debt
|
254
236
|
|
255
|
-
|
237
|
+
- Param - iss - shares issuable from stock options
|
256
238
|
|
257
239
|
Examples:
|
258
240
|
|
@@ -274,20 +256,20 @@ Finrb::Utils.diluted_eps(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000
|
|
274
256
|
|
275
257
|
### Computing the rate of return for each period
|
276
258
|
|
277
|
-
|
259
|
+
- Param - n - number of periods
|
278
260
|
|
279
|
-
|
261
|
+
- Param - pv - present value
|
280
262
|
|
281
|
-
|
263
|
+
- Param - fv - future value
|
282
264
|
|
283
|
-
|
265
|
+
- Param - pmt - payment per period
|
284
266
|
|
285
|
-
|
267
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
286
268
|
|
287
|
-
|
269
|
+
- Param - lower - the lower end points of the rate of return to be searched.
|
288
270
|
|
289
|
-
|
290
|
-
@importFrom stats uniroot
|
271
|
+
- Param - upper - the upper end points of the rate of return to be searched.
|
272
|
+
@importFrom stats uniroot
|
291
273
|
|
292
274
|
Examples:
|
293
275
|
|
@@ -297,9 +279,9 @@ Finrb::Utils.discount_rate(n=5,pv=0,fv=600,pmt=-100,type=0)
|
|
297
279
|
|
298
280
|
### Convert stated annual rate to the effective annual rate
|
299
281
|
|
300
|
-
|
282
|
+
- Param - r - stated annual rate
|
301
283
|
|
302
|
-
|
284
|
+
- Param - m - number of compounding periods per year
|
303
285
|
|
304
286
|
Examples:
|
305
287
|
|
@@ -313,7 +295,7 @@ Finrb::Utils.ear(0.04,365)
|
|
313
295
|
|
314
296
|
### Convert stated annual rate to the effective annual rate with continuous compounding
|
315
297
|
|
316
|
-
|
298
|
+
- Param - r - stated annual rate
|
317
299
|
|
318
300
|
Examples:
|
319
301
|
|
@@ -327,7 +309,7 @@ Finrb::Utils.ear_continuous(0.03)
|
|
327
309
|
|
328
310
|
### Bond-equivalent yield (BEY), 2 x the semiannual discount rate
|
329
311
|
|
330
|
-
|
312
|
+
- Param - ear - effective annual rate
|
331
313
|
|
332
314
|
Examples:
|
333
315
|
|
@@ -337,9 +319,9 @@ Finrb::Utils.ear2bey(ear=0.08)
|
|
337
319
|
|
338
320
|
### Computing HPR, the holding period return
|
339
321
|
|
340
|
-
|
322
|
+
- Param - ear - effective annual rate
|
341
323
|
|
342
|
-
|
324
|
+
- Param - t - number of days remaining until maturity
|
343
325
|
|
344
326
|
Examples:
|
345
327
|
|
@@ -351,56 +333,56 @@ Finrb::Utils.ear2hpr(ear=0.05039,t=150)
|
|
351
333
|
|
352
334
|
@description An interest rate to be applied n times p.a. can be converted to an equivalent rate to be applied p times p.a.
|
353
335
|
|
354
|
-
|
336
|
+
- Param - r - interest rate to be applied n times per year (r is annual rate!)
|
355
337
|
|
356
|
-
|
338
|
+
- Param - n - times that the interest rate r were compounded per year
|
357
339
|
|
358
|
-
|
340
|
+
- Param - p - times that the equivalent rate were compounded per year
|
359
341
|
|
360
|
-
|
342
|
+
- Param - type - equivalent interest rates ('e',default) or proportional interest rates ('p')
|
361
343
|
|
362
344
|
Examples:
|
363
345
|
|
364
|
-
|
346
|
+
- monthly interest rat equivalent to 5% compounded per year
|
365
347
|
|
366
348
|
```ruby
|
367
349
|
Finrb::Utils.eir(r=0.05,n=1,p=12)
|
368
350
|
```
|
369
351
|
|
370
|
-
|
352
|
+
- monthly interest rat equivalent to 5% compounded per half year
|
371
353
|
|
372
354
|
```ruby
|
373
355
|
Finrb::Utils.eir(r=0.05,n=2,p=12)
|
374
356
|
```
|
375
357
|
|
376
|
-
|
358
|
+
- monthly interest rat equivalent to 5% compounded per quarter
|
377
359
|
|
378
360
|
```ruby
|
379
361
|
Finrb::Utils.eir(r=0.05,n=4,p=12)
|
380
362
|
```
|
381
363
|
|
382
|
-
|
364
|
+
- annual interest rate equivalent to 5% compounded per month
|
383
365
|
|
384
366
|
```ruby
|
385
367
|
Finrb::Utils.eir(r=0.05,n=12,p=1)
|
386
368
|
```
|
387
369
|
|
388
|
-
|
389
|
-
ear(r=0.05,m=12)
|
370
|
+
- this is equivalent to
|
371
|
+
ear(r=0.05,m=12)
|
390
372
|
|
391
|
-
|
373
|
+
- quarter interest rate equivalent to 5% compounded per year
|
392
374
|
|
393
375
|
```ruby
|
394
376
|
Finrb::Utils.eir(r=0.05,n=1,p=4)
|
395
377
|
```
|
396
378
|
|
397
|
-
|
379
|
+
- quarter interest rate equivalent to 5% compounded per month
|
398
380
|
|
399
381
|
```ruby
|
400
382
|
Finrb::Utils.eir(r=0.05,n=12,p=4)
|
401
383
|
```
|
402
384
|
|
403
|
-
|
385
|
+
- monthly proportional interest rate which is equivalent to a simple annual interest
|
404
386
|
|
405
387
|
```ruby
|
406
388
|
Finrb::Utils.eir(r=0.05,p=12,type='p')
|
@@ -408,11 +390,11 @@ Finrb::Utils.eir(r=0.05,p=12,type='p')
|
|
408
390
|
|
409
391
|
### Basic Earnings Per Share
|
410
392
|
|
411
|
-
|
393
|
+
- Param - ni - net income
|
412
394
|
|
413
|
-
|
395
|
+
- Param - pd - preferred dividends
|
414
396
|
|
415
|
-
|
397
|
+
- Param - w - weighted average number of common shares outstanding
|
416
398
|
|
417
399
|
Examples:
|
418
400
|
|
@@ -420,11 +402,11 @@ Examples:
|
|
420
402
|
Finrb::Utils.eps(ni=10000,pd=1000,w=11000)
|
421
403
|
```
|
422
404
|
|
423
|
-
### Financial leverage - Solvency ratios measure the firm's ability to satisfy its long-term obligations
|
405
|
+
### Financial leverage - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
424
406
|
|
425
|
-
|
407
|
+
- Param - te - total equity
|
426
408
|
|
427
|
-
|
409
|
+
- Param - ta - total assets
|
428
410
|
|
429
411
|
Examples:
|
430
412
|
|
@@ -434,15 +416,15 @@ Finrb::Utils.financial_leverage(te=16000,ta=20000)
|
|
434
416
|
|
435
417
|
### Estimate future value (fv)
|
436
418
|
|
437
|
-
|
419
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
438
420
|
|
439
|
-
|
421
|
+
- Param - n - number of periods
|
440
422
|
|
441
|
-
|
423
|
+
- Param - pv - present value
|
442
424
|
|
443
|
-
|
425
|
+
- Param - pmt - payment per period
|
444
426
|
|
445
|
-
|
427
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
446
428
|
|
447
429
|
Examples:
|
448
430
|
|
@@ -452,13 +434,13 @@ Finrb::Utils.fv(r=0.07,n=10,pv=1000,pmt=10)
|
|
452
434
|
|
453
435
|
### Estimate future value of an annuity
|
454
436
|
|
455
|
-
|
437
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
456
438
|
|
457
|
-
|
439
|
+
- Param - n - number of periods
|
458
440
|
|
459
|
-
|
441
|
+
- Param - pmt - payment per period
|
460
442
|
|
461
|
-
|
443
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
462
444
|
|
463
445
|
Examples:
|
464
446
|
|
@@ -472,11 +454,11 @@ Finrb::Utils.fv_annuity(r=0.03,n=12,pmt=-1000,type=1)
|
|
472
454
|
|
473
455
|
### Estimate future value (fv) of a single sum
|
474
456
|
|
475
|
-
|
457
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
476
458
|
|
477
|
-
|
459
|
+
- Param - n - number of periods
|
478
460
|
|
479
|
-
|
461
|
+
- Param - pv - present value
|
480
462
|
|
481
463
|
Examples:
|
482
464
|
|
@@ -490,31 +472,31 @@ Finrb::Utils.fv_simple(r=0.04,n=20,pv=-50000)
|
|
490
472
|
|
491
473
|
### Computing the future value of an uneven cash flow series
|
492
474
|
|
493
|
-
|
475
|
+
- Param - r - stated annual rate
|
494
476
|
|
495
|
-
|
477
|
+
- Param - cf - uneven cash flow
|
496
478
|
|
497
479
|
Examples:
|
498
480
|
|
499
481
|
```ruby
|
500
|
-
Finrb::Utils.fv_uneven(r=0.1, cf=
|
482
|
+
Finrb::Utils.fv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
|
501
483
|
```
|
502
484
|
|
503
485
|
### Geometric mean return
|
504
486
|
|
505
|
-
|
487
|
+
- Param - r - returns over multiple periods
|
506
488
|
|
507
489
|
Examples:
|
508
490
|
|
509
491
|
```ruby
|
510
|
-
Finrb::Utils.geometric_mean(r=
|
492
|
+
Finrb::Utils.geometric_mean(r=[-0.0934, 0.2345, 0.0892])
|
511
493
|
```
|
512
494
|
|
513
495
|
### Gross profit margin - Evaluate a company's financial performance
|
514
496
|
|
515
|
-
|
497
|
+
- Param - gp - gross profit, equal to revenue minus cost of goods sold (cogs)
|
516
498
|
|
517
|
-
|
499
|
+
- Param - rv - revenue (sales)
|
518
500
|
|
519
501
|
Examples:
|
520
502
|
|
@@ -524,21 +506,21 @@ Finrb::Utils.gpm(gp=1000,rv=20000)
|
|
524
506
|
|
525
507
|
### Harmonic mean, average price
|
526
508
|
|
527
|
-
|
509
|
+
- Param - p - price over multiple periods
|
528
510
|
|
529
511
|
Examples:
|
530
512
|
|
531
513
|
```ruby
|
532
|
-
Finrb::Utils.harmonic_mean(p=
|
514
|
+
Finrb::Utils.harmonic_mean(p=[8,9,10])
|
533
515
|
```
|
534
516
|
|
535
517
|
### Computing HPR, the holding period return
|
536
518
|
|
537
|
-
|
519
|
+
- Param - ev - ending value
|
538
520
|
|
539
|
-
|
521
|
+
- Param - bv - beginning value
|
540
522
|
|
541
|
-
|
523
|
+
- Param - cfr - cash flow received
|
542
524
|
|
543
525
|
Examples:
|
544
526
|
|
@@ -548,9 +530,9 @@ Finrb::Utils.hpr(ev=33,bv=30,cfr=0.5)
|
|
548
530
|
|
549
531
|
### Bond-equivalent yield (BEY), 2 x the semiannual discount rate
|
550
532
|
|
551
|
-
|
533
|
+
- Param - hpr - holding period return
|
552
534
|
|
553
|
-
|
535
|
+
- Param - t - number of month remaining until maturity
|
554
536
|
|
555
537
|
Examples:
|
556
538
|
|
@@ -560,9 +542,9 @@ Finrb::Utils.hpr2bey(hpr=0.02,t=3)
|
|
560
542
|
|
561
543
|
### Convert holding period return to the effective annual rate
|
562
544
|
|
563
|
-
|
545
|
+
- Param - hpr - holding period return
|
564
546
|
|
565
|
-
|
547
|
+
- Param - t - number of days remaining until maturity
|
566
548
|
|
567
549
|
Examples:
|
568
550
|
|
@@ -572,9 +554,9 @@ Finrb::Utils.hpr2ear(hpr=0.015228,t=120)
|
|
572
554
|
|
573
555
|
### Computing money market yield (MMY) for a T-bill
|
574
556
|
|
575
|
-
|
557
|
+
- Param - hpr - holding period return
|
576
558
|
|
577
|
-
|
559
|
+
- Param - t - number of days remaining until maturity
|
578
560
|
|
579
561
|
Examples:
|
580
562
|
|
@@ -584,46 +566,46 @@ Finrb::Utils.hpr2mmy(hpr=0.01523,t=120)
|
|
584
566
|
|
585
567
|
### Computing IRR, the internal rate of return
|
586
568
|
|
587
|
-
|
588
|
-
@importFrom stats uniroot
|
569
|
+
- Param - cf - cash flow,the first cash flow is the initial outlay
|
570
|
+
@importFrom stats uniroot
|
589
571
|
|
590
572
|
Examples:
|
591
573
|
|
592
574
|
```ruby
|
593
|
-
Finrb::Utils.irr(cf=
|
575
|
+
Finrb::Utils.irr(cf=[-5, 1.6, 2.4, 2.8])
|
594
576
|
```
|
595
577
|
|
596
578
|
### Computing IRR, the internal rate of return
|
597
579
|
|
598
580
|
@description This function is the same as irr but can calculate negative value. This function may take a very long time. You can use larger cutoff and larger step to get a less precision irr first. Then based on the result, change from and to, to narrow down the interval, and use a smaller step to get a more precision irr.
|
599
581
|
|
600
|
-
|
582
|
+
- Param - cf - cash flow,the first cash flow is the initial outlay
|
601
583
|
|
602
|
-
|
584
|
+
- Param - cutoff - threshold to take npv as zero
|
603
585
|
|
604
|
-
|
586
|
+
- Param - from - smallest irr to try
|
605
587
|
|
606
|
-
|
588
|
+
- Param - to - largest irr to try
|
607
589
|
|
608
|
-
|
590
|
+
- Param - step - increment of the irr
|
609
591
|
|
610
592
|
Examples:
|
611
593
|
|
612
594
|
```ruby
|
613
|
-
Finrb::Utils.irr2(cf=
|
595
|
+
Finrb::Utils.irr2(cf=[-5, 1.6, 2.4, 2.8])
|
614
596
|
```
|
615
597
|
|
616
598
|
```ruby
|
617
|
-
Finrb::Utils.irr2(cf=
|
599
|
+
Finrb::Utils.irr2(cf=[-200, 50, 60, -70, 30, 20])
|
618
600
|
```
|
619
601
|
|
620
602
|
### Calculate the net increase in common shares from the potential exercise of stock options or warrants
|
621
603
|
|
622
|
-
|
604
|
+
- Param - amp - average market price over the year
|
623
605
|
|
624
|
-
|
606
|
+
- Param - ep - exercise price of the options or warrants
|
625
607
|
|
626
|
-
|
608
|
+
- Param - n - number of common shares that the options and warrants can be convened into
|
627
609
|
|
628
610
|
Examples:
|
629
611
|
|
@@ -631,11 +613,11 @@ Examples:
|
|
631
613
|
Finrb::Utils.iss(amp=20,ep=15,n=10000)
|
632
614
|
```
|
633
615
|
|
634
|
-
### Long-term debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations
|
616
|
+
### Long-term debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
635
617
|
|
636
|
-
|
618
|
+
- Param - ltd - long-term debt
|
637
619
|
|
638
|
-
|
620
|
+
- Param - te - total equity
|
639
621
|
|
640
622
|
Examples:
|
641
623
|
|
@@ -645,9 +627,9 @@ Finrb::Utils.lt_d2e(ltd=8000,te=20000)
|
|
645
627
|
|
646
628
|
### Computing HPR, the holding period return
|
647
629
|
|
648
|
-
|
630
|
+
- Param - mmy - money market yield
|
649
631
|
|
650
|
-
|
632
|
+
- Param - t - number of days remaining until maturity
|
651
633
|
|
652
634
|
Examples:
|
653
635
|
|
@@ -657,15 +639,15 @@ Finrb::Utils.mmy2hpr(mmy=0.04898,t=150)
|
|
657
639
|
|
658
640
|
### Estimate the number of periods
|
659
641
|
|
660
|
-
|
642
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
661
643
|
|
662
|
-
|
644
|
+
- Param - pv - present value
|
663
645
|
|
664
|
-
|
646
|
+
- Param - fv - future value
|
665
647
|
|
666
|
-
|
648
|
+
- Param - pmt - payment per period
|
667
649
|
|
668
|
-
|
650
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
669
651
|
|
670
652
|
Examples:
|
671
653
|
|
@@ -679,9 +661,9 @@ Finrb::Utils.n_period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1)
|
|
679
661
|
|
680
662
|
### Net profit margin - Evaluate a company's financial performance
|
681
663
|
|
682
|
-
|
664
|
+
- Param - ni - net income
|
683
665
|
|
684
|
-
|
666
|
+
- Param - rv - revenue (sales)
|
685
667
|
|
686
668
|
Examples:
|
687
669
|
|
@@ -691,27 +673,27 @@ Finrb::Utils.npm(ni=8000,rv=20000)
|
|
691
673
|
|
692
674
|
### Computing NPV, the PV of the cash flows less the initial (time = 0) outlay
|
693
675
|
|
694
|
-
|
676
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
695
677
|
|
696
|
-
|
678
|
+
- Param - cf - cash flow,the first cash flow is the initial outlay
|
697
679
|
|
698
680
|
Examples:
|
699
681
|
|
700
682
|
```ruby
|
701
|
-
Finrb::Utils.npv(r=0.12, cf=
|
683
|
+
Finrb::Utils.npv(r=0.12, cf=[-5, 1.6, 2.4, 2.8])
|
702
684
|
```
|
703
685
|
|
704
686
|
### Estimate period payment
|
705
687
|
|
706
|
-
|
688
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
707
689
|
|
708
|
-
|
690
|
+
- Param - n - number of periods
|
709
691
|
|
710
|
-
|
692
|
+
- Param - pv - present value
|
711
693
|
|
712
|
-
|
694
|
+
- Param - fv - future value
|
713
695
|
|
714
|
-
|
696
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
715
697
|
|
716
698
|
Examples:
|
717
699
|
|
@@ -729,15 +711,15 @@ Finrb::Utils.pmt(0.08,10,-1000,10,1)
|
|
729
711
|
|
730
712
|
### Estimate present value (pv)
|
731
713
|
|
732
|
-
|
714
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
733
715
|
|
734
|
-
|
716
|
+
- Param - n - number of periods
|
735
717
|
|
736
|
-
|
718
|
+
- Param - fv - future value
|
737
719
|
|
738
|
-
|
720
|
+
- Param - pmt - payment per period
|
739
721
|
|
740
|
-
|
722
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
741
723
|
|
742
724
|
Examples:
|
743
725
|
|
@@ -751,13 +733,13 @@ Finrb::Utils.pv(r=0.05,n=20,fv=1000,pmt=10,type=1)
|
|
751
733
|
|
752
734
|
### Estimate present value (pv) of an annuity
|
753
735
|
|
754
|
-
|
736
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
755
737
|
|
756
|
-
|
738
|
+
- Param - n - number of periods
|
757
739
|
|
758
|
-
|
740
|
+
- Param - pmt - payment per period
|
759
741
|
|
760
|
-
|
742
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
761
743
|
|
762
744
|
Examples:
|
763
745
|
|
@@ -771,13 +753,13 @@ Finrb::Utils.pv_annuity(r=0.0425,n=3,pmt=30000)
|
|
771
753
|
|
772
754
|
### Estimate present value of a perpetuity
|
773
755
|
|
774
|
-
|
756
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
775
757
|
|
776
|
-
|
758
|
+
- Param - g - growth rate of perpetuity
|
777
759
|
|
778
|
-
|
760
|
+
- Param - pmt - payment per period
|
779
761
|
|
780
|
-
|
762
|
+
- Param - type - payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)
|
781
763
|
|
782
764
|
Examples:
|
783
765
|
|
@@ -795,11 +777,11 @@ Finrb::Utils.pv_perpetuity(r=0.1,pmt=1000)
|
|
795
777
|
|
796
778
|
### Estimate present value (pv) of a single sum
|
797
779
|
|
798
|
-
|
780
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
799
781
|
|
800
|
-
|
782
|
+
- Param - n - number of periods
|
801
783
|
|
802
|
-
|
784
|
+
- Param - fv - future value
|
803
785
|
|
804
786
|
Examples:
|
805
787
|
|
@@ -813,25 +795,25 @@ Finrb::Utils.pv_simple(r=0.03,n=3,fv=1000)
|
|
813
795
|
|
814
796
|
### Computing the present value of an uneven cash flow series
|
815
797
|
|
816
|
-
|
798
|
+
- Param - r - discount rate, or the interest rate at which the amount will be compounded each period
|
817
799
|
|
818
|
-
|
800
|
+
- Param - cf - uneven cash flow
|
819
801
|
|
820
802
|
Examples:
|
821
803
|
|
822
804
|
```ruby
|
823
|
-
Finrb::Utils.pv_uneven(r=0.1, cf=
|
805
|
+
Finrb::Utils.pv_uneven(r=0.1, cf=[-1000, -500, 0, 4000, 3500, 2000])
|
824
806
|
```
|
825
807
|
|
826
|
-
### Quick ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due
|
808
|
+
### Quick ratio - Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
|
827
809
|
|
828
|
-
|
810
|
+
- Param - cash - cash
|
829
811
|
|
830
|
-
|
812
|
+
- Param - ms - marketable securities
|
831
813
|
|
832
|
-
|
814
|
+
- Param - rc - receivables
|
833
815
|
|
834
|
-
|
816
|
+
- Param - cl - current liabilities
|
835
817
|
|
836
818
|
Examples:
|
837
819
|
|
@@ -841,9 +823,9 @@ Finrb::Utils.quick_ratio(cash=3000,ms=2000,rc=1000,cl=2000)
|
|
841
823
|
|
842
824
|
### Convert a given norminal rate to a continuous compounded rate
|
843
825
|
|
844
|
-
|
826
|
+
- Param - r - norminal rate
|
845
827
|
|
846
|
-
|
828
|
+
- Param - m - number of times compounded each year
|
847
829
|
|
848
830
|
Examples:
|
849
831
|
|
@@ -853,9 +835,9 @@ Finrb::Utils.r_continuous(r=0.03,m=4)
|
|
853
835
|
|
854
836
|
### Convert a given continuous compounded rate to a norminal rate
|
855
837
|
|
856
|
-
|
838
|
+
- Param - rc - continuous compounded rate
|
857
839
|
|
858
|
-
|
840
|
+
- Param - m - number of desired times compounded each year
|
859
841
|
|
860
842
|
Examples:
|
861
843
|
|
@@ -869,9 +851,9 @@ Finrb::Utils.r_norminal(rc=0.03,m=4)
|
|
869
851
|
|
870
852
|
### Rate of return for a perpetuity
|
871
853
|
|
872
|
-
|
854
|
+
- Param - pmt - payment per period
|
873
855
|
|
874
|
-
|
856
|
+
- Param - pv - present value
|
875
857
|
|
876
858
|
Examples:
|
877
859
|
|
@@ -881,9 +863,9 @@ Finrb::Utils.r_perpetuity(pmt=4.5,pv=-75)
|
|
881
863
|
|
882
864
|
### Computing Sampling error
|
883
865
|
|
884
|
-
|
866
|
+
- Param - sm - sample mean
|
885
867
|
|
886
|
-
|
868
|
+
- Param - mu - population mean
|
887
869
|
|
888
870
|
Examples:
|
889
871
|
|
@@ -893,11 +875,11 @@ Finrb::Utils.sampling_error(sm=0.45, mu=0.5)
|
|
893
875
|
|
894
876
|
### Computing Roy's safety-first ratio
|
895
877
|
|
896
|
-
|
878
|
+
- Param - rp - portfolio return
|
897
879
|
|
898
|
-
|
880
|
+
- Param - rl - threshold level return
|
899
881
|
|
900
|
-
|
882
|
+
- Param - sd - standard deviation of portfolio retwns
|
901
883
|
|
902
884
|
Examples:
|
903
885
|
|
@@ -907,11 +889,11 @@ Finrb::Utils.sf_ratio(rp=0.09,rl=0.03,sd=0.12)
|
|
907
889
|
|
908
890
|
### Computing Sharpe Ratio
|
909
891
|
|
910
|
-
|
892
|
+
- Param - rp - portfolio return
|
911
893
|
|
912
|
-
|
894
|
+
- Param - rf - risk-free return
|
913
895
|
|
914
|
-
|
896
|
+
- Param - sd - standard deviation of portfolio retwns
|
915
897
|
|
916
898
|
Examples:
|
917
899
|
|
@@ -921,11 +903,11 @@ Finrb::Utils.sharpe_ratio(rp=0.038,rf=0.015,sd=0.07)
|
|
921
903
|
|
922
904
|
### Depreciation Expense Recognition - Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
|
923
905
|
|
924
|
-
|
906
|
+
- Param - cost - cost of long-lived assets
|
925
907
|
|
926
|
-
|
908
|
+
- Param - rv - residual value of the long-lived assets at the end of its useful life
|
927
909
|
|
928
|
-
|
910
|
+
- Param - t - length of the useful life
|
929
911
|
|
930
912
|
Examples:
|
931
913
|
|
@@ -933,11 +915,11 @@ Examples:
|
|
933
915
|
Finrb::Utils.slde(cost=1200,rv=200,t=5)
|
934
916
|
```
|
935
917
|
|
936
|
-
### Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations
|
918
|
+
### Total debt-to-equity - Solvency ratios measure the firm's ability to satisfy its long-term obligations.
|
937
919
|
|
938
|
-
|
920
|
+
- Param - td - total debt
|
939
921
|
|
940
|
-
|
922
|
+
- Param - te - total equity
|
941
923
|
|
942
924
|
Examples:
|
943
925
|
|
@@ -947,33 +929,33 @@ Finrb::Utils.total_d2e(td=6000,te=20000)
|
|
947
929
|
|
948
930
|
### Computing TWRR, the time-weighted rate of return
|
949
931
|
|
950
|
-
|
932
|
+
- Param - ev - ordered ending value list
|
951
933
|
|
952
|
-
|
934
|
+
- Param - bv - ordered beginning value list
|
953
935
|
|
954
|
-
|
936
|
+
- Param - cfr - ordered cash flow received list
|
955
937
|
|
956
938
|
Examples:
|
957
939
|
|
958
940
|
```ruby
|
959
|
-
Finrb::Utils.twrr(ev=
|
941
|
+
Finrb::Utils.twrr(ev=[120,260],bv=[100,240],cfr=[2,4])
|
960
942
|
```
|
961
943
|
|
962
944
|
### Calculate weighted average shares - weighted average number of common shares
|
963
945
|
|
964
|
-
|
946
|
+
- Param - ns - n x 1 vector vector of number of shares
|
965
947
|
|
966
|
-
|
948
|
+
- Param - nm - n x 1 vector vector of number of months relate to ns
|
967
949
|
|
968
950
|
Examples:
|
969
951
|
|
970
|
-
s=
|
952
|
+
s=[10000,2000];m=[12,6];
|
971
953
|
|
972
954
|
```ruby
|
973
955
|
Finrb::Utils.was(ns=s,nm=m)
|
974
956
|
```
|
975
957
|
|
976
|
-
s=
|
958
|
+
s=[11000,4400,-3000];m=[12,9,4];
|
977
959
|
|
978
960
|
```ruby
|
979
961
|
Finrb::Utils.was(ns=s,nm=m)
|
@@ -981,14 +963,14 @@ Finrb::Utils.was(ns=s,nm=m)
|
|
981
963
|
|
982
964
|
### Weighted mean as a portfolio return
|
983
965
|
|
984
|
-
|
966
|
+
- Param - r - returns of the individual assets in the portfolio
|
985
967
|
|
986
|
-
|
968
|
+
- Param - w - corresponding weights associated with each of the individual assets
|
987
969
|
|
988
970
|
Examples:
|
989
971
|
|
990
972
|
```ruby
|
991
|
-
Finrb::Utils.wpr(r=
|
973
|
+
Finrb::Utils.wpr(r=[0.12, 0.07, 0.03],w=[0.5,0.4,0.1])
|
992
974
|
```
|
993
975
|
|
994
976
|
## Amortization
|
@@ -1029,7 +1011,7 @@ amortization.interest[0,6].sum
|
|
1029
1011
|
=> Flt::DecNum('5294.62')
|
1030
1012
|
```
|
1031
1013
|
|
1032
|
-
If your loan has an adjustable rate, no problem.
|
1014
|
+
If your loan has an adjustable rate, no problem. You can pass an
|
1033
1015
|
arbitrary number of rates, and they will be used in the amortization.
|
1034
1016
|
For example, we can look at an amortization of $250000, where the APR
|
1035
1017
|
starts at 4.25%, and increases by 1% every five years.
|
@@ -1064,7 +1046,7 @@ arm.payments.sum
|
|
1064
1046
|
```
|
1065
1047
|
|
1066
1048
|
Last, but not least, you may pass a block when creating an Amortization
|
1067
|
-
which returns a modified monthly payment.
|
1049
|
+
which returns a modified monthly payment. For example, to increase your
|
1068
1050
|
payment by $150, do:
|
1069
1051
|
|
1070
1052
|
```ruby
|
@@ -1073,7 +1055,7 @@ extra_payments = 250000.amortize(rate){ |period| period.payment - 150 }
|
|
1073
1055
|
```
|
1074
1056
|
|
1075
1057
|
Disregarding the block, we have used the same parameters as the first
|
1076
|
-
example.
|
1058
|
+
example. Notice the difference in the results:
|
1077
1059
|
|
1078
1060
|
```ruby
|
1079
1061
|
amortization.payments.sum
|