[R-SIG-Finance] Drawdown functions from PerformanceAnalytics

Peter Carl peter at braverock.com
Thu Sep 2 16:18:56 CEST 2010


> The maximum drawdown for this series would than be 0.11(-0.10 + -0.01) or
> 11% right?

No, the drawdown is measured from the new equity level, 1.10, in your
example.  Were there to be no gains before those drawdowns occurred, then
the drawdown would be 11% in the non-geometric case, e.g., c(0, 0, -0.10,
-0.01, 0.01, 0.02).

Understand that the drawdown is calculated from the cumulative return
series.  In your example, the cumulative return series would be:
> PerformanceAnalytics:::Return.index(xts(c(0,.1,-0.10,-0.01,0.01,0.02),
Sys.Date()-6:1), geometric=FALSE)
               [,1]
2010-08-27 1.000000
2010-08-28 1.100000
2010-08-29 0.990000
2010-08-30 0.980100
2010-08-31 0.989901
2010-09-01 1.009699

and the Drawdown series is measured as:
> Drawdowns(xts(c(0,.1,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
geometric=FALSE)
                  [,1]
2010-08-27  0.00000000
2010-08-28  0.00000000
2010-08-29 -0.09090909
2010-08-30 -0.10000000
2010-08-31 -0.09090909
2010-09-01 -0.07272727

Think about the issue in terms of cumulation of returns, rather than
trades.  If you use geometric returns, you are indeed assuming
reinvestment.  If you use simple, you don't.  The truth is usually
somewhere in between; such are the hazards of using returns rather than
P&L.

As for your issue with findDrawdowns, I haven't been able to reproduce it:
> findDrawdowns(xts(c(0,.11,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
geometric=FALSE)
$return
[1]  0.0000000 -0.0990991

$from
[1] 1 3

$trough
[1] 1 4

$to
[1] 3 7

$length
[1] 3 5

$peaktotrough
[1] 1 2

$recovery
[1] 2 3

This isn't a very helpful function, and some day we'll take it out of the
namespace.  A more helpful function:
> table.Drawdowns(xts(c(0,.11,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1))    
    From     Trough   To  Depth Length To Trough Recovery
1 2010-08-29 2010-08-30 <NA> -0.109      5         2       NA
Warning message:
In table.Drawdowns(xts(c(0, 0.11, -0.1, -0.01, 0.01, 0.02), Sys.Date() -  :
  Only 1 available in the data.

Although I now see that we don't pass 'geometric' here, so I'll have to
fix that.

pcc
-- 
Peter Carl
http://www.braverock.com/~peter

> I think Samuel's suggestion just changes the order of magnitude of the
> (still) unexpected results.
> Let me explain that I don't have price data, just a series of percentage
> wins and losses from a fixed size trading system (no reinvestment).
>
> So if I have c(0, 0.10, -0.10, -0.01, 0.01, 0.02) that means the first
> trade
> was a break-even, the second trade was a 10% winner (on a fixed amount say
> $10000 = $1000), the third trade was a 10% loser (= -$1000) etc.
>
> The maximum drawdown for this series would than be 0.11(-0.10 + -0.01) or
> 11% right?
> maxDrawdown() just gives me 0.109 or 0.1. (depending on the geometric
> param
> setting) but not 0.11
>
> I think this means that maxDrawdown() expects full reinvestment in the
> returns?
>
> Besides, findDrawdowns() still crashes:
>
>> findDrawdowns(xts(c(0, 0.11, -0.10, -0.01, 0.03, 0.02), Sys.Date()-6:1),
> geometric=F)
> Error in if (drawdowns[i] < sofar) { : argument is of length zero
>
> Thanks,
>
> -Mark-
>
> 2010/9/2 Brian G. Peterson <brian at braverock.com>
>
>> Samuel is correct.
>>
>> Returns are multiplied times assets to get returns in a currency (or
>> price
>> change).  As such, whole number returns don't make any sense. This is
>> the
>> convention used by every statistical finance package I've ever seen,
>> including R.
>>
>> If you have cash 'returns' in a currency, you'll bneed to convert them
>> to
>> simple returns first.  see 'Return,calculate', among others.
>
>
>
> Just to finish out the example:
>>
>> #####
>> # Using Samuel's modified series:
>> maxDrawdown(xts(c(0,0.10,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
>> geometric=T)
>> # [1] 0.109
>>
>> maxDrawdown(xts(c(0,0.10,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
>> geometric=FALSE)
>> # [1] 0.1
>>
>> # and now chaning so that there are no repeated numbers
>> maxDrawdown(xts(c(0,0.05,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
>> geometric=FALSE)
>> # [1] 0.1047619
>>
>> maxDrawdown(xts(c(0,0.05,-0.10,-0.01,0.01,0.02), Sys.Date()-6:1),
>> geometric=TRUE)
>> # [1] 0.109
>>
>> # and charting for a visual representation,
>> # drawdowns are the third panel
>>
>> charts.PerformanceSummary(xts(c(0,0.05,-0.10,-0.01,0.01,0.02),
>> Sys.Date()-6:1))
>>
>> #####
>>
>> Regards,
>>
>>  - Brian
>>
>>
>>
>> On 09/02/2010 04:55 AM, Samuel Le wrote:
>>
>>> I think your asset returns are not supposed to be in percentage, so you
>>> should use c(0,0.10,-0.10,-0.01,0.01,0.02) instead.
>>>
>>> Samuel
>>>
>>> -----Original Message-----
>>> From: r-sig-finance-bounces at stat.math.ethz.ch [mailto:
>>> r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Mark Breman
>>> Sent: 02 September 2010 10:21
>>> To: r-sig-finance at stat.math.ethz.ch
>>> Subject: [R-SIG-Finance] Drawdown functions from PerformanceAnalytics
>>>
>>> Hello everyone,
>>>
>>> I'm looking at the Drawdown functions from the PerformanceAnalytics
>>> package
>>> and I just don't get it.
>>> The docs say that the input should be Asset Returns and the output will
>>> be
>>> drawdown levels as percentages but if I call them with a simple return
>>> series I don't get what I expect.
>>>
>>> For instance: if I have a simple returns series like c(0, 10, -10, -1,
>>> 1,
>>> 2)
>>> I would expect the maximum drawdown to be -11 (or 110%), but instead I
>>> get:
>>>
>>>  library(PerformanceAnalytics)
>>>> maxDrawdown(xts(c(0, 10, -10, -1, 1, 2), Sys.Date()-6:1), geometric=T)
>>>>
>>> [1] 10
>>>
>>> Changing the geometric parameter to False also gives me not what I
>>> would
>>> expect:
>>>
>>>  maxDrawdown(xts(c(0, 10, -10, -1, 1, 2), Sys.Date()-6:1), geometric=F)
>>>>
>>> [1] 1
>>>
>>> findDrawdowns() gives me an error:
>>>
>>>  findDrawdowns(xts(c(0, 10, -10, -1, 1, 2), Sys.Date()-6:1),
>>> geometric=T)
>>>>
>>> Error in if (drawdowns[i]<  sofar) { : argument is of length zero
>>>
>>> Here is my sessionInfo()
>>>
>>>  sessionInfo()
>>>>
>>> R version 2.11.1 (2010-05-31)
>>> i486-pc-linux-gnu
>>>
>>> locale:
>>>  [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
>>>  LC_TIME=en_US.utf8
>>>        LC_COLLATE=en_US.utf8     LC_MONETARY=C
>>>  [6] LC_MESSAGES=en_US.utf8    LC_PAPER=en_US.utf8       LC_NAME=C
>>>       LC_ADDRESS=C              LC_TELEPHONE=C
>>> [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> other attached packages:
>>>  [1] fTrading_2100.76           fBasics_2110.79            MASS_7.3-5
>>>           timeSeries_2120.89         timeDate_2120.90
>>>  [6] XML_3.1-1                  quantmod_0.3-14            TTR_0.20-2
>>>           Defaults_1.1-1             PerformanceAnalytics_1.0.3
>>> [11] xts_0.7-5                  zoo_1.6-4
>>>
>>> loaded via a namespace (and not attached):
>>> [1] grid_2.11.1    lattice_0.18-8 tools_2.11.1
>>>
>>> Can someone explain the unexpected results or is it just broken?
>>>
>>> Thanks,
>>>
>>> -Mark-
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>> -- Also note that this is not the r-help list where general R questions
>>> should go.
>>>
>>>
>>> __________ Information from ESET NOD32 Antivirus, version of virus
>>> signature database 5416 (20100901) __________
>>>
>>> The message was checked by ESET NOD32 Antivirus.
>>>
>>> http://www.eset.com
>>>
>>>
>>>
>>> __________ Information from ESET NOD32 Antivirus, version of virus
>>> signature database 5416 (20100901) __________
>>>
>>> The message was checked by ESET NOD32 Antivirus.
>>>
>>> http://www.eset.com
>>>
>>> _______________________________________________
>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>> -- Also note that this is not the r-help list where general R questions
>>> should go.
>>>
>>
>>
>> --
>> Brian G. Peterson
>> http://braverock.com/brian/
>> Ph: 773-459-4973
>> IM: bgpbraverock
>>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



More information about the R-SIG-Finance mailing list