ans_econ_tools: A collection of useful tools in doing economics


This is a set of executables which are useful in doing economics and finance. They utilise a variety of implementation techniques, but in the end, each of them yields an executable that you can run.

The tools are:

  1. rollingvol: Compute 'rolling window volatility' estimates.
  2. rollingcorr: Compute 'rolling window correlation coefficients'.
  3. univar: Compute univariate descriptive statistics.

rollingvol

The program makes a rolling window volatility estimator using a window of width N time-periods. If you don't specify N, then it defaults to 250. For example, you could --

$ ./rollingvol.pl --width 500 --annualise < test.returns 
03-01-02 0.282286037008975
04-01-02 0.281963923462387
07-01-02 0.281398535300216
08-01-02 0.28129726927646
09-01-02 0.281323433564108
10-01-02 0.281188792597485
11-01-02 0.280064994961043
14-01-02 0.279401120905391

Here, you asked for rolling windows of width 500 time periods, and you asked for annualisation of the resulting volatility estimates.

Usage :


$ rollingvol.pl [--width N]
           [--annualise]
           [--difference]
           [--pchanges]
           [--makereturns]

The input to this program, on stdin, is a series of the format:

   date  value
   date  value
   date  value
   ...

The special code "." is used to mean "missing data". When faced with missing data, rollingvol behaves as follows. He will respect your window width N, isolate all non-missing data within that window, and compute a volatility using these points only.

Options controlling display of results:

Options controlling pre-processing of data (pick any one ONLY):

On stdout, the series that is written is a time-series for each date of the volatility over the last N time-periods.

rollingcorr

This program makes a rolling window correlation coefficient estimator using a window of width N time-periods. If you don't specify N, then it defaults to 250. For example, you could --

$ ./rollingcorr.pl --width 95 testcase
95 0.9375124
96 0.9363526
97 0.9357725
98 0.9354432
99 0.9404018
100 0.9435606

Here, you asked for rolling windows of width 95 time periods. The data file had 100 lines. So you got results for time period 95 to 100. At each point, he does a lookback for 95 observations.

Usage :


$ rollingcorr.pl [--width N]

The input, on stdin, is a series of the format:

   date  value value
   date  value value
   date  value value
   ...

As with rollingvol, the special code "." is used to mean "missing data". When faced with missing data, rollingcorr behaves as follows. He will respect your window width N, isolate all non-missing data within that window, and compute a correlation coefficient using that.

univar

This program reports univariate summary statistics given a vector of input data. For example, you could --

$ cat testcase | ./univar.pl
Number of points               : 999
Mean                           : -0.000384
Standard devn                  : 1.002072

Min                            : -3.190681
Percentile  1.0                : -2.389175
Percentile  5.0                : -1.700496
Percentile 10.0                : -1.270056
Percentile 25.0                : -0.711448
Percentile 50.0                : 0.059162
Percentile 75.0                : 0.693471
Percentile 90.0                : 1.265343
Percentile 95.0                : 1.620296
Percentile 99.0                : 2.386520
Max                            : 2.886820

Usage:

$ ./univar.pl [-trimmed float]

./univar.pl is a filter which eats a vector of numbers on stdin and reports all sorts of summary statistics on stdout.

If the argument -trimmed is supplied, then the raw data is first trimmed. Example: Suppose you say -trimmed 1 Then the most extreme 1% of the data at the top and the bottom is first removed. The remaining 98% of the data is processed as usual. So you get trimmed mean, trimmed median, etc.


Back up to Ajay Shah's home page -- Free software


Ajay Shah
ajayshah at mayin dot org