Skip to content

Instantly share code, notes, and snippets.

@StuartGordonReid
Created February 6, 2016 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save StuartGordonReid/983f6a8698dcd6d0e130 to your computer and use it in GitHub Desktop.
Save StuartGordonReid/983f6a8698dcd6d0e130 to your computer and use it in GitHub Desktop.
#' @title Estimator for the value of mu. Mu is the drift component in the
#' Geometric Brownian Motion model.
#'
#' @description Given a log price process, this function estimates the value of
#' mu. Mu is the daily component of the returns which is attributable to upward,
#' or downward, drift. This estimate can be annualized.
#'
#' @param X vector :: A log price process.
#' @param annualize logical :: Annualize the parameter estimate.
#' @return mu.est double :: The estimated value of mu.
#'
calibrateMu <- function(X, annualize = TRUE) {
# Ensure the format of X is appropriate.
X <- as.numeric(as.vector(X))
# Estimate the value of mu.
n <- length(X)
mu.est <- (X[n] - X[1])/n
if (!annualize) return(mu.est)
else return(mu.est * 252)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment