This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' | |
#' Default value for `NULL` | |
#' | |
#' This infix function makes it easy to replace `NULL`s with a default | |
#' value. It's inspired by the way that Ruby's or operation (`||`) | |
#' works. | |
#' | |
#' @param x,y If `x` is NULL, will return `y`; otherwise returns `x`. | |
#' @export | |
#' @name op-null-default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' | |
#' Type-check a function parameter | |
#' | |
#' Stops if variable type is wrong. | |
#' | |
#' \code{decl} is a simple, fast type checker, | |
#' and should be used when speed matters, | |
#' such as in low-level functions. | |
#' \code{declare} is more powerful and implements | |
#' a convenient syntax for richer types. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @export | |
fatal = function(..., sep = " ", caller = NULL) { | |
caller <- caller %||% as.list(sys.call(-1))[[1]] | |
msg <- paste0("[", caller, "] ", paste(..., sep = sep)) | |
stop(msg, call. = FALSE) | |
} | |
#' @export | |
fatalIf = function(cond, ..., caller = NULL) { | |
if (cond) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Barrier Breach Simulation" | |
author: "Paul Teetor" | |
date: "June 2022" | |
output: html_document | |
params: | |
annualVol: 0.20 | |
annualDrift: 0.0 | |
term: 30 # In days | |
startPrice: 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Demonstration of bootstrapping AR(1) residuals, | |
# using the AirPassergers data. | |
# | |
# This code performs a simple bootstrap, not a | |
# block bootstrap, because it assumes the model's residuals | |
# are independent. If your residuals exhibit autocorrelation, | |
# then a block bootstrap would be more appropriate. | |
# (However, if your residuals *do* show autocorrelation, | |
# then your time series model needs improvement.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# One-factor model of spread using DLM package | |
# | |
# Model in discrete form: | |
# | |
# y[t] = a + b*s[t] + u[t] | |
# s[t] = c*s[t-1] + v[t] | |
# | |
# Model in matrix form: | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a toy example of splitting an R application | |
# into three distinct parts: | |
# | |
# - Loading the data | |
# - Calculating the analytics | |
# - Rendering an RMarkdown document | |
# | |
# Note: The RMarkdown doc appears in a companion file, toyDoc.Rmd. | |
# |