#! /bin/bash
# Last edited on 2015-04-20 01:01:46 by stolfilocal

prefix="$1"; shift

pricesfile="${prefix}-prices.txt"
gainsfile="${prefix}-gains.txt"
cat ${pricesfile} \
  | gawk \
      ' BEGIN { op = 0; } 
        /^ *20/ { 
          y = $1; p = $2 + 0;
          if (op == 0) { 
            y0 = y; 
          } else if (op > 0) { 
            x = y - y0 - 1;
            g = p/op;
            z = log(g)/log(10);
            printf "%d %+8.5f %5.2f %5.2f %5.2f\n", y, z, 1.0, x, x*x;
          }
          op = p;
        }
      ' \
  > ${gainsfile}
cat ${gainsfile} 1>&2 
