Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## Fuction that computes the devaluation factor depending on the
# time interval, based on the target yearly ratio.
decrease <- function(days, yrRatio = 0.5) {
exp(days/365.25 * log(yrRatio))
}
# Test & plot
x <- 0:800;
plot(x, decrease(x), type = "l", yaxp = c(0.25, 1, 3), #xaxp = c(0, 365.25*2, 6),
ylab = "Devaluation", xlab = "time (in days)")
abline(v = (1:2) * 365.25, h = c(0.5, 0.25))
# In our case...
buy <- as.Date('2015-12-01')
sell <- as.Date('2016-05-15')
total <- 373
print(res <- decrease(as.numeric(sell - buy)) * total)
# 272.2048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.