Hi,
I would like to calculate the maximum drawdown from asset returns (and not prices). The definition from Investopedia is the following:
"A drawdown is a peak-to-trough decline during a specific period for an investment. A drawdown is usually quoted as the percentage between the peak and the subsequent trough. If a trading account has $10,000 in it, and the funds drop to $9,000 before moving back above $10,000, then the trading account witnessed a 10% drawdown."
I have found the following Stata module but it does the job with a time series of prices (and not returns):
ssc install maxdrawdown
https://econpapers.repec.org/softwar...de/s458234.htm
Here is the data I have. CAR_S returns are expressed in % here:
I would like to calculate the global maximum drawdown and then, if possible, being able to calculate a few local maximum drawdown by selecting particular periods. Please help! Thanks.
I would like to calculate the maximum drawdown from asset returns (and not prices). The definition from Investopedia is the following:
"A drawdown is a peak-to-trough decline during a specific period for an investment. A drawdown is usually quoted as the percentage between the peak and the subsequent trough. If a trading account has $10,000 in it, and the funds drop to $9,000 before moving back above $10,000, then the trading account witnessed a 10% drawdown."
I have found the following Stata module but it does the job with a time series of prices (and not returns):
ssc install maxdrawdown
https://econpapers.repec.org/softwar...de/s458234.htm
Code:
capt program drop _all mata: mata clear version 13.1 mata: mata set matastrict on void down(string scalar varlist, /// string scalar touse) { real colvector x,maxdrawdown st_view(x,.,varlist,touse) N=length(x) drawdown=J(N,1,0) for (i=2;i<=N;i++){ c=max(x[(1::i)]) if (c==x[i]){ drawdown[i]=0 } else{ drawdown[i]=(x[i]-c)/c } } maxdrawdown=min(drawdown); st_numscalar("r(drawdown)",maxdrawdown[1]) } end program maxdrawdown,rclass *! varextrema1.0.0 version 13.1 syntax varlist(numeric)[if] [in] marksample touse mata:down("`varlist'","`touse'") display as txt "maxdrawdown(`varlist')=" as res r(drawdown) return scalar maxdrawdown=r(drawdown) end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(ym CAR_S) 193 -4.955649465375698 194 -6.339490131920598 195 -2.2085909105983883 196 5.0697072999447546 197 1.5230009468702013 198 .4465776036932692 199 1.6849011886329255 200 -.3153071843080411 201 1.0034142523957397 202 3.173579966108508 203 .3626220170161193 204 3.7606463036604745 205 1.6097575927271197 206 1.5511188873208348 207 -.5901847848517586 208 1.022720013505459 209 .8956018347505074 210 -9.06956574407067 211 -4.356956415343178 212 .8692812643197029 213 2.155593145782702 214 -1.105166282830968 215 -1.9155843469957576 216 2.394801626547746 217 .2413081226243894 218 4.677405785053766 219 2.5613313637882698 220 .9572651020898989 221 .5885842700802983 222 -2.341790344477331 223 1.0768635318696078 224 .5129555054158106 225 1.8504713044698482 226 5.721799946508766 227 -.40342807934669833 228 3.986336890125122 229 .8113956057296925 230 4.813445457096 231 2.45576711718332 232 .21289686762756188 233 1.7124875966774804 234 1.1436768405005182 235 2.6345094579980612 236 -.007732036831873401 237 3.590608189676082 238 1.215903951037156 239 -.5466841823464981 240 1.5514306796014525 241 2.894552477629012 242 -.9724231404096386 243 -3.388116209394454 244 2.2770837124208687 245 -.047009329370436115 246 1.1231010098306924 247 1.0156940088288544 248 .9350310254615996 249 1.4001954350949577 250 -.19086276571913174 251 -1.730841501540115 252 3.326560411905674 253 -.6055385093723241 254 -.2330857297221054 255 2.0090884593451195 256 .8087691581694171 257 -.860190504754828 258 2.783416631801735 259 .4189224092838906 260 2.5616379593537895 261 -1.7545000467375578 262 -2.418127025423753 263 1.3396784957990593 264 1.1709206337278675 265 -1.320829458386171 266 .462360687258057 267 1.9000914417279373 268 2.9679684801061432 269 -.9998566749570248 270 1.012491305122047 271 -.13482369096798166 272 1.4429577138271052 273 .4836774477703438 274 -1.9621027902266837 275 -1.7251334281134019 276 .8021924416397117 277 1.5691281499534069 278 -1.7022888575502682 279 1.046120612915143 280 .9219742775645444 281 -.7226977368491909 282 1.1101008297093193 283 1.0807732720386911 284 -.543479577743237 285 .9559707941618126 286 1.293485372141531 287 .25298857629446225 288 1.9385891487724078 289 .14288137609656726 290 .7208830272759534 291 2.251307370696712 292 .7799676743364827 end format %tm ym
Comment