AMI Profile Analysis
Author: Peter Catt
The Knowable Future, theknowablefuture.com

------------------------------------------------------------------------
WHAT THIS DOES
------------------------------------------------------------------------

Estimates horizon-specific lag-pair auto-mutual information (AMI) for each
series in a CSV file. AMI is computed on first-differenced values: at each
horizon h it measures the information the current difference carries about
the difference h steps ahead, in nats.

This is a deliberately restricted quantity. It describes dependence in the
differenced process for a single-observation information set. It is not
forecastability of the original levels and not forecastability from the
full history, and it does not say which forecasting method will use that
dependence best; that needs separate out-of-sample evaluation.

Each series is described as Low, Moderate or High lag-pair AMI, using the
AMI at horizon 1 and its persistence across horizons (mean AMI divided by
AMI at horizon 1). The thresholds are illustrative defaults, not calibrated
values; adjust them for your portfolio.

Outputs:

  ami_<series>.png  two-panel chart: raw series (top), AMI profile (bottom)
  results.csv       AMI by series and horizon, with the number of pairs
  summary.csv       one row per series: AMI at horizon 1, mean AMI,
                    persistence, peak AMI and horizon, and class

------------------------------------------------------------------------
DEPENDENCIES
------------------------------------------------------------------------

Python 3.9 or later is required. Install dependencies via pip:

  pip install numpy pandas matplotlib seaborn scikit-learn

------------------------------------------------------------------------
SAMPLE DATA
------------------------------------------------------------------------

sample_data.csv is included to allow an immediate test run. It contains
four series across two frequencies:

  Passengers  monthly airline passenger counts (classic seasonal series)
  Sine_Wave   deterministic periodic signal (monthly)
  Henon_Map   chaotic deterministic system (monthly)
  AAPL        Apple Inc. daily closing prices

Rows where a series has no value are left blank and handled automatically
by the script.

To run with the sample data, set INPUT_CSV_PATH to the full path of
sample_data.csv and DATE_COLUMN_NAME to "Date".

------------------------------------------------------------------------
SETUP
------------------------------------------------------------------------

1. Open ami_analysis.py in any text editor or Python IDE.

2. Update the three lines at the top of the USER CONFIGURATION section:

     INPUT_CSV_PATH   full path to your CSV file
     OUTPUT_DIR       folder where outputs will be written
     DATE_COLUMN_NAME exact name of the date column in your CSV

3. CSV format requirements:
     - One date column in YYYY-MM-DD format
     - One or more numeric columns (each treated as a separate series)
     - At least 55 observations per series with the default settings
       (MAX_HORIZON 24 + MIN_PAIRS 30 + 1); shorter series are skipped

4. Run the script:

     python ami_analysis.py

   Outputs are written to OUTPUT_DIR automatically.

------------------------------------------------------------------------
ADVANCED CONFIGURATION
------------------------------------------------------------------------

The maximum horizon, the minimum number of lagged pairs, the number of
nearest neighbours and the class thresholds can be adjusted in the
ADVANCED CONFIGURATION section of the script. Every series is assessed
over the same horizons, so classes are comparable across series.

------------------------------------------------------------------------
METHOD
------------------------------------------------------------------------

AMI is estimated with scikit-learn's mutual_info_regression, which
implements the Kraskov, Stögbauer and Grassberger (KSG) k-nearest-neighbour
estimator. Estimates carry bias and sampling error; negative estimates are
reported as zero.

Kraskov, A., Stögbauer, H., & Grassberger, P. (2004). Estimating mutual
information. Physical Review E, 69(6), 066138.
https://doi.org/10.1103/PhysRevE.69.066138

------------------------------------------------------------------------
CONTACT
------------------------------------------------------------------------

theknowablefuture.com
