Chart: Cumulative 500 random returns
Let's take a series of randomly generated 500 returns in the range of 0.92 to 1.10 (or -8% to +10%).
Now, let's try to calculate some basic potential loss statistics for this series based on the observed draw-downs:
Number of the draw-down losing sequences:
> downsN [1] 228
First draw-downs losing sequences:
d(dd_stats)
start stop length loss
[1,] 1 1 1 -0.005949528
[2,] 2 3 2 -0.122208798
[3,] 4 4 1 -0.024784714
[4,] 5 6 2 -0.098330307
[5,] 7 8 2 -0.060649554
[6,] 9 11 3 -0.137897672
The worst
> min(sapply(drawdowns, function(x) x$result-1)) [1] -0.2625977
The longest draw-down losing sequence:
> max(sapply(drawdowns, function(x) x$length)) [1] 6
Average loss of draw-down losing sequences:
> mean(sapply(drawdowns, function(x) x$result-1)) [1] -0.07221781
The bottom, peak and the last value of the process:
> min(cumreturns)-1; max(cumreturns)-1; cumreturns[length(cumreturns)]-1 [1] -0.0683741 [1] 46.30488 [1] 38.46427
UPDATE 2012-02-10
Chart: Cumulative random sequence of 500 returns [-8%, +10%] and draw-down line
Above I did calculate the statistics for losing sequences not draw down.
The correct results (for a different random process) should be:
> downsN # number of losing sequences [1] 214 > > head(dd_stats) start stop length loss [1,] 1 1 1 -0.039665746 [2,] 2 3 2 -0.097175026 [3,] 4 4 1 -0.001900723 [4,] 5 6 2 -0.076761609 [5,] 7 8 2 -0.083846687 [6,] 9 10 2 -0.062338201 > > min(sapply(drawdowns, function(x) x$result-1)) # worst sequence [1] -0.2556858 > > mean(sapply(drawdowns, function(x) x$result-1)) # average sequence [1] -0.06519456 > > max(sapply(drawdowns, function(x) x$length)) # longest sequence [1] 6 > > mean(sapply(drawdowns, function(x) x$length)) # average length of sequence [1] 1.658915 > > # bottom, top, last result > min(cumreturns)-1; max(cumreturns)-1; cumreturns[length(cumreturns)]-1 [1] -0.06119829 [1] 161.2614 [1] 85.06354 > > > min(dd) # worst draw down [1] -0.5623983
R Source
No comments:
Post a Comment