NtropiX_medium.jpg

 

Software For Algorithmic Trading Of Equities:

The Tsinvestsim Program - Generate a Time Series for the Tsinvest Program


Home | Installation | Usage | FAQs | Utilities | Architecture | QA | Tests | Links | Mailing List | License | Author | Download | Thanks



home.jpg
installation.jpg
usage.jpg
FAQs.jpg
utilities.jpg
architecture.jpg
QA.jpg
tests.jpg
links.jpg
mailinglist.jpg
license.jpg
author.jpg
download.jpg
thanks.jpg

tsinvestsim [-n n] [-v] infile number

DESCRIPTION

Tsinvestsim is for generating a time series for the tsinvest(1) program. Generates a fractal time series, of many equities, concurrently.

The time series' increments for each equity is generated as a binomial distribution, (which is a reasonably close approximation to a Gaussian distribution, and is a reasonably close first order approximation to an equity's value, over time.)

The input file is organized, one equity per record, with each record having up to four fields, of which only the Shannon probability need be specified. The fields are sequential, in any order, with the field type specified by a single letter-P for the Shannon probability, H for the short term, (Markov,) Hurst exponent, F for the wager fraction, I for the initial value, and L if the distribu- tion of the marginal increments for a stock is to have exponential leptokurtosis. Any field that is not one of these letters is assumed to be the equity's name. For example:


  ABC, P = 0.51, F = 0.01, I = 31
  DEF, P = 0.52, F = 0.02, I = 4, L = 1
  GHI, P = 0.53, F = 0.03, I = 65

        

Naturally, single letter equity names should be avoided, (since P, H, F, I, and L, are reserved tokens.) Any punc- tuation is for clarity, and ignored. Upper or lower case characters may be used. The fields are delimited by whitespace, or punctuation. Comment records are are signi- fied by a '#' character as the first non whitespace char- acter in a record. Blank records are ignored.

The output file structure is a text file consisting of records, in temporal order, one record per time series sample of each equity. Blank records are ignored, and comment records are signified by a '#' character as the first non white space character in the record. Each data record represents an equity transaction, consisting of a minium of three fields, separated by white space. The fields are ordered by time stamp, equity ticker identifier, and closing price, for example:


  0       GHI     62.270000
  0       DEF     3.967743
  0       ABC     30.752000
  1       GHI     64.885340
  1       DEF     3.951808
  1       ABC     29.890944

        

The index of various American equity markets, since 1950, can be simulated with 10 equities, each having p = 0.505, and f = 0.03. For the last few years, p = 0.51 to 0.52 should be used, with f = 0.03 for each equity. In general, more than 10 equities will have to be simulated, making the index volatility, ie., the root mean square of the normalized increments of the index, too small.


DERIVATION

The equity value simulator produces a time series, with normal, or Gaussian, distributed increments, approximated with a binomial distribution, produced by sequential calls to a uniform deviate random number generator, and using the formula:


  V(t) = V(t - 1)(1 + f * F(t))

        

where V(t - 1) and V(t) is the previous and next values of the equity in the recursion, F(t) is the normal, or Gaussian, distributed fluctuations in the equity's value, of unit variance, and, f, is a scaling factor. If F(t) is not zero mean, the Shannon probability, P, of an increase in the equity's price, (ie., the likelihood of an up movement,) is:


      avg
      --- + 1
      rms
  P = -------
         2

        

where avg is the offset of the mean, and f = rms, ie., avg is the average growth in the equity's value, (eg., the average of the increments,) and rms the risk, (eg., the root mean square of the increments.)

The Shannon probability, P, is simulated with an offset in the summation of the uniform deviate random number generator to produce a binomial distribution-ie., if the threshold, for increase, or decrease, is 0.5, (where the uniform deviate values lie between 0 and 1,) then P = 0.5, and avg = 0. If the threshold is 0.49, then P = 0.51, (and rms always is equal to f,) and so on.

For more details on the equity price model used, see the manual page for tsinvest(1) for a complete derivation.

The short term, (Markov,) Hurst exponent specifies persistence, from one time increment to the next. If the Hurst exponent is 0.5, there is no persistence, (ie., whether the next time increment will have an increase, or decrease in value, is a 50%/50% proposition.) If it is larger than 0.5, then there is a propensity for what happened in the last increment to happen in the next, (ie., a better than 50%/50% proposition.) And, if the Hurst exponent is less than 0.5, there is a propensity for the opposite of what happened in the last increment to happen in the next.

For example, if the Hurst exponent is 0.6, then there is a 60% chance of what happened in the last element of the time series, to happen in the next.

The way this is implemented in tsinvestsim(1), is to find what value the preceeding value must be multiplied by, such that when added to the current value will increase the probability that the current value will do the same thing as the preceeding value-ie., it is a recursive algorithm:


  V(t)  = (G  + (Hvalue * V(t - 1)))

        

where G is normally, or Gaussian, distributed random variable of unit variance, (approximated by a binomial distribution,) Hvalue is the multiplying value, and V the value of an equity at time t, and t - 1, (which will be corrected to unit variance.)

The value, Hvalue, is calculated by finding x, in the normal, or Gaussian, distribution, F(x), where F(x) is the Hurst exponent.

For example, if it is desired that the current value of a stock's value have a persistence of H, meaning that the value of F(x) = H, find x, which the previous stock's value will be multiplied by, and added to the current value. For example, if H = F(x) = 0.6, then x would be about 0.25, meaning that the previous value would be multiplied by 0.25, and added to the current value.

V, of course, does not have unit variance, and must be compensated by a correction factor:


  V(t)  = (G  + (Hvalue * V(t - 1))) * correction

        

such that both the current and previous values of V have unit variance, or working with distributions:


      2     2                      2              2
  V(t)  = (G  + (Hvalue * V(t - 1)) ) * correction

        

where V = G = 1:


   2     2              2               2
  1  = (1  + (Hvalue * 1 )) * correction

        

or:


                 2              2
  1 = (1 + Hvalue ) * correction

        

and, finally:


                                    2
  correction = sqrt (1 / (1 + Hvalue ))

        

Obviously, the maximum Hurst exponent, H, that can be accommodated is one standard deviation, (ie., 0.84,) since the recursion will diverge for values greater.


OPTIONS

-n n
Number of elements in the binomial distribution, (100).

-v
Print the version and copyright banner of this program.

infile
Input filename.

number
Number of samples in the time series.


WARNINGS

There is little or no provision for handling numerical exceptions.


SEE ALSO

tsinvest(1), tsinvestsim(1), tsshannoneffective(1)


DIAGNOSTICS

Error messages for incompatible arguments, failure to allocate memory, inaccessible files, and opening and closing files.


AUTHORS


A license is hereby granted to reproduce this software source code and to create executable versions from this source code for personal, non-commercial use. The copyright notice included with the software must be maintained in all copies produced.

THIS PROGRAM IS PROVIDED "AS IS". THE AUTHOR PROVIDES NO WARRANTIES WHATSOEVER, EXPRESSED OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, TITLE, OR FITNESS FOR ANY PARTICULAR PURPOSE. THE AUTHOR DOES NOT WARRANT THAT USE OF THIS PROGRAM DOES NOT INFRINGE THE INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD PARTY IN ANY COUNTRY.

So there.

Copyright © 1994-2011, John Conover, All Rights Reserved.


Comments and/or bug reports should be addressed to:

john@email.johncon.com

http://www.johncon.com/
http://www.johncon.com/ntropix/
http://www.johncon.com/ndustrix/
http://www.johncon.com/nformatix/
http://www.johncon.com/ndex/



Home | Installation | Usage | FAQs | Utilities | Architecture | QA | Tests | Links | Mailing List | License | Author | Download | Thanks


Copyright © 1994-2011 John Conover, john@email.johncon.com. All Rights Reserved.
Last modified: Sun Apr 24 00:04:51 PDT 2011 $Id: tsinvestsim.html,v 1.0 2011/04/24 07:07:34 conover Exp $
Valid HTML 4.0!