# [R-SIG-Finance] Drawdown functions from PerformanceAnalytics

Brian G. Peterson brian at braverock.com
Thu Sep 2 16:07:00 CEST 2010

```No investments book or paper that I can think of represents returns as
whole numbers.  "Correct" or not, that's the way it is.  You get crazy
results from the math otherwise.

In your example, use geometric=FALSE (which is correct for daily returns
in most cases, again, crazy results if you assume geometric)

That said, a return series is based on a percentage of your then-current
capital.  If you want to assume no reinvestment, then you have a
different series.

This is consistent with the literature, and the functions are, I
believe, correct per the Bacon reference in the documentation.

The arithmetic works in both geometric and non-geometric cases, and
produces the expected result.

For example:

Drawdowns(xts(c(0,0.10,-0.10,-0.01,0.01,0.02,.1,.01,.01),
Sys.Date()-9:1),geometric=FALSE)

#####
[,1]
2010-08-24  0.00000000
2010-08-25  0.00000000
2010-08-26 -0.09090909
2010-08-27 -0.10000000
2010-08-28 -0.09090909
2010-08-29 -0.07272727
2010-08-30  0.00000000
2010-08-31  0.00000000
2010-09-01  0.00000000

I wouldn't mind seeing a function for calculating 'no-reinvestment'
returns where the amount available to invest does not change (where your
period returns basically generate dividends in a different
account/portfolio) from a set of simple cash proceeds, but no such
function currently exists.

Regards,

- Brian

On 09/02/2010 08:33 AM, Mark Breman wrote:
> 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
>>> [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.

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

```