Note that there are some explanatory texts on larger screens.

plurals
  1. POcalculating "Max Draw Down" in SQL
    primarykey
    data
    text
    <p>edit: it's worth reviewing the comments section of the first answer to get a clearer idea of the problem.</p> <p>edit: I'm using SQLServer 2005</p> <p>something similar to this was posted before but I don't think enough information was given by the poster to truly explain what max draw down is. All my definitions of max draw down come from (the first two pages of) this paper: <a href="http://www.stat.columbia.edu/~vecer/maxdrawdown3.pdf">http://www.stat.columbia.edu/~vecer/maxdrawdown3.pdf</a></p> <p>effectively, you have a few terms defined mathematically:</p> <p>Running Maximum, M<sub>t</sub></p> <blockquote> <p>M<sub>t</sub> = max<sub>u in [0,t]</sub> (S<sub>u</sub>)<br> where S<sub>t</sub> is the price of a Stock, S, at time, t.</p> </blockquote> <p><p>Drawdown, D<sub>t</sub><p></p> <blockquote> <p>D<sub>t</sub> = M<sub>t</sub> - S<sub>t</sub></p> </blockquote> <p><p>Max Draw Down, MDD<sub>t</sub></p> <blockquote> <p>MDD<sub>t</sub> = max<sub>u in [0,t]</sub> (D<sub>u</sub>)</p> </blockquote> <p>so, effectively what needs to be determined is the local maximums and minimums from a set of hi and low prices for a given stock over a period of time. I have a historical quote table with the following (relevant) columns: </p> <blockquote> <pre><code>stockid int day date hi int --this is in pennies low int --also in pennies </code></pre> <p>so for a given date range, you'll see the same stockid every day for that date range.</p> </blockquote> <p><strong>EDIT:</strong><br> hi and low are high for the day and low for each day.</p> <p>once the local max's and min's are determined, you can pair every max with every min that comes after it and calculate the difference. From that set, the maximum difference would be the "Max Draw Down".</p> <p>The hard part though, is finding those max's and min's.</p> <p>edit: it should be noted: max drawdown is defined as the value of the hypothetical loss if the stock is bought at it's highest buy point and sold at it's lows sell point. A stock can't be sold at a minval that came before a maxval. so, if the global minval comes before the global maxval, those two values do not provide enough information to determine the max-drawdown.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload