{
  "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": [
        "# 04 COT positioning\n",
        "\n",
        "After managed money net on WTI-PHYSICAL is extremely long versus the pre-2020 book, is the next five-print RWTC return higher?\n",
        "\n",
        "Holdout starts 2020-01-01. Verdict: failed.\n",
        "\n",
        "This study reads stored series. It does not add a derived column."
      ]
    },
    {
      "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'] == 'positioning')\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": [
            "failed\n",
            "The frozen 90th percentile of managed-money net over open interest is 0.1653. Train five-print return above that line minus the return below it is -0.444%. Holdout difference is 1.034%. The holdout flipped the train sign.\n",
            "Five-print RWTC return after CFTC_CL managed-money net / open interest\n",
            "Train | At or above 0.1653 | 52 | -0.471%\n",
            "Train | Below the frozen line | 467 | -0.027%\n",
            "Holdout | At or above 0.1653 | 16 | 1.023%\n",
            "Holdout | Below the frozen line | 335 | -0.011%\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Method\n",
        "\n",
        "The 90th percentile is the nearest rank of the train ratios only. The holdout is cut with that same number.\n",
        "\n",
        "## Result\n",
        "\n",
        "The frozen 90th percentile of managed-money net over open interest is 0.1653. Train five-print return above that line minus the return below it is -0.444%. Holdout difference is 1.034%. The holdout flipped the train sign."
      ]
    }
  ]
}
