mcsim: Monte Carlo simulate strategy results

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/mcsim.R

Description

This function resamples the daily transaction, cash equity, or percent-return P&L from a portfolio of trading results. It may be applied to both real (post-trade) and backtested transactions.

Usage

1
2
3
mcsim(Portfolio, Account, n = 1000, replacement = TRUE, ...,
  use = c("equity", "txns", "returns"), l = 1, varblock = FALSE,
  gap = 1)

Arguments

Portfolio

string identifier of portfolio name

Account

string identifier of account name

n

number of simulations, default = 1000

replacement

sample with or without replacement, default TRUE

use

determines whether to use 'equity', 'txn', or 'returns' P\&L, default = "equity" ie. daily

l

block length, default = 1

varblock

boolean to determine whether to use variable block length, default FALSE

gap

numeric number of periods from start of series to start on, to eliminate leading NA's

...

any other passthrough parameters

Details

The general argument here is that you can compare the performance of real portfolio equity or a backtest equity curve to a sampled version of the same.

We've chosen to use daily frequency for the resampling period. If your holding period is longer than one day, on average, the samples will increase variability in the overall path. If your average holding period is shorter than a day, the mcsim function will still provide a useful benchmark for comparing to other strategies, but you may additionally wish to sample round turn trades, as provided in (TODO: add link once function exists).

A few of the arguments and methods probably deserve more discussion as well.

use describes the method to use to generate the initial daily P\&L to be sampled from. The options are:

Sampling may be performed either with or without replacement.

If the post-trade or backtested equity curve exhibits autocorrelation, runs, streaks, etc. it may be advantageous to utilize a block resampling method. The length of the block "l" may be fixed or variable. If a varblock method is used, the distribution of block lengths will be uniform random for replacement=FALSE and geometric random for replacement=TRUE. By sampling blocks, the resampled returns will contain more of the structure of the original series. If varblock=TRUE, the blocks will be of variable length, centered around l.

Value

a list containing:

Note that this object and its slots may change in the future. Slots replicates,dailypl,initeq, and call are likely to exist in all future versions of this function, but other slots may be added and removed as S3method's are developed.

Note

Requires boot package

Author(s)

Jasen Mackie, Brian G. Peterson

See Also

boot plot.mcsim hist.mcsim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 

demo('longtrend', ask=FALSE)

nrsim <- mcsim("longtrend", "longtrend", n=1000, replacement=FALSE, l=1, gap=10)
nrblocksim <- mcsim("longtrend", "longtrend", n=1000, replacement=FALSE, l=10, gap=10)
rsim <- mcsim("longtrend", "longtrend", n=1000, replacement=TRUE, l=1, gap=10)
varsim <- mcsim("longtrend", "longtrend", n=1000, replacement=TRUE, l=10, varblock=TRUE, gap=10)
nrvarsim <- mcsim("longtrend", "longtrend", n=1000, replacement=FALSE, l=10, varblock=TRUE, gap=10)

quantile(varsim)
quantile(nrsim)
quantile(nrvarsim)

plot(nrsim, normalize=TRUE)
plot(nrsim, normalize=FALSE)
plot(varsim)
plot(rsim)
hist(rsim)
hist(varsim)


## End(Not run) #end dontrun

naturalsmen/blotter documentation built on May 23, 2019, 12:21 p.m.