Skip to content
Code to help analyze financial data http://greg-turnquist.blogspot.com/search/label/finance
Scala
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
LICENSE.txt
README
core.scala
finance.scala

README

This project contains code used to analyze financial data.

To build and run the finance.scala app:

1) Install scala (brew install scala works)
2) scalac *.scala && scala Main  (this ensures that compile errors break out and don't try to run anything)

This will show you a demo of S&P 500 performance, comparing arithmetic mean and geometric mean, and then compare it to an EIUL.

The output of the latest version is shown below:

S&P 500 performance = List((1951,16.3), (1952,11.8), (1953,-6.6), (1954,26.4), (1955,26.4), (1956,2.6), (1957,-14.3), (1958,38.1), (1959,8.5), (1960,-3.0), (1961,23.1), (1962,-11.8), (1963,18.9), (1964,13.0), (1965,9.1), (1966,-13.1), (1967,20.1), (1968,7.7), (1969,-11.4), (1970,0.1), (1971,10.8), (1972,15.6), (1973,-17.4), (1974,-29.7), (1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7), (1982,14.8), (1983,17.3), (1984,1.4), (1985,26.3), (1986,14.6), (1987,2.0), (1988,12.4), (1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7), (1999,19.5), (2000,-10.1), (2001,-13.0), (2002,-23.4), (2003,26.4), (2004,9.0), (2005,3.0), (2006,13.6), (2007,3.5), (2008,-38.5), (2009,23.5), (2010,12.8))
Arithmetic mean = 8.235000000000001%
Geometric mean = 6.866554380824419%
Actual total growth factor = 53.766085563840456

EIUL performance = List((1951,15.0), (1952,11.8), (1953,0.0), (1954,15.0), (1955,15.0), (1956,2.6), (1957,0.0), (1958,15.0), (1959,8.5), (1960,0.0), (1961,15.0), (1962,0.0), (1963,15.0), (1964,13.0), (1965,9.1), (1966,0.0), (1967,15.0), (1968,7.7), (1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1), (1979,12.3), (1980,15.0), (1981,0.0), (1982,14.8), (1983,15.0), (1984,1.4), (1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0), (1990,0.0), (1991,15.0), (1992,4.5), (1993,7.1), (1994,0.0), (1995,15.0), (1996,15.0), (1997,15.0), (1998,15.0), (1999,15.0), (2000,0.0), (2001,0.0), (2002,0.0), (2003,15.0), (2004,9.0), (2005,3.0), (2006,13.6), (2007,3.5), (2008,0.0), (2009,15.0), (2010,12.8))
EIUL arithmetic performance = 8.428333333333335%
EIUL geometric performance = 8.226111328758012%
Actual EIUL total growth factor = 114.79507227304792


  This is where every 10, 15, 20, etc. year interval in all the data is evaluated and then averaged together.
  The min and max performance of each interval is displayed, and the 1st stddev is shown. There is a 68%
  that actual performance is within 1 stddev of the average.
  
10-year stats
==========================
S&P 500 stats:	 Avg geom mean = 7.08 (-3.04..16.06)	68% chance between 2.22 and 11.94
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1999,2008,-1.0,-3.03655852778808,List((1999,19.5), (2000,-10.1), (2001,-13.0), (2002,-23.4), (2003,26.4), (2004,9.0), (2005,3.0), (2006,13.6), (2007,3.5), (2008,-38.5)))
Max window is (1989,1998,16.919999999999998,16.05565146835952,List((1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7)))

EIUL stats:	 Avg geom mean = 8.08 (5.48..10.34)	68% chance between 6.83 and 9.33
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1969,1978,5.7,5.4828490622638615,List((1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1)))
Max window is (1980,1989,10.52,10.339809675418588,List((1980,15.0), (1981,0.0), (1982,14.8), (1983,15.0), (1984,1.4), (1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0)))


15-year stats
==========================
S&P 500 stats:	 Avg geom mean = 7.30 (0.90..15.59)	68% chance between 3.58 and 11.02
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1960,1974,2.1333333333333333,0.9045720770387566,List((1960,-3.0), (1961,23.1), (1962,-11.8), (1963,18.9), (1964,13.0), (1965,9.1), (1966,-13.1), (1967,20.1), (1968,7.7), (1969,-11.4), (1970,0.1), (1971,10.8), (1972,15.6), (1973,-17.4), (1974,-29.7)))
Max window is (1985,1999,16.266666666666666,15.593217663103399,List((1985,26.3), (1986,14.6), (1987,2.0), (1988,12.4), (1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7), (1999,19.5)))

EIUL stats:	 Avg geom mean = 8.18 (6.51..10.54)	68% chance between 7.22 and 9.14
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1960,1974,6.713333333333333,6.510463134204358,List((1960,0.0), (1961,15.0), (1962,0.0), (1963,15.0), (1964,13.0), (1965,9.1), (1966,0.0), (1967,15.0), (1968,7.7), (1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0)))
Max window is (1985,1999,10.706666666666667,10.544202859986584,List((1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0), (1990,0.0), (1991,15.0), (1992,4.5), (1993,7.1), (1994,0.0), (1995,15.0), (1996,15.0), (1997,15.0), (1998,15.0), (1999,15.0)))


20-year stats
==========================
S&P 500 stats:	 Avg geom mean = 7.16 (2.73..13.95)	68% chance between 4.07 and 10.25
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1962,1981,4.025,2.7296122232188136,List((1962,-11.8), (1963,18.9), (1964,13.0), (1965,9.1), (1966,-13.1), (1967,20.1), (1968,7.7), (1969,-11.4), (1970,0.1), (1971,10.8), (1972,15.6), (1973,-17.4), (1974,-29.7), (1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7)))
Max window is (1980,1999,14.680000000000001,13.954525490462633,List((1980,25.8), (1981,-9.7), (1982,14.8), (1983,17.3), (1984,1.4), (1985,26.3), (1986,14.6), (1987,2.0), (1988,12.4), (1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7), (1999,19.5)))

EIUL stats:	 Avg geom mean = 8.13 (6.81..10.16)	68% chance between 7.32 and 8.94
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1959,1978,7.014999999999999,6.8127345067537926,List((1959,8.5), (1960,0.0), (1961,15.0), (1962,0.0), (1963,15.0), (1964,13.0), (1965,9.1), (1966,0.0), (1967,15.0), (1968,7.7), (1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1)))
Max window is (1980,1999,10.34,10.159195461024083,List((1980,15.0), (1981,0.0), (1982,14.8), (1983,15.0), (1984,1.4), (1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0), (1990,0.0), (1991,15.0), (1992,4.5), (1993,7.1), (1994,0.0), (1995,15.0), (1996,15.0), (1997,15.0), (1998,15.0), (1999,15.0)))


25-year stats
==========================
S&P 500 stats:	 Avg geom mean = 7.15 (3.94..13.05)	68% chance between 4.77 and 9.53
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1957,1981,5.315999999999999,3.9398007731819895,List((1957,-14.3), (1958,38.1), (1959,8.5), (1960,-3.0), (1961,23.1), (1962,-11.8), (1963,18.9), (1964,13.0), (1965,9.1), (1966,-13.1), (1967,20.1), (1968,7.7), (1969,-11.4), (1970,0.1), (1971,10.8), (1972,15.6), (1973,-17.4), (1974,-29.7), (1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7)))
Max window is (1975,1999,13.844000000000001,13.04769964490491,List((1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7), (1982,14.8), (1983,17.3), (1984,1.4), (1985,26.3), (1986,14.6), (1987,2.0), (1988,12.4), (1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7), (1999,19.5)))

EIUL stats:	 Avg geom mean = 8.18 (7.10..9.82)	68% chance between 7.52 and 8.84
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1957,1981,7.303999999999999,7.095061439650552,List((1957,0.0), (1958,15.0), (1959,8.5), (1960,0.0), (1961,15.0), (1962,0.0), (1963,15.0), (1964,13.0), (1965,9.1), (1966,0.0), (1967,15.0), (1968,7.7), (1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1), (1979,12.3), (1980,15.0), (1981,0.0)))
Max window is (1975,1999,10.008,9.819046348080974,List((1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1), (1979,12.3), (1980,15.0), (1981,0.0), (1982,14.8), (1983,15.0), (1984,1.4), (1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0), (1990,0.0), (1991,15.0), (1992,4.5), (1993,7.1), (1994,0.0), (1995,15.0), (1996,15.0), (1997,15.0), (1998,15.0), (1999,15.0)))


30-year stats
==========================
S&P 500 stats:	 Avg geom mean = 7.17 (5.14..10.05)	68% chance between 5.66 and 8.68
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1952,1981,6.45,5.139499749040755,List((1952,11.8), (1953,-6.6), (1954,26.4), (1955,26.4), (1956,2.6), (1957,-14.3), (1958,38.1), (1959,8.5), (1960,-3.0), (1961,23.1), (1962,-11.8), (1963,18.9), (1964,13.0), (1965,9.1), (1966,-13.1), (1967,20.1), (1968,7.7), (1969,-11.4), (1970,0.1), (1971,10.8), (1972,15.6), (1973,-17.4), (1974,-29.7), (1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7)))
Max window is (1975,2004,11.166666666666666,10.054418675228272,List((1975,31.5), (1976,19.1), (1977,-11.5), (1978,1.1), (1979,12.3), (1980,25.8), (1981,-9.7), (1982,14.8), (1983,17.3), (1984,1.4), (1985,26.3), (1986,14.6), (1987,2.0), (1988,12.4), (1989,27.3), (1990,-6.6), (1991,26.3), (1992,4.5), (1993,7.1), (1994,-1.5), (1995,34.1), (1996,20.3), (1997,31.0), (1998,26.7), (1999,19.5), (2000,-10.1), (2001,-13.0), (2002,-23.4), (2003,26.4), (2004,9.0)))

EIUL stats:	 Avg geom mean = 8.20 (7.36..9.00)	68% chance between 7.74 and 8.66
Windows displayed are (first year, last year, arithmetic mean, geom mean, and the original data)
Min window is (1952,1981,7.566666666666666,7.359553946499009,List((1952,11.8), (1953,0.0), (1954,15.0), (1955,15.0), (1956,2.6), (1957,0.0), (1958,15.0), (1959,8.5), (1960,0.0), (1961,15.0), (1962,0.0), (1963,15.0), (1964,13.0), (1965,9.1), (1966,0.0), (1967,15.0), (1968,7.7), (1969,0.0), (1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1), (1979,12.3), (1980,15.0), (1981,0.0)))
Max window is (1970,1999,9.203333333333335,8.998481077806385,List((1970,0.1), (1971,10.8), (1972,15.0), (1973,0.0), (1974,0.0), (1975,15.0), (1976,15.0), (1977,0.0), (1978,1.1), (1979,12.3), (1980,15.0), (1981,0.0), (1982,14.8), (1983,15.0), (1984,1.4), (1985,15.0), (1986,14.6), (1987,2.0), (1988,12.4), (1989,15.0), (1990,0.0), (1991,15.0), (1992,4.5), (1993,7.1), (1994,0.0), (1995,15.0), (1996,15.0), (1997,15.0), (1998,15.0), (1999,15.0)))

Something went wrong with that request. Please try again.