title: Theil's U 1 / Theil's U 2 Forecast Coefficient formula in Python
body: <p>I have a problem implementing the Theil U forecast coefficient formula in my Python code. One of the problems is that I found several different versions of the formula.
  The 3 formulas I want to try are the following:</p>
  
  <p>Theil's U 1 and 2 from a paper that ironically discusses the confusion of the Theil's U forecast coefficient: <a href="https://journals.sagepub.com/na101/home/literatum/publisher/sage/journals/content/mrja/1973/mrja_10_4/002224377301000413/20181220/002224377301000413.fp.png_v03" rel="nofollow noreferrer">https://journals.sagepub.com/na101/home/literatum/publisher/sage/journals/content/mrja/1973/mrja_10_4/002224377301000413/20181220/002224377301000413.fp.png_v03</a></p>
  
  <p>A different version of the Theil's U forecast coefficient from what appears to be an Oracle help page: <a href="https://docs.oracle.com/cd/E40248_01/epm.1112/cb_statistical/frameset.htm?ch07s02s03s04.html" rel="nofollow noreferrer">https://docs.oracle.com/cd/E40248_01/epm.1112/cb_statistical/frameset.htm?ch07s02s03s04.html</a></p>
  
  <p>The three formulas should achieve a value of 1 if the forecast is just a naive lagged forecast. So, let's consider the following simple list: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and assume that the forecast for every value is the previous value.</p>
  
  <p>This is my code for the 3 formulas:</p>
  
  <pre><code>list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  
  num = (sum([(list[row] - list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5
  denum = ((sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5) + \
      ((sum([list[row - 1] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5)
  
  UI = num / denum
  print(UI)
  
  num = sum([(list[row - 1] - list[row]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
  denum = (sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]])) ** 0.5
  
  UII = num / denum
  print(UII)
  
  num = sum([((list[row - 1] - list[row]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
  denum = sum([((list[row] - list[row - 1]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
  
  U_Oracle = num / denum
  print(U_Oracle)
  </code></pre>
  
  <p>These are the 3 results:</p>
  
  <p>0.08224166442822099</p>
  
  <p>0.15309310892394865</p>
  
  <p>1.0</p>
  
  <p>I can't figure out why not all 3 values are equal to 1. Is something wrong with my code?</p>