{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "pygments_lexer": "ipython3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# 19 Refinery utilization\n",
        "\n",
        "On weeks when refinery utilization is further from its pre-2020 median than the train 90th percentile of that distance, is the holdout mean absolute Wednesday RWTC return larger?\n",
        "\n",
        "Holdout starts 2020-01-01. Verdict: held.\n",
        "\n",
        "WPULEUS3 minus its train median, in percentage points of utilization. Train median 90.40 percent. An anomaly is an absolute deviation at or above the train 90th percentile of absolute deviations, frozen at 7.10 points."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "source": [
        "import json\n",
        "from pathlib import Path\n",
        "studies = json.loads(Path('data/studies.json').read_text())\n",
        "study = next(item for item in studies['studies'] if item['slug'] == 'util-anomaly')\n",
        "print(study['verdict'])\n",
        "print(study['verdict_line'])\n",
        "print(study['table']['caption'])\n",
        "for row in study['table']['rows']:\n",
        "    print(' | '.join(row))\n"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "held\n",
            "Train gap in mean absolute Wednesday return, anomaly minus the rest, is 0.264%. Holdout gap is 0.787% (62 anomalies, 286 other weeks). The holdout gap is positive, which was the bar.\n",
            "Mean absolute Wednesday RWTC return on utilization anomalies\n",
            "Train | 137 | 1193 | 0.264%\n",
            "Holdout | 62 | 286 | 0.787%\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Method\n",
        "\n",
        "The bar is a positive holdout gap in absolute return. The cutoff stays at the train 90th percentile.\n",
        "\n",
        "## Result\n",
        "\n",
        "Train gap in mean absolute Wednesday return, anomaly minus the rest, is 0.264%. Holdout gap is 0.787% (62 anomalies, 286 other weeks). The holdout gap is positive, which was the bar."
      ]
    }
  ]
}
