trading_analysis/COT_data_nasdaq_Silver.ipynb

3028 lines
351 KiB
Plaintext
Raw Permalink Normal View History

2024-08-19 17:41:20 +00:00
{
"cells": [
{
"cell_type": "markdown",
"id": "68e3c2ce-ed33-4c9d-851c-86184d9d3414",
"metadata": {},
"source": [
"# Load NASDAQ API key (Data Link API) - Silver\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "7629bec6-f9e7-4180-aa56-0c2e857d34cb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"# Load the environment variables from .env file\n",
"load_dotenv(\"api_keys\")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "aa5b3443-449e-4f02-b231-1ffdef4d11ac",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"loaded key\n"
]
}
],
"source": [
"nasdaq_api_key = os.getenv('NASDAQ_API_KEY')\n",
"if len(nasdaq_api_key) > 0:\n",
" print(\"loaded key\")"
]
},
{
"cell_type": "markdown",
"id": "5fdcd717-d4a3-4e7e-b8b5-a4369bd1bc83",
"metadata": {},
"source": [
"## Retrieve 2 year of COT data (% shifts producers long / short)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "fc5d6a91-c107-443e-8b6e-84e10d945ca2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Open Interest Producer/Merchant/Processor/User Longs \\\n",
"Date \n",
"2023-11-28 139144.0 3472.0 \n",
"2023-12-05 139753.0 4714.0 \n",
"2023-12-12 134281.0 4311.0 \n",
"2023-12-19 127549.0 3701.0 \n",
"2023-12-26 131408.0 4063.0 \n",
"\n",
" Producer/Merchant/Processor/User Shorts Swap Dealer Longs \\\n",
"Date \n",
"2023-11-28 40323.0 33045.0 \n",
"2023-12-05 41340.0 33328.0 \n",
"2023-12-12 38849.0 30707.0 \n",
"2023-12-19 39714.0 30908.0 \n",
"2023-12-26 41011.0 29911.0 \n",
"\n",
" Swap Dealer Shorts Swap Dealer Spreads Money Manager Longs \\\n",
"Date \n",
"2023-11-28 44049.0 3770.0 45604.0 \n",
"2023-12-05 48716.0 2932.0 43852.0 \n",
"2023-12-12 43665.0 2832.0 33472.0 \n",
"2023-12-19 43686.0 1911.0 34931.0 \n",
"2023-12-26 45585.0 2415.0 36546.0 \n",
"\n",
" Money Manager Shorts Money Manager Spreads \\\n",
"Date \n",
"2023-11-28 21842.0 6885.0 \n",
"2023-12-05 22322.0 7544.0 \n",
"2023-12-12 24805.0 8439.0 \n",
"2023-12-19 20060.0 6662.0 \n",
"2023-12-26 19749.0 6847.0 \n",
"\n",
" Other Reportable Longs Other Reportable Shorts \\\n",
"Date \n",
"2023-11-28 17276.0 6758.0 \n",
"2023-12-05 19389.0 4616.0 \n",
"2023-12-12 22212.0 2421.0 \n",
"2023-12-19 17700.0 2820.0 \n",
"2023-12-26 18013.0 2947.0 \n",
"\n",
" Other Reportable Spreads Total Reportable Longs \\\n",
"Date \n",
"2023-11-28 2445.0 112497.0 \n",
"2023-12-05 1607.0 113366.0 \n",
"2023-12-12 1706.0 103679.0 \n",
"2023-12-19 1577.0 97390.0 \n",
"2023-12-26 2137.0 99932.0 \n",
"\n",
" Total Reportable Shorts Non Reportable Longs \\\n",
"Date \n",
"2023-11-28 126072.0 26647.0 \n",
"2023-12-05 129077.0 26387.0 \n",
"2023-12-12 122717.0 30602.0 \n",
"2023-12-19 116430.0 30159.0 \n",
"2023-12-26 120691.0 31476.0 \n",
"\n",
" Non Reportable Shorts \n",
"Date \n",
"2023-11-28 13072.0 \n",
"2023-12-05 10676.0 \n",
"2023-12-12 11564.0 \n",
"2023-12-19 11119.0 \n",
"2023-12-26 10717.0 \n"
]
}
],
"source": [
"import requests\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"import urllib.parse\n",
"\n",
"# API endpoint components\n",
"base_url = \"https://data.nasdaq.com/api/v3/datasets/\"\n",
"dataset = \"CFTC/084691_F_ALL\"\n",
"data_format = \".json\"\n",
"\n",
"# Parameters\n",
"params = {\n",
" \"start_date\": \"2022-01-01\",\n",
" \"end_date\": \"2024-01-01\",\n",
" \"api_key\": nasdaq_api_key # Make sure this variable is defined\n",
"}\n",
"\n",
"# Construct the full URL with parameters\n",
"param_string = urllib.parse.urlencode(params)\n",
"url = f\"{base_url}{dataset}{data_format}?{param_string}\"\n",
"\n",
"# Make the API request\n",
"response = requests.get(url)\n",
"\n",
"# Check if the request was successful\n",
"if response.status_code == 200:\n",
" # Parse the JSON response\n",
" data = response.json()\n",
" \n",
" # Extract the dataset from the response\n",
" dataset = data['dataset']\n",
" \n",
" # Create a pandas DataFrame\n",
" df = pd.DataFrame(dataset['data'], columns=dataset['column_names'])\n",
" \n",
" # Convert the date column to datetime\n",
" df['Date'] = pd.to_datetime(df['Date'])\n",
" \n",
" # Set the date as the index\n",
" df.set_index('Date', inplace=True)\n",
" \n",
" # Sort the DataFrame by date\n",
" df.sort_index(inplace=True)\n",
" \n",
" # Display the first few rows of the DataFrame\n",
" print(df.tail())\n",
" \n",
" # You can now use this DataFrame for further analysis or visualization\n",
" \n",
"else:\n",
" print(f\"Error fetching data: {response.status_code}\")\n",
" print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "a1ab3a82-5682-4701-ab9e-414d6d4ff115",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Open Interest', 'Producer/Merchant/Processor/User Longs',\n",
" 'Producer/Merchant/Processor/User Shorts', 'Swap Dealer Longs',\n",
" 'Swap Dealer Shorts', 'Swap Dealer Spreads', 'Money Manager Longs',\n",
" 'Money Manager Shorts', 'Money Manager Spreads',\n",
" 'Other Reportable Longs', 'Other Reportable Shorts',\n",
" 'Other Reportable Spreads', 'Total Reportable Longs',\n",
" 'Total Reportable Shorts', 'Non Reportable Longs',\n",
" 'Non Reportable Shorts'],\n",
" dtype='object')"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "61ac72a5-b8f9-451f-ae0e-2c9b5ed7358a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open Interest</th>\n",
" <th>Producer/Merchant/Processor/User Longs</th>\n",
" <th>Producer/Merchant/Processor/User Shorts</th>\n",
" <th>Swap Dealer Longs</th>\n",
" <th>Swap Dealer Shorts</th>\n",
" <th>Swap Dealer Spreads</th>\n",
" <th>Money Manager Longs</th>\n",
" <th>Money Manager Shorts</th>\n",
" <th>Money Manager Spreads</th>\n",
" <th>Other Reportable Longs</th>\n",
" <th>Other Reportable Shorts</th>\n",
" <th>Other Reportable Spreads</th>\n",
" <th>Total Reportable Longs</th>\n",
" <th>Total Reportable Shorts</th>\n",
" <th>Non Reportable Longs</th>\n",
" <th>Non Reportable Shorts</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2023-11-28</th>\n",
" <td>139144.0</td>\n",
" <td>3472.0</td>\n",
" <td>40323.0</td>\n",
" <td>33045.0</td>\n",
" <td>44049.0</td>\n",
" <td>3770.0</td>\n",
" <td>45604.0</td>\n",
" <td>21842.0</td>\n",
" <td>6885.0</td>\n",
" <td>17276.0</td>\n",
" <td>6758.0</td>\n",
" <td>2445.0</td>\n",
" <td>112497.0</td>\n",
" <td>126072.0</td>\n",
" <td>26647.0</td>\n",
" <td>13072.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-05</th>\n",
" <td>139753.0</td>\n",
" <td>4714.0</td>\n",
" <td>41340.0</td>\n",
" <td>33328.0</td>\n",
" <td>48716.0</td>\n",
" <td>2932.0</td>\n",
" <td>43852.0</td>\n",
" <td>22322.0</td>\n",
" <td>7544.0</td>\n",
" <td>19389.0</td>\n",
" <td>4616.0</td>\n",
" <td>1607.0</td>\n",
" <td>113366.0</td>\n",
" <td>129077.0</td>\n",
" <td>26387.0</td>\n",
" <td>10676.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-12</th>\n",
" <td>134281.0</td>\n",
" <td>4311.0</td>\n",
" <td>38849.0</td>\n",
" <td>30707.0</td>\n",
" <td>43665.0</td>\n",
" <td>2832.0</td>\n",
" <td>33472.0</td>\n",
" <td>24805.0</td>\n",
" <td>8439.0</td>\n",
" <td>22212.0</td>\n",
" <td>2421.0</td>\n",
" <td>1706.0</td>\n",
" <td>103679.0</td>\n",
" <td>122717.0</td>\n",
" <td>30602.0</td>\n",
" <td>11564.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-19</th>\n",
" <td>127549.0</td>\n",
" <td>3701.0</td>\n",
" <td>39714.0</td>\n",
" <td>30908.0</td>\n",
" <td>43686.0</td>\n",
" <td>1911.0</td>\n",
" <td>34931.0</td>\n",
" <td>20060.0</td>\n",
" <td>6662.0</td>\n",
" <td>17700.0</td>\n",
" <td>2820.0</td>\n",
" <td>1577.0</td>\n",
" <td>97390.0</td>\n",
" <td>116430.0</td>\n",
" <td>30159.0</td>\n",
" <td>11119.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-26</th>\n",
" <td>131408.0</td>\n",
" <td>4063.0</td>\n",
" <td>41011.0</td>\n",
" <td>29911.0</td>\n",
" <td>45585.0</td>\n",
" <td>2415.0</td>\n",
" <td>36546.0</td>\n",
" <td>19749.0</td>\n",
" <td>6847.0</td>\n",
" <td>18013.0</td>\n",
" <td>2947.0</td>\n",
" <td>2137.0</td>\n",
" <td>99932.0</td>\n",
" <td>120691.0</td>\n",
" <td>31476.0</td>\n",
" <td>10717.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open Interest Producer/Merchant/Processor/User Longs \\\n",
"Date \n",
"2023-11-28 139144.0 3472.0 \n",
"2023-12-05 139753.0 4714.0 \n",
"2023-12-12 134281.0 4311.0 \n",
"2023-12-19 127549.0 3701.0 \n",
"2023-12-26 131408.0 4063.0 \n",
"\n",
" Producer/Merchant/Processor/User Shorts Swap Dealer Longs \\\n",
"Date \n",
"2023-11-28 40323.0 33045.0 \n",
"2023-12-05 41340.0 33328.0 \n",
"2023-12-12 38849.0 30707.0 \n",
"2023-12-19 39714.0 30908.0 \n",
"2023-12-26 41011.0 29911.0 \n",
"\n",
" Swap Dealer Shorts Swap Dealer Spreads Money Manager Longs \\\n",
"Date \n",
"2023-11-28 44049.0 3770.0 45604.0 \n",
"2023-12-05 48716.0 2932.0 43852.0 \n",
"2023-12-12 43665.0 2832.0 33472.0 \n",
"2023-12-19 43686.0 1911.0 34931.0 \n",
"2023-12-26 45585.0 2415.0 36546.0 \n",
"\n",
" Money Manager Shorts Money Manager Spreads \\\n",
"Date \n",
"2023-11-28 21842.0 6885.0 \n",
"2023-12-05 22322.0 7544.0 \n",
"2023-12-12 24805.0 8439.0 \n",
"2023-12-19 20060.0 6662.0 \n",
"2023-12-26 19749.0 6847.0 \n",
"\n",
" Other Reportable Longs Other Reportable Shorts \\\n",
"Date \n",
"2023-11-28 17276.0 6758.0 \n",
"2023-12-05 19389.0 4616.0 \n",
"2023-12-12 22212.0 2421.0 \n",
"2023-12-19 17700.0 2820.0 \n",
"2023-12-26 18013.0 2947.0 \n",
"\n",
" Other Reportable Spreads Total Reportable Longs \\\n",
"Date \n",
"2023-11-28 2445.0 112497.0 \n",
"2023-12-05 1607.0 113366.0 \n",
"2023-12-12 1706.0 103679.0 \n",
"2023-12-19 1577.0 97390.0 \n",
"2023-12-26 2137.0 99932.0 \n",
"\n",
" Total Reportable Shorts Non Reportable Longs \\\n",
"Date \n",
"2023-11-28 126072.0 26647.0 \n",
"2023-12-05 129077.0 26387.0 \n",
"2023-12-12 122717.0 30602.0 \n",
"2023-12-19 116430.0 30159.0 \n",
"2023-12-26 120691.0 31476.0 \n",
"\n",
" Non Reportable Shorts \n",
"Date \n",
"2023-11-28 13072.0 \n",
"2023-12-05 10676.0 \n",
"2023-12-12 11564.0 \n",
"2023-12-19 11119.0 \n",
"2023-12-26 10717.0 "
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail()"
]
},
{
"cell_type": "markdown",
"id": "96e0f458-9969-41a5-a153-9229c441eee5",
"metadata": {},
"source": [
"## Plot the data"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "0babd084-6190-4681-a6a3-23a95b92a68c",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"line": {
"color": "blue",
"width": 2
},
"mode": "lines",
"name": "Producer/Merchant/Processor/User Longs",
"type": "scatter",
"x": [
"2022-01-04T00:00:00",
"2022-01-11T00:00:00",
"2022-01-18T00:00:00",
"2022-01-25T00:00:00",
"2022-02-01T00:00:00",
"2022-02-08T00:00:00",
"2022-02-15T00:00:00",
"2022-02-22T00:00:00",
"2022-03-01T00:00:00",
"2022-03-08T00:00:00",
"2022-03-15T00:00:00",
"2022-03-22T00:00:00",
"2022-03-29T00:00:00",
"2022-04-05T00:00:00",
"2022-04-12T00:00:00",
"2022-04-19T00:00:00",
"2022-04-26T00:00:00",
"2022-05-03T00:00:00",
"2022-05-10T00:00:00",
"2022-05-17T00:00:00",
"2022-05-24T00:00:00",
"2022-05-31T00:00:00",
"2022-06-07T00:00:00",
"2022-06-14T00:00:00",
"2022-06-21T00:00:00",
"2022-06-28T00:00:00",
"2022-07-05T00:00:00",
"2022-07-12T00:00:00",
"2022-07-19T00:00:00",
"2022-07-26T00:00:00",
"2022-08-02T00:00:00",
"2022-08-09T00:00:00",
"2022-08-16T00:00:00",
"2022-08-23T00:00:00",
"2022-08-30T00:00:00",
"2022-09-06T00:00:00",
"2022-09-13T00:00:00",
"2022-09-20T00:00:00",
"2022-09-27T00:00:00",
"2022-10-04T00:00:00",
"2022-10-11T00:00:00",
"2022-10-18T00:00:00",
"2022-10-25T00:00:00",
"2022-11-01T00:00:00",
"2022-11-08T00:00:00",
"2022-11-15T00:00:00",
"2022-11-22T00:00:00",
"2022-11-29T00:00:00",
"2022-12-06T00:00:00",
"2022-12-13T00:00:00",
"2022-12-20T00:00:00",
"2022-12-27T00:00:00",
"2023-01-03T00:00:00",
"2023-01-10T00:00:00",
"2023-01-17T00:00:00",
"2023-01-24T00:00:00",
"2023-01-31T00:00:00",
"2023-02-07T00:00:00",
"2023-02-14T00:00:00",
"2023-02-21T00:00:00",
"2023-02-28T00:00:00",
"2023-03-07T00:00:00",
"2023-03-14T00:00:00",
"2023-03-21T00:00:00",
"2023-03-28T00:00:00",
"2023-04-04T00:00:00",
"2023-04-11T00:00:00",
"2023-04-18T00:00:00",
"2023-04-25T00:00:00",
"2023-05-02T00:00:00",
"2023-05-09T00:00:00",
"2023-05-16T00:00:00",
"2023-05-23T00:00:00",
"2023-05-30T00:00:00",
"2023-06-06T00:00:00",
"2023-06-13T00:00:00",
"2023-06-20T00:00:00",
"2023-06-27T00:00:00",
"2023-07-03T00:00:00",
"2023-07-11T00:00:00",
"2023-07-18T00:00:00",
"2023-07-25T00:00:00",
"2023-08-01T00:00:00",
"2023-08-08T00:00:00",
"2023-08-15T00:00:00",
"2023-08-22T00:00:00",
"2023-08-29T00:00:00",
"2023-09-05T00:00:00",
"2023-09-12T00:00:00",
"2023-09-19T00:00:00",
"2023-09-26T00:00:00",
"2023-10-03T00:00:00",
"2023-10-10T00:00:00",
"2023-10-17T00:00:00",
"2023-10-24T00:00:00",
"2023-10-31T00:00:00",
"2023-11-07T00:00:00",
"2023-11-14T00:00:00",
"2023-11-21T00:00:00",
"2023-11-28T00:00:00",
"2023-12-05T00:00:00",
"2023-12-12T00:00:00",
"2023-12-19T00:00:00",
"2023-12-26T00:00:00"
],
"y": [
3.9176898101361086,
3.980144279364728,
3.738814148463395,
3.4306458732762763,
4.5180238171869975,
4.403612454963055,
3.79121859232455,
2.99428990198174,
2.3406675095780574,
2.8250031197447156,
2.35757123788157,
2.318984149855908,
2.542579900929633,
2.878283936819143,
2.694363811526764,
2.0260644752809585,
2.9992166994187084,
3.0481073700723353,
3.7806825823806323,
4.5428757247429665,
4.836264816736768,
4.6340486486853445,
4.295521059516905,
5.405387621892642,
3.6524120091361896,
5.263855643527895,
6.423043790891551,
6.67163413211115,
6.5667449241636655,
7.136767173712986,
5.343920391584169,
5.026471901511769,
5.881619246919911,
6.719452468532873,
5.837911097654166,
5.9768618944323935,
4.1857891241791485,
3.479755047045198,
3.272093023255814,
2.2605849109045426,
3.003430900392444,
4.959758921024586,
3.8357838731710823,
3.266966696669667,
2.7450030974743123,
2.3004737930985786,
2.3435500011636297,
2.5870458031635026,
2.8100980760129897,
3.6223169129066943,
3.4862853695137614,
3.6600839126001232,
3.780589438593833,
3.7380444902701577,
3.6682289059774615,
3.3196958242540133,
3.6784967778798374,
3.9610481957470376,
3.534344443435353,
1.7715042048004133,
2.11138014527845,
3.206983365097292,
1.5578293860657624,
2.0884768478863305,
2.5759189062566548,
3.3183446383659785,
3.023146623312006,
2.7296664161999358,
1.7489244582208803,
1.684463090544276,
1.7594279624600366,
1.6904644674216314,
1.865330779431266,
1.4795799998503207,
2.296349486113831,
2.3691445730664986,
2.512562814070352,
2.0090532913329717,
0.796182518943201,
0.7291199015646563,
0.6414141070249144,
0.9816335144113602,
1.136410939516297,
1.1523566638330027,
2.396266685960279,
2.851185250219491,
2.508278207018142,
2.641897738523063,
2.5548319126520447,
3.1944588028533034,
2.8390092388634454,
2.6397133026611677,
3.177891014483622,
2.446619217081851,
2.266494595902565,
2.821831859595888,
3.237127402287275,
2.7605951374363995,
2.6665078573395964,
2.495256712470534,
3.373093958627006,
3.2104318555864193,
2.9016299618185952,
3.0918969925727504
]
},
{
"line": {
"color": "red",
"width": 2
},
"mode": "lines",
"name": "Producer/Merchant/Processor/User Shorts",
"type": "scatter",
"x": [
"2022-01-04T00:00:00",
"2022-01-11T00:00:00",
"2022-01-18T00:00:00",
"2022-01-25T00:00:00",
"2022-02-01T00:00:00",
"2022-02-08T00:00:00",
"2022-02-15T00:00:00",
"2022-02-22T00:00:00",
"2022-03-01T00:00:00",
"2022-03-08T00:00:00",
"2022-03-15T00:00:00",
"2022-03-22T00:00:00",
"2022-03-29T00:00:00",
"2022-04-05T00:00:00",
"2022-04-12T00:00:00",
"2022-04-19T00:00:00",
"2022-04-26T00:00:00",
"2022-05-03T00:00:00",
"2022-05-10T00:00:00",
"2022-05-17T00:00:00",
"2022-05-24T00:00:00",
"2022-05-31T00:00:00",
"2022-06-07T00:00:00",
"2022-06-14T00:00:00",
"2022-06-21T00:00:00",
"2022-06-28T00:00:00",
"2022-07-05T00:00:00",
"2022-07-12T00:00:00",
"2022-07-19T00:00:00",
"2022-07-26T00:00:00",
"2022-08-02T00:00:00",
"2022-08-09T00:00:00",
"2022-08-16T00:00:00",
"2022-08-23T00:00:00",
"2022-08-30T00:00:00",
"2022-09-06T00:00:00",
"2022-09-13T00:00:00",
"2022-09-20T00:00:00",
"2022-09-27T00:00:00",
"2022-10-04T00:00:00",
"2022-10-11T00:00:00",
"2022-10-18T00:00:00",
"2022-10-25T00:00:00",
"2022-11-01T00:00:00",
"2022-11-08T00:00:00",
"2022-11-15T00:00:00",
"2022-11-22T00:00:00",
"2022-11-29T00:00:00",
"2022-12-06T00:00:00",
"2022-12-13T00:00:00",
"2022-12-20T00:00:00",
"2022-12-27T00:00:00",
"2023-01-03T00:00:00",
"2023-01-10T00:00:00",
"2023-01-17T00:00:00",
"2023-01-24T00:00:00",
"2023-01-31T00:00:00",
"2023-02-07T00:00:00",
"2023-02-14T00:00:00",
"2023-02-21T00:00:00",
"2023-02-28T00:00:00",
"2023-03-07T00:00:00",
"2023-03-14T00:00:00",
"2023-03-21T00:00:00",
"2023-03-28T00:00:00",
"2023-04-04T00:00:00",
"2023-04-11T00:00:00",
"2023-04-18T00:00:00",
"2023-04-25T00:00:00",
"2023-05-02T00:00:00",
"2023-05-09T00:00:00",
"2023-05-16T00:00:00",
"2023-05-23T00:00:00",
"2023-05-30T00:00:00",
"2023-06-06T00:00:00",
"2023-06-13T00:00:00",
"2023-06-20T00:00:00",
"2023-06-27T00:00:00",
"2023-07-03T00:00:00",
"2023-07-11T00:00:00",
"2023-07-18T00:00:00",
"2023-07-25T00:00:00",
"2023-08-01T00:00:00",
"2023-08-08T00:00:00",
"2023-08-15T00:00:00",
"2023-08-22T00:00:00",
"2023-08-29T00:00:00",
"2023-09-05T00:00:00",
"2023-09-12T00:00:00",
"2023-09-19T00:00:00",
"2023-09-26T00:00:00",
"2023-10-03T00:00:00",
"2023-10-10T00:00:00",
"2023-10-17T00:00:00",
"2023-10-24T00:00:00",
"2023-10-31T00:00:00",
"2023-11-07T00:00:00",
"2023-11-14T00:00:00",
"2023-11-21T00:00:00",
"2023-11-28T00:00:00",
"2023-12-05T00:00:00",
"2023-12-12T00:00:00",
"2023-12-19T00:00:00",
"2023-12-26T00:00:00"
],
"y": [
30.997484249682845,
30.000969247171877,
32.266349328008495,
32.465624361736474,
30.115465078854196,
29.418709585490472,
27.899317058253914,
28.5798039634798,
31.69749223271979,
32.77455239091292,
30.94860594970264,
31.228128859613008,
31.708624550451248,
30.30513176144244,
29.910019960582574,
27.617439631368825,
29.991479888414023,
28.256543590041545,
25.294216543375924,
25.15117550195802,
24.967908450319552,
25.594530926470288,
26.587724385342632,
24.560133703562357,
25.308208811469772,
23.29515742957098,
19.99245352868727,
19.86728431944552,
19.31950401729468,
18.784171493531097,
20.246281197942277,
21.301552876471547,
21.663871835026402,
20.409124600816035,
18.723416526089654,
18.07519884309472,
19.243709879731423,
21.008727773698592,
21.51937984496124,
24.500478675766654,
24.52098739880436,
20.679872110543528,
20.59172448502714,
21.912511251125114,
24.833911291183945,
24.304668027085995,
27.468640182457122,
28.93169935179535,
29.01728161360336,
31.53199792919438,
31.61404105880351,
32.21527707504651,
31.43419956057277,
29.698140211294156,
31.164399144560225,
28.692874401506057,
28.803801450858145,
25.468372242722737,
24.845608936518026,
23.13366584346198,
20.488297013720743,
18.606621020681864,
20.854547843510822,
22.57100149476831,
25.34009114527876,
25.85930950384879,
24.188676865289878,
22.092428538053053,
22.321834166154503,
24.099538368715713,
23.118017119873493,
21.733421816910354,
21.255341093266537,
21.200577762144604,
20.6569909553133,
19.890414876537992,
20.346189880301115,
23.877853446809887,
25.615053180797233,
25.42774479972066,
26.60915274779897,
24.220207218614277,
23.112572673410202,
23.56591174953317,
23.553159931990013,
24.551507170032192,
26.557673360840933,
27.213339673680025,
25.948185039747152,
25.303580942989605,
25.177883777316453,
25.33234800988502,
25.649163982326673,
27.558233581365254,
28.23761897080174,
26.63079123501569,
25.823014655955078,
24.92842626793052,
27.52488219573746,
28.97933076525039,
29.580760341459577,
28.93112205002942,
31.136269198504102,
31.208906611469622
]
}
],
"layout": {
"height": 600,
"hovermode": "x unified",
"legend": {
"title": {
"text": "Producer Categories"
}
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "COT Data: Percentage of Open Interest for Producers"
},
"width": 1200,
"xaxis": {
"autorange": true,
"dtick": "M1",
"range": [
"2022-01-04",
"2023-12-26"
],
"tickangle": 45,
"tickformat": "%d %b %Y",
"ticklabelmode": "period",
"title": {
"text": "Date"
},
"type": "date"
},
"yaxis": {
"autorange": true,
"range": [
-1.1437602420799753,
34.559726740017815
],
"ticksuffix": "%",
"title": {
"text": "Percentage of Open Interest"
},
"type": "linear"
}
}
},
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJUAAAJYCAYAAADbkteOAAAAAXNSR0IArs4c6QAAIABJREFUeF7snQdYFFfbhh+kK0VAEEssscRorDHW2I3GFnvvNfbeS9TYe6+xG2ONPbbYTdTEHo3G2BKjghQBQREQ+P/3+M264C7sugiKz7mu7/ri7syZM/ecGZib932PVWxsbCzYSIAESIAESIAESIAESIAESIAESIAESIAESMAMAlaUSmbQ4qYkQAIkQAIkQAIkQAIkQAIkQAIkQAIkQAKKAKUSJwIJkAAJkAAJkAAJkAAJkAAJkAAJkAAJkIDZBCiVzEbGHUiABEiABEiABEiABEiABEiABEiABEiABCiVOAdIgARIgARIgARIgARIgARIgARIgARIgATMJkCpZDYy7kACJEACJEACJEACJEACJEACJEACJEACJECpxDlAAiRAAiRAAiRAAiRAAiRAAiRAAiRAAiRgNgFKJbORcQcSIAESIAESIAESIAESIAESIAESIAESIAFKJc4BEiABEiABEiABEiABEiABEiABEiABEiABswlQKpmNjDuQAAmQAAmQAAmQAAmQAAmQAAmQAAmQAAlQKnEOkAAJkAAJkAAJkAAJkAAJkAAJkAAJkAAJmE2AUslsZNyBBEiABEiABEiABEiABEiABEiABEiABEiAUolzgARIgARIgARIgARIgARIgARIgARIgARIwGwClEpmI+MOJEACJEACJEACJEACJEACJEACJEACJEAClEqcAyRAAiRAAiRAAiRAAiRAAiRAAiRAAiRAAmYToFQyGxl3IAESIAESIAESIAESIAESIAESIAESIAESoFTiHCABEiABEiABEiABEiABEiABEiABEiABEjCbAKWS2ci4AwmQAAmQAAmQAAmQAAmQAAmQAAmQAAmQAKUS5wAJkAAJkAAJkAAJkAAJkAAJkAAJkAAJkIDZBCiVzEbGHUiABEiABEiABEiABEiABEiABEiABEiABCiVOAdIgARIgARIgARIgARIgARIgARIgARIgATMJkCpZDYy7kACJEACJEACJEACJEACJEACJEACJEACJECpxDlAAiRAAiRAAiRAAiRAAiRAAiRAAiRAAiRgNgFKJbORcQcSIAESIAESIAESIAESIAESIAESIAESIAFKJc4BEiABEiABEiABEiABEiABEiABEiABEiABswlQKpmNjDuQAAmQAAmQAAmQAAmQAAmQAAmQAAmQAAlQKnEOkAAJkAAJkAAJkAAJkAAJkAAJkAAJkAAJmE2AUslsZNyBBEiABEiABEiABEiABEiABEiABEiABEiAUolzgARIgARIgARIgARIgARIgARIgARIgARIwGwClEpmI+MOJEACJEACJEACJEACJEACJEACJEACJEAClE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JMy+qFAc7ZvWgIebSxx8l6/dVqlEMi5p1St+pup9SYSQyEatSUTQ2s0HsO/I77rrWr5UIfTu2NDkFElJt9yy65huf0mN7NOpkW6+z1yyCeu3H45zXrlyZMbArk0NXnJ52a7SpL+6Nj8sHIXC+XO9sp2kkvYfswDFCubF2nnD43Du0qo2dh44iWOnLiI0LByli+fHyD5t4ogpc+dIj/b1sGDldhUZJ+3LSiUwuHszkxkZk0raHEyof5kPfb+Zr66l3Jda2qmjgz1mjulu8jz88/o/mL9yG5rVrayivnb/fBI3bt9D6eKfoEX9KqofiYxcs3k/Lv91R/27VLGPMbBbszi1r0SCLF+/B7/+flndZ3JfyP0l/cp1TWys8S/m9Vv/YcyMVer5of9c6dOpIfLlzgaJYlq4ajsO/XJO3WMS8SmyXO4xLcX4WUQk+o2W+ZBHRX1u/ek4Lv91W12fsQPbG320mPpM0e7hUX1bqzEcOXkB930
"text/html": [
"<div> <div id=\"ed83f0aa-b86f-4112-bc29-1408f880e2df\" class=\"plotly-graph-div\" style=\"height:600px; width:1200px;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"ed83f0aa-b86f-4112-bc29-1408f880e2df\")) { Plotly.newPlot( \"ed83f0aa-b86f-4112-bc29-1408f880e2df\", [{\"line\":{\"color\":\"blue\",\"width\":2},\"mode\":\"lines\",\"name\":\"Producer\\u002fMerchant\\u002fProcessor\\u002fUser Longs\",\"x\":[\"2022-01-04T00:00:00\",\"2022-01-11T00:00:00\",\"2022-01-18T00:00:00\",\"2022-01-25T00:00:00\",\"2022-02-01T00:00:00\",\"2022-02-08T00:00:00\",\"2022-02-15T00:00:00\",\"2022-02-22T00:00:00\",\"2022-03-01T00:00:00\",\"2022-03-08T00:00:00\",\"2022-03-15T00:00:00\",\"2022-03-22T00:00:00\",\"2022-03-29T00:00:00\",\"2022-04-05T00:00:00\",\"2022-04-12T00:00:00\",\"2022-04-19T00:00:00\",\"2022-04-26T00:00:00\",\"2022-05-03T00:00:00\",\"2022-05-10T00:00:00\",\"2022-05-17T00:00:00\",\"2022-05-24T00:00:00\",\"2022-05-31T00:00:00\",\"2022-06-07T00:00:00\",\"2022-06-14T00:00:00\",\"2022-06-21T00:00:00\",\"2022-06-28T00:00:00\",\"2022-07-05T00:00:00\",\"2022-07-12T00:00:00\",\"2022-07-19T00:00:00\",\"2022-07-26T00:00:00\",\"2022-08-02T00:00:00\",\"2022-08-09T00:00:00\",\"2022-08-16T00:00:00\",\"2022-08-23T00:00:00\",\"2022-08-30T00:00:00\",\"2022-09-06T00:00:00\",\"2022-09-13T00:00:00\",\"2022-09-20T00:00:00\",\"2022-09-27T00:00:00\",\"2022-10-04T00:00:00\",\"2022-10-11T00:00:00\",\"2022-10-18T00:00:00\",\"2022-10-25T00:00:00\",\"2022-11-01T00:00:00\",\"2022-11-08T00:00:00\",\"2022-11-15T00:00:00\",\"2022-11-22T00:00:00\",\"2022-11-29T00:00:00\",\"2022-12-06T00:00:00\",\"2022-12-13T00:00:00\",\"2022-12-20T00:00:00\",\"2022-12-27T00:00:00\",\"2023-01-03T00:00:00\",\"2023-01-10T00:00:00\",\"2023-01-17T00:00:00\",\"2023-01-24T00:00:00\",\"2023-01-31T00:00:00\",\"2023-02-07T00:00:00\",\"2023-02-14T00:00:00\",\"2023-02-21T00:00:00\",\"2023-02-28T00:00:00\",\"2023-03-07T00:00:00\",\"2023-03-14T00:00:00\",\"2023-03-21T00:00:00\",\"2023-03-28T00:00:00\",\"2023-04-04T00:00:00\",\"2023-04-11T00:00:00\",\"2023-04-18T00:00:00\",\"2023-04-25T00:00:00\",\"2023-05-02T00:00:00\",\"2023-05-09T00:00:00\",\"2023-05-16T00:00:00\",\"2023-05-23T00:00:00\",\"2023-05-30T00:00:00\",\"2023-06-06T00:00:00\",\"2023-06-13T00:00:00\",\"2023-06-20T00:00:00\",\"2023-06-27T00:00:00\",\"2023-07-03T00:00:00\",\"2023-07-11T00:00:00\",\"2023-07-18T00:00:00\",\"2023-07-25T00:00:00\",\"2023-08-01T00:00:00\",\"2023-08-08T00:00:00\",\"2023-08-15T00:00:00\",\"2023-08-22T00:00:00\",\"2023-08-29T00:00:00\",\"2023-09-05T00:00:00\",\"2023-09-12T00:00:00\",\"2023-09-19T00:00:00\",\"2023-09-26T00:00:00\",\"2023-10-03T00:00:00\",\"2023-10-10T00:00:00\",\"2023-10-17T00:00:00\",\"2023-10-24T00:00:00\",\"2023-10-31T00:00:00\",\"2023-11-07T00:00:00\",\"2023-11-14T00:00:00\",\"2023-11-21T00:00:00\",\"2023-11-28T00:00:00\",\"2023-12-05T00:00:00\",\"2023-12-12T00:00:00\",\"2023-12-19T00:00:00\",\"2023-12-26T00:00:00\"],\"y\":[3.9176898101361086,3.980144279364728,3.738814148463395,3.4306458732762763,4.5180238171869975,4.403612454963055,3.79121859232455,2.99428990198174,2.3406675095780574,2.8250031197447156,2.35757123788157,2.318984149855908,2.542579900929633,2.878283936819143,2.694363811526764,2.0260644752809585,2.9992166994187084,3.0481073700723353,3.7806825823806323,4.5428757247429665,4.836264816736768,4.6340486486853445,4.295521059516905,5.405387621892642,3.6524120091361896,5.263855643527895,6.423043790891551,6.67163413211115,6.5667449241636655,7.136767173712986,5.343920391584169,5.026471901511769,5.881619246919911,6.719452468532873,5.837911097654166,5.9768618944323935,4.1857891241791485,3.479755047045198,3.272093023255814,2.2605849109045426,3.003430900392444,4.959758921024586,3.8357838731710823,3.266966696669667,2.7450030974743123,2.3004737930985786,2.3435500011636297,2.5870458031635026,2.81009807601298
" \n",
"var gd = document.getElementById('ed83f0aa-b86f-4112-bc29-1408f880e2df');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" }) }; }); </script> </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Metrics for Producer/Merchant/Processor/User Longs:\n",
"Volatility (Standard Deviation): 1.36%\n",
"Average: 3.23%\n",
"Median: 3.00%\n",
"Minimum: 0.64%\n",
"Maximum: 7.14%\n",
"Typical Range: 2.37% to 3.78%\n",
"\n",
"Metrics for Producer/Merchant/Processor/User Shorts:\n",
"Volatility (Standard Deviation): 3.96%\n",
"Average: 25.57%\n",
"Median: 25.32%\n",
"Minimum: 18.08%\n",
"Maximum: 32.77%\n",
"Typical Range: 22.26% to 28.93%\n",
"\n",
"Correlation between Longs and Shorts: -0.22\n"
]
}
],
"source": [
"import pandas as pd\n",
"import plotly.graph_objects as go\n",
"import numpy as np\n",
"\n",
"# Assuming df is your DataFrame with the COT data\n",
"# If not, you'll need to load your data here\n",
"\n",
"# Calculate percentages for producers\n",
"categories = [\n",
" 'Producer/Merchant/Processor/User Longs',\n",
" 'Producer/Merchant/Processor/User Shorts'\n",
"]\n",
"\n",
"for category in categories:\n",
" df[f'{category} %'] = df[category] / df['Open Interest'] * 100\n",
"\n",
"# Create the main figure\n",
"fig = go.Figure()\n",
"\n",
"# Add traces for each category\n",
"colors = ['blue', 'red']\n",
"for i, category in enumerate(categories):\n",
" fig.add_trace(go.Scatter(\n",
" x=df.index, \n",
" y=df[f'{category} %'], \n",
" mode='lines',\n",
" name=category,\n",
" line=dict(width=2, color=colors[i])\n",
" ))\n",
"\n",
"# Update layout\n",
"fig.update_layout(\n",
" title='COT Data: Percentage of Open Interest for Producers',\n",
" yaxis_title='Percentage of Open Interest',\n",
" xaxis_title='Date',\n",
" legend_title='Producer Categories',\n",
" height=600,\n",
" width=1200,\n",
" hovermode='x unified'\n",
")\n",
"\n",
"# Improve date labeling for better readability\n",
"fig.update_xaxes(\n",
" tickformat=\"%d %b %Y\",\n",
" tickangle=45,\n",
" dtick=\"M1\",\n",
" ticklabelmode=\"period\"\n",
")\n",
"\n",
"# Set y-axis to percentage\n",
"fig.update_yaxes(ticksuffix='%')\n",
"\n",
"# Show the plot\n",
"fig.show()\n",
"\n",
"# Calculate and print metrics\n",
"for category in categories:\n",
" print(f\"\\nMetrics for {category}:\")\n",
" data = df[f'{category} %']\n",
" \n",
" print(f\"Volatility (Standard Deviation): {data.std():.2f}%\")\n",
" print(f\"Average: {data.mean():.2f}%\")\n",
" print(f\"Median: {data.median():.2f}%\")\n",
" print(f\"Minimum: {data.min():.2f}%\")\n",
" print(f\"Maximum: {data.max():.2f}%\")\n",
" \n",
" # Calculate typical range\n",
" typical_low = np.percentile(data, 25)\n",
" typical_high = np.percentile(data, 75)\n",
" print(f\"Typical Range: {typical_low:.2f}% to {typical_high:.2f}%\")\n",
"\n",
"# Calculate and print the correlation between longs and shorts\n",
"correlation = df[f'{categories[0]} %'].corr(df[f'{categories[1]} %'])\n",
"print(f\"\\nCorrelation between Longs and Shorts: {correlation:.2f}\")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "a7f6c187-39dc-4950-9e3f-0a328825c443",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"line": {
"color": "blue",
"width": 2
},
"mode": "lines",
"name": "Open Interest",
"type": "scatter",
"x": [
"2023-08-01T00:00:00",
"2023-08-08T00:00:00",
"2023-08-15T00:00:00",
"2023-08-22T00:00:00",
"2023-08-29T00:00:00",
"2023-09-05T00:00:00",
"2023-09-12T00:00:00",
"2023-09-19T00:00:00",
"2023-09-26T00:00:00",
"2023-10-03T00:00:00",
"2023-10-10T00:00:00",
"2023-10-17T00:00:00",
"2023-10-24T00:00:00",
"2023-10-31T00:00:00",
"2023-11-07T00:00:00",
"2023-11-14T00:00:00",
"2023-11-21T00:00:00",
"2023-11-28T00:00:00",
"2023-12-05T00:00:00",
"2023-12-12T00:00:00",
"2023-12-19T00:00:00",
"2023-12-26T00:00:00",
"2024-01-02T00:00:00"
],
"y": [
144138,
137631,
138215,
136680,
134993,
128279,
125292,
125749,
126206,
125847,
126971,
123640,
123980,
126549,
131073,
134826,
134333,
139144,
139753,
134281,
127549,
131408,
134725
]
}
],
"layout": {
"height": 600,
"hovermode": "x unified",
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "COT Data: Open Interest Over Time (Silver)"
},
"width": 800,
"xaxis": {
"autorange": true,
"dtick": "M1",
"range": [
"2023-08-01",
"2024-01-02"
],
"tickangle": 45,
"tickformat": "%d %b %Y",
"ticklabelmode": "period",
"title": {
"text": "Date"
},
"type": "date"
},
"yaxis": {
"autorange": true,
"range": [
122501.22222222222,
145276.77777777778
],
"title": {
"text": "Open Interest"
},
"type": "linear"
}
}
},
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJUAAAJYCAYAAADbkteOAAAAAXNSR0IArs4c6QAAIABJREFUeF7s3QeYFFXa9vG7wwRQRDEiJnQVA6IoIOaccxYzmBBFFBFQJAooKIKwoJjALGDWFTFgxAAIimHVfc05YUBh8nzfU7M9OwMTuqe6uquq/3Vd7+W7TJ1T5/yemoG+59SpSGVlZaU4EEAAAQQQQAABBBBAAAEEEEAAAQQQSEEgQqiUghanIoAAAggggAACCCCAAAIIIIAAAgg4AoRK3AgIIIAAAggggAACCCCAAAIIIIAAAikLECqlTEYDBBBAAAEEEEAAAQQQQAABBBBAAAFCJe4BBBBAAAEEEEAAAQQQQAABBBBAAIGUBQiVUiajAQIIIIAAAggggAACCCCAAAIIIIAAoRL3AAIIIIAAAggggAACCCCAAAIIIIBAygKESimT0QABBBBAAAEEEEAAAQQQQAABBBBAgFCJewABBBBAAAEEEEAAAQQQQAABBBBAIGUBQqWUyWiAAAIIIIAAAggggAACCCCAAAIIIECoxD2AAAIIIIAAAggggAACCCCAAAIIIJCyAKFSymQ0QAABBBBAAAEEEEAAAQQQQAABBBAgVOIeQAABBBBAAAEEEEAAAQQQQAABBBBIWYBQKWUyGiCAAAIIIIAAAggggAACCCCAAAIIECpxDyCAAAIIIIAAAggggAACCCCAAAIIpCxAqJQyGQ0QQAABBBBAAAEEEEAAAQQQQAABBAiVuAcQQAABBBBAAAEEEEAAAQQQQAABBFIWIFRKmYwGCCCA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utO2SXul40R7DCjVFVJWi7tnzdH9UwZrh223SHkYqYRKTRlfygNqpEGqoZKFR4efPlDffP+zrr70DHU7Zv/qK1RUVGriHQ/rtvue0k7bb6V7Jl2V7uGmrb/+19yif73wpmbfN0abtFk/bf163ZH5Tr3nSefnXNed//f99H+ff6ujuw9yvg/vnzJklZ8htiLzzUUfysLy+o50hUpu7mv7RcA+x1+qXTpu4/zMSPX712t/+kcAAQQQQAABBBBAIBcEci5UOuz0Afrymx91y5i+2nOXDnXW2FYGtVitmfNh+JBT+zuh0UsPT6hz745RN92j+x99QRd1P1a9zjq6Vn/pDpWscwsiLrpqguYteL/WNZd8+KluvvsJZ9WPjdvGvP3WbXXGiQdp3906OuOyc0bddK/e//hzZ7XT5ptu6Py5Pb533mlHOF9vrI+aE7RAray8QoP6nO7019BhHx73P6mvExrVF8LYh9m+wybXChk++PgL/XPao04w98XXP+iZF9/SJ599o47tt9TlPU9y/lvzMPObbn9Ii9/7j7O6zL5+4VlHO4/0JI5HZ78qe/yxd49j9eRzb2jua4scs107badBl5y+StBY37zqC5Xsz22eF3U/RpOnPSYLMu04ZN8u6t/rFOfRRVuVdemQfzp1tFolHkVsVligG4f1cs63UOaeWc/qmRfnV9dsr64ddMk5x1c//lhUXKLLhprZls5quUf+9Yre++gz5+v2uJMdyZj8svQP3fHA05o3/z3nfHucz+xOOXo/ZxWR3eePPTPPGfdeXXeoJrGwaOV9ehJftJV7A0ZNdexvvb7fKowWLB3TfZBzvTvHD3DCAXsc0B4vHHzpGdpwpf1/7BGs5155W73OPsa5t+2wlYAW7L330efO/+660zbqd+EpzvgTR6IeYwdf4KwuXPjux1r293INvvRMrbv2/4LN+urcUKhk34+XDJ7khIo9zzzK6SJxf1n9H336Vb34+mIt+2uFDtq7k/O9Yj9fJt3xiF55810VFZc6q4Js5eLKKw+TqVt
"text/html": [
"<div> <div id=\"027bacce-a366-44ec-9a84-88a9bb2851f9\" class=\"plotly-graph-div\" style=\"height:600px; width:800px;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"027bacce-a366-44ec-9a84-88a9bb2851f9\")) { Plotly.newPlot( \"027bacce-a366-44ec-9a84-88a9bb2851f9\", [{\"line\":{\"color\":\"blue\",\"width\":2},\"mode\":\"lines\",\"name\":\"Open Interest\",\"x\":[\"2023-08-01T00:00:00\",\"2023-08-08T00:00:00\",\"2023-08-15T00:00:00\",\"2023-08-22T00:00:00\",\"2023-08-29T00:00:00\",\"2023-09-05T00:00:00\",\"2023-09-12T00:00:00\",\"2023-09-19T00:00:00\",\"2023-09-26T00:00:00\",\"2023-10-03T00:00:00\",\"2023-10-10T00:00:00\",\"2023-10-17T00:00:00\",\"2023-10-24T00:00:00\",\"2023-10-31T00:00:00\",\"2023-11-07T00:00:00\",\"2023-11-14T00:00:00\",\"2023-11-21T00:00:00\",\"2023-11-28T00:00:00\",\"2023-12-05T00:00:00\",\"2023-12-12T00:00:00\",\"2023-12-19T00:00:00\",\"2023-12-26T00:00:00\",\"2024-01-02T00:00:00\"],\"y\":[144138.0,137631.0,138215.0,136680.0,134993.0,128279.0,125292.0,125749.0,126206.0,125847.0,126971.0,123640.0,123980.0,126549.0,131073.0,134826.0,134333.0,139144.0,139753.0,134281.0,127549.0,131408.0,134725.0],\"type\":\"scatter\"}], {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.88888888888888
" \n",
"var gd = document.getElementById('027bacce-a366-44ec-9a84-88a9bb2851f9');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" }) }; }); </script> </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Metrics for Open Interest:\n",
"Volatility (Standard Deviation): 5894.28\n",
"Average: 131794.00\n",
"Median: 131408.00\n",
"Minimum: 123640.00\n",
"Maximum: 144138.00\n",
"Typical Range: 126377.50 to 135836.50\n",
"\n",
"Overall trend: Downward\n",
"\n",
"Significant points:\n",
"Peak on 2023-10-10 00:00:00: 126971.00\n",
"Peak on 2023-12-05 00:00:00: 139753.00\n",
"Trough on 2023-09-12 00:00:00: 125292.00\n",
"Trough on 2023-10-17 00:00:00: 123640.00\n",
"Trough on 2023-12-19 00:00:00: 127549.00\n",
"\n",
"Sudden changes (>5% day-to-day):\n",
"2023-12-19 00:00:00: -5.01% change\n"
]
}
],
"source": [
"import pandas as pd\n",
"import plotly.graph_objects as go\n",
"import numpy as np\n",
"from scipy import signal\n",
"\n",
"# Assuming df is your DataFrame with the COT data\n",
"# If not, you'll need to load your data here\n",
"\n",
"# Create the main figure\n",
"fig = go.Figure()\n",
"\n",
"# Add trace for Open Interest\n",
"fig.add_trace(go.Scatter(\n",
" x=df.index, \n",
" y=df['Open Interest'], \n",
" mode='lines',\n",
" name='Open Interest',\n",
" line=dict(width=2, color='blue')\n",
"))\n",
"\n",
"# Update layout\n",
"fig.update_layout(\n",
" title='COT Data: Open Interest Over Time (Silver)',\n",
" yaxis_title='Open Interest',\n",
" xaxis_title='Date',\n",
" height=600,\n",
" width=800,\n",
" hovermode='x unified'\n",
")\n",
"\n",
"# Improve date labeling for better readability\n",
"fig.update_xaxes(\n",
" tickformat=\"%d %b %Y\",\n",
" tickangle=45,\n",
" dtick=\"M1\",\n",
" ticklabelmode=\"period\"\n",
")\n",
"\n",
"# Show the plot\n",
"fig.show()\n",
"\n",
"# Calculate and print metrics\n",
"print(\"\\nMetrics for Open Interest:\")\n",
"data = df['Open Interest']\n",
"\n",
"print(f\"Volatility (Standard Deviation): {data.std():.2f}\")\n",
"print(f\"Average: {data.mean():.2f}\")\n",
"print(f\"Median: {data.median():.2f}\")\n",
"print(f\"Minimum: {data.min():.2f}\")\n",
"print(f\"Maximum: {data.max():.2f}\")\n",
"\n",
"# Calculate typical range\n",
"typical_low = np.percentile(data, 25)\n",
"typical_high = np.percentile(data, 75)\n",
"print(f\"Typical Range: {typical_low:.2f} to {typical_high:.2f}\")\n",
"\n",
"# Identify trends\n",
"def identify_trend(series):\n",
" # Calculate the overall trend\n",
" trend = np.polyfit(range(len(series)), series, 1)[0]\n",
" if trend > 0:\n",
" return \"Upward\"\n",
" elif trend < 0:\n",
" return \"Downward\"\n",
" else:\n",
" return \"Stable\"\n",
"\n",
"trend = identify_trend(data)\n",
"print(f\"\\nOverall trend: {trend}\")\n",
"\n",
"# Identify significant points\n",
"def find_peaks(series, prominence=1000):\n",
" peaks, _ = signal.find_peaks(series, prominence=prominence)\n",
" troughs, _ = signal.find_peaks(-series, prominence=prominence)\n",
" return peaks, troughs\n",
"\n",
"peaks, troughs = find_peaks(data)\n",
"\n",
"print(\"\\nSignificant points:\")\n",
"for peak in peaks:\n",
" print(f\"Peak on {df.index[peak]}: {data.iloc[peak]:.2f}\")\n",
"for trough in troughs:\n",
" print(f\"Trough on {df.index[trough]}: {data.iloc[trough]:.2f}\")\n",
"\n",
"# Identify sudden changes\n",
"pct_change = data.pct_change()\n",
"sudden_changes = pct_change[abs(pct_change) > 0.05] # 5% threshold\n",
"if not sudden_changes.empty:\n",
" print(\"\\nSudden changes (>5% day-to-day):\")\n",
" for date, change in sudden_changes.items():\n",
" print(f\"{date}: {change*100:.2f}% change\")\n",
"else:\n",
" print(\"\\nNo sudden changes above 5% threshold detected.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10913a96-3d9a-4224-8984-6fb9abf31e72",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}