spedygiorgio / lifecontingencies

Financial and Actuarial Mathematics for Life Contingencies
Other
61 stars 29 forks source link

Macaulay Duration, Modified duration and Effective duration #21

Closed nth1502 closed 6 years ago

nth1502 commented 6 years ago

ISSUE:

With reference to this source : https://www.investopedia.com/exam-guide/cfa-level-1/fixed-income-investments/effective-modified-macaulay-duration.asp

Current duratiion function in v1.3.2

function (cashFlows, timeIds, i, k = 1, macaulay = TRUE) { out = 0 if (missing(timeIds)) { warning("Warning: missing time vector") timeIds = 1 } if (!(length(cashFlows) == length(timeIds))) stop("Error! check dimensionality of cash flow and time ids vectors") interestRates = rep(i/k, length.out = length(timeIds)) ts = timeIds k v = (1 + interestRates)^-(ts) pv = sum((cashFlows v)) weightedTime = sum((cashFlows v ts)) out = weightedTime/pv if (macaulay == FALSE) out = out else out = out/(1 + i/k) return(out) }

Instead it should be if (macaulay == TRUE) out = out else out = out/(1 + i/k) return(out)

"Else" part in fact refers to Modified Duration, Not Effective Duration like documentation states (Although in some cases, Modified and Effective duration are the same)

SUGGESTION:

1/Fixed the modified and effective duration in function and their documentation accordingly 2/Add another option of effective duration calculation.

spedygiorgio commented 6 years ago

Hi thanks for raising the issue. I have accepted your suggestion in the dev and I'll commit asap

dutangc commented 6 years ago

I have committed some modifications this afternoon. Feel free to commit.

Christophe


Christophe Dutang CEREMADE, Univ. Paris Dauphine, France Web : http://dutangc.free.fr

Le 30 mars 2018 à 10:25, Giorgio Alfredo Spedicato notifications@github.com a écrit :

Hi thanks for raising the issue. I have accepted your suggestion in the dev and I'll commit asap

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spedygiorgio/lifecontingencies/issues/21#issuecomment-377476513, or mute the thread https://github.com/notifications/unsubscribe-auth/AGF2tncEMy2tmbg5Gp91YlXPtzhzcirMks5tjev9gaJpZM4TBQk6.

nth1502 commented 6 years ago

Superb and prompt responses. Thank you for your attention!

spedygiorgio commented 6 years ago

added one duration test