Skip to content

Instantly share code, notes, and snippets.

View jaymon0703's full-sized avatar

Jasen Mackie jaymon0703

View GitHub Profile
@jaymon0703
jaymon0703 / txnsim.R
Last active April 8, 2017 12:41
start of txnsim() function for simulating blotter trades whilst retaining strategy characteristics
#' Monte Carlo analysis of transactions
#'
#' Running simulations with similar properties as the backtest or production
#' portfolio may allow the analyst to evaluate the distribution of returns
#' possible with similat trading approaches and evaluate skill versus luck or
#' overfitting.
#'
#' @details
#'
#' If \code{update=TRUE} (the default), the user may wish to pass \code{Interval}
@jaymon0703
jaymon0703 / mcsim_gist.R
Last active July 5, 2016 20:14
mcsim gist for rapid prototypive collaborative narrative R
#' Monte Carlo simulate strategy results
#'
#' Return bands of returns based on Monte Carlo simulations of back-test results
#' @param Portfolio string identifier of portfolio name
#' @param Account string identifier of account name
#' @param n number of simulations, default = 1000
#' @param \dots any other passthrough parameters
#' @param l block length, default = 20
#' @param use determines whether to use 'daily' or 'txn' PL, default = "equity" ie. daily
#' @param gap numeric number of periods from start of series to start on, to eliminate leading NA's
@jaymon0703
jaymon0703 / mcsimr.R
Last active May 21, 2016 13:39
A Monte Carlo Simulation function for your back-test results - in R
# Record script start time ----------------------------------------
t1 <- Sys.time()
# Load required packages ------------------------------------------
library(quantmod)
library(TTR)
library(PerformanceAnalytics)
library(ggplot2)
library(timeSeries)
@jaymon0703
jaymon0703 / mcblocksim.R
Last active April 26, 2016 22:31
Monte Carlo Simulation with Block Bootstrapping
# Record script start time ----------------------------------------
t1 <- Sys.time()
# Load required packages ------------------------------------------
library(quantmod)
# Build the function ----------------------------------------------
mcblocksim <- function(R, l){
# Read price data and build xts object