script that does the same thing as tsinvest?

From: John Conover <>
Subject: script that does the same thing as tsinvest?
Date: 14 Dec 2000 18:07:53 -0000

The numerical methods used in tsinvest are quite straight forward, and
most can be done in a spread sheet.

There is, also, a set of 60 some programs that can be used for general
fractal analysis at, or
they can be downloaded as a tape archive from

The tsinvest sources were, largely, cut-and-stick from the sources to
these programs.

A possible scenario to automatically pick stocks might be:

    To find the marginal increments, (i.e., the fluctuations,) of a
    stock's price, use the tsfraction program.

    To find the average increase in value, use the tsavg program.

    To find the risk of the investing in a stock, (i.e., the root mean
    square of the fluctuations,) use the tsrms program.

which is the two values used by tsinvest.

So, if sprice is the name of a file containing the price of a stock
over time:

    tsfraction sprice | tsavg -p

would print the average increase in value of the stock, avg, and:

    tsfraction sprice | tsrms -p

would print the risk of investing in the stock, rms.

Then, the Shannon Entropy, (or Shannon Probability, i.e., the
likelihood of an up movement,) P, would be:

    P = ((avg / rms) + 1) / 2

Or you could use the tsshannonwindow program to measure the entropy

    tsshannonwindow -a -b -c -d -e -f -g -h sprice

To calculate the gain, G, in value of a stock, use the tsgain program:

    tsgain -a avg -r rms

which, as a stock picker, bigger values are better. All it does is
solve the equation:

    G = ((1 + rms)^P) * ((1 - rms)^(1 - P))

This would be the same as the -d1 option to tsinvest. The -d2 option
assumes avg = rms * rms, and the -d3, rms = sqrt (avg).

To get the -d5 value, one needs the persistence in the time series,
and the tsrootmean program can be used:

    tsrootmean -p sprice

will give the persistence, (which is the same as the Shannon Entropy,
P, in this case.)

If you want to compensate the values for uncertainty do to data set
size, use the statistical estimation program, tsstatest:

    tsstatest -P P -D 0.001

which is the default in tsinvest, (the -c option disables it.)

Or, if compensation for run lengths is required, (the -C option in
tsinvest,) use the tsshannoneffective program, (where count is the
number of time samples in the sprice file,):

    tsshannoneffective avg rms count

Both the tsstatest and tsshannoneffective programs print a probability
of uncertainty do to data set size, so the measured Shannon Entropy
and one, or both, of these values can be multiplied together to get
the likelihood of an up movement in a stock's price, which is
compensated for data set size and/or run length.

If you automate this with a shell script, and do it for many stocks at
the same time, (picking stocks that have the largest value from
tsgain,) the result will be very close to what tsinvest does.


BTW, note that there are really only two empirical constants used,
avg, and rms, both of which can be calculated in a spread sheet from a
stock price time series. Many spread sheets have statistical
estimation capability, and the functionality of the tsshannoneffective
program can be approximated with the square root function, for t >> 1.


John Conover,,

Copyright © 2000 John Conover, All Rights Reserved.
Last modified: Thu Dec 14 13:07:14 PST 2000 $Id: 001214100805.31544.html,v 1.0 2001/11/17 23:05:50 conover Exp $
Valid HTML 4.0!