The drawdown measures the decline of a time-series from an historical peak; generally the drawdown is used to analyze portfolio equities.
The maximum drawdown will then let you know how much money a portfolio has lost (or the maximum portfolio value decline) during the investing/backtesting period and therefore the drawdown is a measure of the risk of a financial investment.
This drawdown measure is very important and is the basis of many other financial risk measures.
The drawdown can also be used for normal time-series or security quotes.
This function is an extension of the already available drawdown function. The function that exists in QuantShare let you calculate the drawdown of a time-series. But what the QuantShare drawdown formula doesn't calculate is the drawdown of a security if we are short the asset.
This function has two calculation modes: a long mode and a short mode.
In a short mode, the formula calculates the drawdown of the time-series as if we were short this time-series security; the more the time-series raise the more the drawdown increase (since the calculated values are negative the drawdown values will, in fact, decrease); and the opposite for the long mode.
Note that the drawdown calculation starts from the first quote.
The function name is 'drawdown_adv', it accept only one parameter; this parameters will let you decide whether to calculate in long or short mode.
Set the parameter value to 1 for a long mode, otherwise the short mode will be used.
The formula isn't complicated; it is about 30 lines of code. It starts by getting the close price of the asset, then loop through the time-series data elements while keeping track of the highest close values (long mode) or lowest close values (short mode).