Registered User Joined: 1/2/2006 Posts: 23
|
On Wednesday, May 25, 2005 12:38:07 PM - TomG18 wrote:
[(C-C1)/C*(C<C1)+(C1-C2)/C1*(C1<C2)]/ABS[(C<C1)+(C1<C2)] is the formula for a 2 day Ulcer Index.
yet when I pasted the above I received the error: "Error: The formula must not return a boolean value for a Formula Indicator"
An internet search found some information; can you make sense of any of this? I think I would be looking for more than 2 days of data...
The Ulcer Index (UI) is a measure of volatility over time. Lower UI values imply less daily volatility in an investment vehicle or strategy. To compute the Ulcer Index you:
1. Square all the daily drawdowns of the vehicle or strategy. 2. Sum all the daily squared retracements. 3. UI = the square-root of the sum.
Or;
Ulcer Index = Square root of sum of squared retracements divided by number of bars.
Or;
Sqrt(Sum(Power(100*( HHV(CLOSE,Period) - CLOSE )/(HHV(CLOSE, Period)),2),Period)/Period)
Or;
The algorithm for computing UI is simple, and can be seen in the pseudo-code fragment below:
SumSq = 0 MaxValue = 0 for T = 1 to NumOfPeriods do if Value[T] > MaxValue then MaxValue = Value[T] else SumSq = SumSq + sqr(100 * ((Value[T] / MaxValue) - 1)) UI = sqrt(SumSq / NumOfPeriods)
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I suspect the example formula was meant as just that, an example that would need to be converted to work in TeleChart. The square brackets should produce a syntax error. Even if the brackets were converted to parentheses, it would probably produce frequent division by zero errors.
Your pseudo-code could probably be reproduced using the Personal Criteria Formula Language for fairly short periods, but would probably get too large and slow very quickly as the Period increased (unless there's a shortcut I'm not seeing). There is no way to store MaxValue, so it would have to be recalculated for each bar in the Period (with the code size for the MAX () function increasing during each trip through the "loop").
Do you have a specific Period in mind?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/2/2006 Posts: 23
|
A chart diplayed on Investopedia shows this indicatior in TradeStation as:
Ulcer Index (Close,14,5)
Not being familiar with TradeStation, I believe they are suggesting a 14 period, with a smoothing of 5???
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Actually, it looks like it will be simpler than I thought since the built in MAX function can be used directly with with Price.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Here's what I've come up with so far:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC13.1 - 1)) ^ 2 + (100 * (C2 / MAXC12.2 - 1)) ^ 2 + (100 * (C3 / MAXC11.3 - 1)) ^ 2 + (100 * (C4 / MAXC10.4 - 1)) ^ 2 + (100 * (C5 / MAXC9.5 - 1)) ^ 2 + (100 * (C6 / MAXC8.6 - 1)) ^ 2 + (100 * (C7 / MAXC7.7 - 1)) ^ 2 + (100 * (C8 / MAXC6.8 - 1)) ^ 2 + (100 * (C9 / MAXC5.9 - 1)) ^ 2 + (100 * (C10 / MAXC4.10 - 1)) ^ 2 + (100 * (C11 / MAXC3.11 - 1)) ^ 2 + (100 * (C12 / MAXC2.12 - 1)) ^ 2) / 14)
It isn't smoothed. When used as a Custom Indicator, it is possible to just set the Smoothing Average to 5 and choose either Simple or Exponential depending on your preference.
It should be noted that this is based on the algorithm you presented. I would have interpreted the formula as using MAXC14 for each term. Please take a look and let me know if it doesn't do what you want.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/2/2006 Posts: 23
|
It SEEMS to look right on the chart, but I am not sure from your comments if you would have created it differently. This further comment below may be useful:
To measure downside risk, the Ulcer Index computes the percentage retracement from the security's highest Closing price. The drawdown is computed on a daily basis and is averaged over time. Unlike Standard Deviation, the calculated value of Ulcer Index is essentially the same regardless of the time interval per data point.
Also, this description as posted above...
Ulcer Index = Square root of sum of squared retracements divided by number of bars.
Nevertheless, it seems to look right; can you comment on whether you are happy with it based on the information in this post?
Thanks again
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Here are two other possible interpretations you might wish to try out:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14 - 1)) ^ 2 + (100 * (C2 / MAXC14 - 1)) ^ 2 + (100 * (C3 / MAXC14 - 1)) ^ 2 + (100 * (C4 / MAXC14 - 1)) ^ 2 + (100 * (C5 / MAXC14 - 1)) ^ 2 + (100 * (C6 / MAXC14 - 1)) ^ 2 + (100 * (C7 / MAXC14 - 1)) ^ 2 + (100 * (C8 / MAXC14 - 1)) ^ 2 + (100 * (C9 / MAXC14 - 1)) ^ 2 + (100 * (C10 / MAXC14 - 1)) ^ 2 + (100 * (C11 / MAXC14 - 1)) ^ 2 + (100 * (C12 / MAXC14 - 1)) ^ 2 + (100 * (C13 / MAXC14 - 1)) ^ 2 ) / 14)
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2 + (100 * (C5 / MAXC14.5 - 1)) ^ 2 + (100 * (C6 / MAXC14.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2 + (100 * (C8 / MAXC14.8 - 1)) ^ 2 + (100 * (C9 / MAXC14.9 - 1)) ^ 2 + (100 * (C10 / MAXC14.10 - 1)) ^ 2 + (100 * (C11 / MAXC14.11 - 1)) ^ 2 + (100 * (C12 / MAXC14.12 - 1)) ^ 2 + (100 * (C13 / MAXC14.13 - 1)) ^ 2 ) / 14)
I really don't know how it is calculated, but based on your English language descriptions, I would tend to think your algorithm and the first formula I provided would be closest to the mark.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/2/2006 Posts: 23
|
Your first formula definitely has the look of what I was seeking. Thanks again.
Here is a little more clarity in the words of the original creator:
"The Ulcer Index measures the depth and duration of percentage drawdowns in price from earlier highs.
Technically, it is the square root of the mean of the squared percentage drops in value." Peter Martin.
It was first described in The Investor's Guide to Fidelity Funds: Winning Strategies for Mutual Fund Investors, by Peter Martin & Byron McCann originally published by John Wiley & Sons in 1989.
|
|
Gold Customer
Joined: 8/6/2010 Posts: 3
|
I've visited this a few times now. Here's where I'm stumped -- I'm not clear on the construction of the formula... perhaps it's too many nested layers. Whatever the case, I'm running into errors when I try to change the time horizon of the calculation. What I'd like to be able to do is create ulcer indexes for various time periods -- like a 5-bar, 21-bar, 40-bar, etc... then plot them against each other (which should be a pretty simple overlay in TC2000. Any help with the construction here would be great. Somehow I've lost track of the parenthesis each time I try to alter the original formula.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A 5-Period version of the first formula with which I came up would be:
SQR(((100 * (C / MAXC5 - 1)) ^ 2 + (100 * (C1 / MAXC4.1 - 1)) ^ 2 + (100 * (C2 / MAXC3.2 - 1)) ^ 2 + (100 * (C3 / MAXC2.3 - 1)) ^ 2) / 5)
A 21-Period version would be:
SQR(((100 * (C / MAXC21 - 1)) ^ 2 + (100 * (C1 / MAXC20.1 - 1)) ^ 2 + (100 * (C2 / MAXC19.2 - 1)) ^ 2 + (100 * (C3 / MAXC18.3 - 1)) ^ 2 + (100 * (C4 / MAXC17.4 - 1)) ^ 2 + (100 * (C5 / MAXC16.5 - 1)) ^ 2 + (100 * (C6 / MAXC15.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2 + (100 * (C8 / MAXC13.8 - 1)) ^ 2 + (100 * (C9 / MAXC12.9 - 1)) ^ 2 + (100 * (C10 / MAXC11.10 - 1)) ^ 2 + (100 * (C11 / MAXC10.11 - 1)) ^ 2 + (100 * (C12 / MAXC9.12 - 1)) ^ 2 + (100 * (C13 / MAXC8.13 - 1)) ^ 2 + (100 * (C14 / MAXC7.14 - 1)) ^ 2 + (100 * (C15 / MAXC6.15 - 1)) ^ 2 + (100 * (C16 / MAXC5.16 - 1)) ^ 2 + (100 * (C17 / MAXC4.17 - 1)) ^ 2 + (100 * (C18 / MAXC3.18 - 1)) ^ 2 + (100 * (C19 / MAXC2.19 - 1)) ^ 2) / 21)
And a 40-Period version would be:
SQR(((100 * (C / MAXC40 - 1)) ^ 2 + (100 * (C1 / MAXC39.1 - 1)) ^ 2 + (100 * (C2 / MAXC38.2 - 1)) ^ 2 + (100 * (C3 / MAXC37.3 - 1)) ^ 2 + (100 * (C4 / MAXC36.4 - 1)) ^ 2 + (100 * (C5 / MAXC35.5 - 1)) ^ 2 + (100 * (C6 / MAXC34.6 - 1)) ^ 2 + (100 * (C7 / MAXC33.7 - 1)) ^ 2 + (100 * (C8 / MAXC32.8 - 1)) ^ 2 + (100 * (C9 / MAXC31.9 - 1)) ^ 2 + (100 * (C10 / MAXC30.10 - 1)) ^ 2 + (100 * (C11 / MAXC29.11 - 1)) ^ 2 + (100 * (C12 / MAXC28.12 - 1)) ^ 2 + (100 * (C13 / MAXC27.13 - 1)) ^ 2 + (100 * (C14 / MAXC26.14 - 1)) ^ 2 + (100 * (C15 / MAXC25.15 - 1)) ^ 2 + (100 * (C16 / MAXC24.16 - 1)) ^ 2 + (100 * (C17 / MAXC23.17 - 1)) ^ 2 + (100 * (C18 / MAXC22.18 - 1)) ^ 2 + (100 * (C19 / MAXC21.19 - 1)) ^ 2 + (100 * (C20 / MAXC20.20 - 1)) ^ 2 + (100 * (C21 / MAXC19.21 - 1)) ^ 2 + (100 * (C22 / MAXC18.22 - 1)) ^ 2 + (100 * (C23 / MAXC17.23 - 1)) ^ 2 + (100 * (C24 / MAXC16.24 - 1)) ^ 2 + (100 * (C25 / MAXC15.25 - 1)) ^ 2 + (100 * (C26 / MAXC14.26 - 1)) ^ 2 + (100 * (C27 / MAXC13.27 - 1)) ^ 2 + (100 * (C28 / MAXC12.28 - 1)) ^ 2 + (100 * (C29 / MAXC11.29 - 1)) ^ 2 + (100 * (C30 / MAXC10.30 - 1)) ^ 2 + (100 * (C31 / MAXC9.31 - 1)) ^ 2 + (100 * (C32 / MAXC8.32 - 1)) ^ 2 + (100 * (C33 / MAXC7.33 - 1)) ^ 2 + (100 * (C34 / MAXC6.34 - 1)) ^ 2 + (100 * (C35 / MAXC5.35 - 1)) ^ 2 + (100 * (C36 / MAXC4.36 - 1)) ^ 2 + (100 * (C37 / MAXC3.37 - 1)) ^ 2 + (100 * (C38 / MAXC2.38 - 1)) ^ 2) / 40)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
QUOTE (Bruce_L) Here are two other possible interpretations you might wish to try out:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14 - 1)) ^ 2 + (100 * (C2 / MAXC14 - 1)) ^ 2 + (100 * (C3 / MAXC14 - 1)) ^ 2 + (100 * (C4 / MAXC14 - 1)) ^ 2 + (100 * (C5 / MAXC14 - 1)) ^ 2 + (100 * (C6 / MAXC14 - 1)) ^ 2 + (100 * (C7 / MAXC14 - 1)) ^ 2 + (100 * (C8 / MAXC14 - 1)) ^ 2 + (100 * (C9 / MAXC14 - 1)) ^ 2 + (100 * (C10 / MAXC14 - 1)) ^ 2 + (100 * (C11 / MAXC14 - 1)) ^ 2 + (100 * (C12 / MAXC14 - 1)) ^ 2 + (100 * (C13 / MAXC14 - 1)) ^ 2 ) / 14)
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2 + (100 * (C5 / MAXC14.5 - 1)) ^ 2 + (100 * (C6 / MAXC14.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2 + (100 * (C8 / MAXC14.8 - 1)) ^ 2 + (100 * (C9 / MAXC14.9 - 1)) ^ 2 + (100 * (C10 / MAXC14.10 - 1)) ^ 2 + (100 * (C11 / MAXC14.11 - 1)) ^ 2 + (100 * (C12 / MAXC14.12 - 1)) ^ 2 + (100 * (C13 / MAXC14.13 - 1)) ^ 2 ) / 14)
I really don't know how it is calculated, but based on your English language descriptions, I would tend to think your algorithm and the first formula I provided would be closest to the mark.
Using the second version in your post, can you create, 5, 8, 13, 21 period versions?
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
5 period:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2) / 5)
8 period:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2 + (100 * (C5 / MAXC14.5 - 1)) ^ 2 + (100 * (C6 / MAXC14.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2) / 8)
13 period:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2 + (100 * (C5 / MAXC14.5 - 1)) ^ 2 + (100 * (C6 / MAXC14.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2 + (100 * (C8 / MAXC14.8 - 1)) ^ 2 + (100 * (C9 / MAXC14.9 - 1)) ^ 2 + (100 * (C10 / MAXC14.10 - 1)) ^ 2 + (100 * (C11 / MAXC14.11 - 1)) ^ 2 + (100 * (C12 / MAXC14.12 - 1)) ^ 2) / 13)
21 period:
SQR(((100 * (C / MAXC14 - 1)) ^ 2 + (100 * (C1 / MAXC14.1 - 1)) ^ 2 + (100 * (C2 / MAXC14.2 - 1)) ^ 2 + (100 * (C3 / MAXC14.3 - 1)) ^ 2 + (100 * (C4 / MAXC14.4 - 1)) ^ 2 + (100 * (C5 / MAXC14.5 - 1)) ^ 2 + (100 * (C6 / MAXC14.6 - 1)) ^ 2 + (100 * (C7 / MAXC14.7 - 1)) ^ 2 + (100 * (C8 / MAXC14.8 - 1)) ^ 2 + (100 * (C9 / MAXC14.9 - 1)) ^ 2 + (100 * (C10 / MAXC14.10 - 1)) ^ 2 + (100 * (C11 / MAXC14.11 - 1)) ^ 2 + (100 * (C12 / MAXC14.12 - 1)) ^ 2 + (100 * (C13 / MAXC14.13 - 1)) ^ 2 + (100 * (C14 / MAXC14.14 - 1)) ^ 2 + (100 * (C15 / MAXC14.15 - 1)) ^ 2 + (100 * (C16 / MAXC14.16 - 1)) ^ 2 + (100 * (C17 / MAXC14.17 - 1)) ^ 2 + (100 * (C18 / MAXC14.18 - 1)) ^ 2 + (100 * (C19 / MAXC14.19 - 1)) ^ 2 + (100 * (C20 / MAXC14.19 - 1)) ^ 2) / 21)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/29/2010 Posts: 417
|
Bruce,
Please create a 3 period version of the first:
"A 5-Period version of the first formula with which I came up would be:
SQR(((100 * (C / MAXC5 - 1)) ^ 2 + (100 * (C1 / MAXC4.1 - 1)) ^ 2 + (100 * (C2 / MAXC3.2 - 1)) ^ 2 + (100 * (C3 / MAXC2.3 - 1)) ^ 2) / 5)"
Thank you,
Don
|
|
Registered User Joined: 7/29/2010 Posts: 417
|
Bruce,
I am assuming the above formulas will also work on V12.5 and V16,V17.
Is that correct?
Thanks,
Don
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A 3-Period version of the first formula with which I came up would be:
SQR(((100 * (C / MAXC3 - 1)) ^ 2 + (100 * (C1 / MAXC2.1 - 1)) ^ 2) / 3)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/29/2010 Posts: 417
|
Wonderful!
Many thanks for your efforts Bruce.
Don
|
|
Registered User Joined: 7/29/2010 Posts: 417
|
This helped me better understand and interpret the Ulcer Index:
http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ulcer_index
|
|
Guest-1 |