Skip to content

Instantly share code, notes, and snippets.

@antoine-lizee
Last active April 29, 2016 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoine-lizee/2cc53bd8a062bcafeea2cf8f27fb024b to your computer and use it in GitHub Desktop.
Save antoine-lizee/2cc53bd8a062bcafeea2cf8f27fb024b to your computer and use it in GitHub Desktop.
## 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