Description Usage Arguments Details Value Note Author(s) See Also Examples
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.
1 2 3 |
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 |
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:
equitywill use daily portfolio cash P&L
txnwill use transaction Net.Trading.PL
returnswill use PortfReturns to generate percent returns
Sampling may be performed either with or without replacement.
without replacementIf sampled **without** replacement, the replicated equity curves will use all the same data as the input series, only reordered. This will lead to all the replicates having identical final P\&L and mean returns, but different paths along the way.
with replacementIf sampled **with** replacement, individual observations may be re-used. This will tend to create more variability than replicates 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
.
a list containing:
replicates
:an xts object containing all the resampled time series replicates
dailypl
:an xts object containing daily P&L from the original backtest
initeq
:a numeric variable containing the initEq of the portfolio, for starting portfolio value
num
:a numeric variable reporting the number of replicaes in the simulation
length
:a numeric variable reporting the block length used in the simulation, if any
ddvec
:a numeric vector of drawdowns for each replicate series
w
:a string containing information on whether the simulation is with or without replacement
use
: a string with the value of the 'use' parameter, for checking later
call
:an object of type call
that contains the mcsim
call
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.
Requires boot package
Jasen Mackie, Brian G. Peterson
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.