mirror of
https://github.com/norandom/trading_analysis.git
synced 2024-11-24 22:13:43 +00:00
2242 lines
273 KiB
Plaintext
2242 lines
273 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "c1ed63c850198a27",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# DL of CTFC COT\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"* go to [CFTC legacy reports](https://www.cftc.gov/MarketReports/CommitmentsofTraders/index.htm) for the respective commodity\n",
|
|||
|
"* [Data source](https://www.cftc.gov/MarketReports/CommitmentsofTraders/HistoricalCompressed/index.htm)\n",
|
|||
|
"\n",
|
|||
|
"## Example \"Metals and other\" \n",
|
|||
|
"\n",
|
|||
|
"-> Short Format -> [Report](https://www.cftc.gov/dea/futures/other_sf.htm)\n",
|
|||
|
"\n",
|
|||
|
"```\n",
|
|||
|
"Disaggregated Commitments of Traders-All Futures Combined Positions as of March 5, 2024 \n",
|
|||
|
": Reportable Positions :\n",
|
|||
|
":------------------------------------------------------------------------------------------------------------- :\n",
|
|||
|
": Producer/Merchant : : : :\n",
|
|||
|
": Processor/User : Swap Dealers : Managed Money : Other Reportables :\n",
|
|||
|
": Long : Short : Long : Short :Spreading: Long : Short :Spreading: Long : Short :Spreading :\n",
|
|||
|
"----------------------------------------------------------------------------------------------------------------\n",
|
|||
|
"COPPER- #1 - COMMODITY EXCHANGE INC. (CONTRACTS OF 25,000 POUNDS) :\n",
|
|||
|
"CFTC Code #085692 Open Interest is 198,561 :\n",
|
|||
|
": Positions :\n",
|
|||
|
": 25,549 55,033 40,929 8,737 4,060 51,724 60,287 29,969 19,246 16,010 11,212 :\n",
|
|||
|
": :\n",
|
|||
|
"`: Changes from: February 27, 2024 :`\n",
|
|||
|
": 1,596 -1,200 -506 -138 -166 -2,788 10,821 5,613 4,085 -5,800 1,264 :\n",
|
|||
|
": :\n",
|
|||
|
": Percent of Open Interest Represented by Each Category of Trader :\n",
|
|||
|
": 12.9 27.7 20.6 4.4 2.0 26.0 30.4 15.1 9.7 8.1 5.6 :\n",
|
|||
|
": :\n",
|
|||
|
": Number of Traders in Each Category Total Traders: 310 :\n",
|
|||
|
": 33 42 20 12 16 66 58 55 54 45 35 :\n",
|
|||
|
"----------------------------------------------------------------------------------------------------------------\n",
|
|||
|
"```\n",
|
|||
|
"\n",
|
|||
|
"## Long / Short positions most notably per \n",
|
|||
|
"\n",
|
|||
|
"* Processor (who produces the commodity, knows the market in adv.)\n",
|
|||
|
"* Swap Dealers (retail investors)\n",
|
|||
|
"* Managed Money (investment banks, market makers)\n",
|
|||
|
"\n",
|
|||
|
"### Here for March 5th '24: \n",
|
|||
|
"\n",
|
|||
|
"Analyse-Compass (basis Ray Dalio)\n",
|
|||
|
"\n",
|
|||
|
"Our target:\n",
|
|||
|
"% Open Interest \n",
|
|||
|
"Bullish / Bearish ranges\n",
|
|||
|
"\n",
|
|||
|
"* Copper\t25-20%\t/ 40-50%\n",
|
|||
|
"\n",
|
|||
|
"-> we want 25-20% Producers long for Bullish\n",
|
|||
|
"-> we want 40-50% Producers short for Bearish\n",
|
|||
|
"\n",
|
|||
|
"Both conditions are not met.\n",
|
|||
|
"\n",
|
|||
|
"12,9\n",
|
|||
|
"27,7%.\n",
|
|||
|
"\n",
|
|||
|
"Therefore, this signal indiction: no trade to set for March '24.\n",
|
|||
|
"\n",
|
|||
|
"### Signal interpretation\n",
|
|||
|
"\n",
|
|||
|
"* Bullish (=rising expectation), means go long (IF at all)\n",
|
|||
|
"* Bearish (=falling expectation), means go short \n",
|
|||
|
"\n",
|
|||
|
"* Copper COT signal interpretation for 5th of March '24\n",
|
|||
|
"\n",
|
|||
|
"12,9% of Producers are long\n",
|
|||
|
"27,7% are short\n",
|
|||
|
"\n",
|
|||
|
"Most producers expect the market to fall.\n",
|
|||
|
"Swap dealers are positioned differently.\n",
|
|||
|
"Market Makers are balanced."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "17e978b957c34cc",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Data-driven analysis\n",
|
|||
|
"\n",
|
|||
|
"The COT data as shown above is pasted in a format, which looks like from the Mainframe era of computing."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 94,
|
|||
|
"id": "afa222d7d5329711",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T10:49:10.777655Z",
|
|||
|
"start_time": "2024-03-09T10:49:07.411783Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Requirement already satisfied: cot_reports==0.1.3 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (0.1.3)\r\n",
|
|||
|
"Requirement already satisfied: pandas in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from cot_reports==0.1.3) (2.2.1)\r\n",
|
|||
|
"Requirement already satisfied: requests in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from cot_reports==0.1.3) (2.31.0)\r\n",
|
|||
|
"Requirement already satisfied: beautifulsoup4 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from cot_reports==0.1.3) (4.12.3)\r\n",
|
|||
|
"Requirement already satisfied: soupsieve>1.2 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from beautifulsoup4->cot_reports==0.1.3) (2.5)\r\n",
|
|||
|
"Requirement already satisfied: numpy<2,>=1.23.2 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from pandas->cot_reports==0.1.3) (1.26.4)\r\n",
|
|||
|
"Requirement already satisfied: python-dateutil>=2.8.2 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from pandas->cot_reports==0.1.3) (2.9.0)\r\n",
|
|||
|
"Requirement already satisfied: pytz>=2020.1 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from pandas->cot_reports==0.1.3) (2024.1)\r\n",
|
|||
|
"Requirement already satisfied: tzdata>=2022.7 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from pandas->cot_reports==0.1.3) (2024.1)\r\n",
|
|||
|
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from requests->cot_reports==0.1.3) (3.3.2)\r\n",
|
|||
|
"Requirement already satisfied: idna<4,>=2.5 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from requests->cot_reports==0.1.3) (3.6)\r\n",
|
|||
|
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from requests->cot_reports==0.1.3) (2.2.1)\r\n",
|
|||
|
"Requirement already satisfied: certifi>=2017.4.17 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from requests->cot_reports==0.1.3) (2024.2.2)\r\n",
|
|||
|
"Requirement already satisfied: six>=1.5 in /home/marius/miniconda3/envs/lang_chain/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->cot_reports==0.1.3) (1.16.0)\r\n",
|
|||
|
"Note: you may need to restart the kernel to use updated packages.\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%pip install cot_reports==\"0.1.3\""
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "dc4d9aade9f5a019",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Analysis of the initial data\n",
|
|||
|
"\n",
|
|||
|
"* different commodities etc. in the disaggregated Futures report\n",
|
|||
|
"* we need to filter this down intelligently"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 116,
|
|||
|
"id": "59275665b54f456",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:06:49.260108Z",
|
|||
|
"start_time": "2024-03-09T11:06:40.871193Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Selected: disaggregated_fut\n",
|
|||
|
"Downloaded single year data from: 2020\n",
|
|||
|
"Stored the file f_year.txt in the working directory.\n",
|
|||
|
"Selected: disaggregated_fut\n",
|
|||
|
"Downloaded single year data from: 2021\n",
|
|||
|
"Stored the file f_year.txt in the working directory.\n",
|
|||
|
"Selected: disaggregated_fut\n",
|
|||
|
"Downloaded single year data from: 2022\n",
|
|||
|
"Stored the file f_year.txt in the working directory.\n",
|
|||
|
"Selected: disaggregated_fut\n",
|
|||
|
"Downloaded single year data from: 2023\n",
|
|||
|
"Stored the file f_year.txt in the working directory.\n",
|
|||
|
"Selected: disaggregated_fut\n",
|
|||
|
"Downloaded single year data from: 2024\n",
|
|||
|
"Stored the file f_year.txt in the working directory.\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import cot_reports as cot # Ensure cot_reports is correctly imported and cot.cot_year() works as expected\n",
|
|||
|
"\n",
|
|||
|
"df = pd.DataFrame()\n",
|
|||
|
"begin_year = 2020\n",
|
|||
|
"end_year = 2024\n",
|
|||
|
"\n",
|
|||
|
"for i in range(begin_year, end_year + 1):\n",
|
|||
|
" # Assuming cot.cot_year returns a DataFrame\n",
|
|||
|
" single_year = pd.DataFrame(cot.cot_year(i, cot_report_type='disaggregated_fut'))\n",
|
|||
|
" single_year.to_csv(f'./COT_CFTC_{i}.csv', index=False)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 117,
|
|||
|
"id": "e6d4d271e1d99abb",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:08:44.322381Z",
|
|||
|
"start_time": "2024-03-09T11:08:44.318455Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"['COT_CFTC_2022.csv', 'COT_CFTC_2023.csv', 'COT_CFTC_2021.csv', 'COT_CFTC_2020.csv', 'COT_CFTC_2024.csv']\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import glob\n",
|
|||
|
"\n",
|
|||
|
"# Adjust the path and pattern according to your CSV files location and naming convention\n",
|
|||
|
"csv_files = glob.glob('COT_CFTC_20*.csv')\n",
|
|||
|
"print(csv_files)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 136,
|
|||
|
"id": "b284835ac41d4a4f",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:22:19.817094Z",
|
|||
|
"start_time": "2024-03-09T11:22:19.742368Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"df = pd.read_csv('COT_CFTC_2024.csv')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 137,
|
|||
|
"id": "7946ebc889c6f8ae",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:22:30.274312Z",
|
|||
|
"start_time": "2024-03-09T11:22:30.218822Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"(2481, 191)"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 137,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"\n",
|
|||
|
"df[\"Report_Date_as_YYYY-MM-DD\"] = pd.to_datetime(df[\"Report_Date_as_YYYY-MM-DD\"], format='%Y-%m-%d')\n",
|
|||
|
"df.set_index(\"Report_Date_as_YYYY-MM-DD\")\n",
|
|||
|
"df.shape"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 138,
|
|||
|
"id": "f81761725b000258",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:22:54.071128Z",
|
|||
|
"start_time": "2024-03-09T11:22:53.921142Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"2482\r\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"!cat COT_CFTC_2024.csv | wc -l"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 140,
|
|||
|
"id": "80c7995f47756134",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:23:33.531638Z",
|
|||
|
"start_time": "2024-03-09T11:23:33.499054Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"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>Market_and_Exchange_Names</th>\n",
|
|||
|
" <th>As_of_Date_In_Form_YYMMDD</th>\n",
|
|||
|
" <th>Report_Date_as_YYYY-MM-DD</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Region_Code</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code</th>\n",
|
|||
|
" <th>Open_Interest_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Long_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Short_All</th>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Short_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Short_Other</th>\n",
|
|||
|
" <th>Contract_Units</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_SubGroup_Code</th>\n",
|
|||
|
" <th>FutOnly_or_Combined</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>WHEAT-SRW - CHICAGO BOARD OF TRADE</td>\n",
|
|||
|
" <td>240305</td>\n",
|
|||
|
" <td>2024-03-05</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>401311</td>\n",
|
|||
|
" <td>50034</td>\n",
|
|||
|
" <td>74289</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>20.5</td>\n",
|
|||
|
" <td>18.7</td>\n",
|
|||
|
" <td>32.4</td>\n",
|
|||
|
" <td>28.2</td>\n",
|
|||
|
" <td>(CONTRACTS OF 5,000 BUSHELS)</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>A10</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>WHEAT-SRW - CHICAGO BOARD OF TRADE</td>\n",
|
|||
|
" <td>240227</td>\n",
|
|||
|
" <td>2024-02-27</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>373389</td>\n",
|
|||
|
" <td>43686</td>\n",
|
|||
|
" <td>75295</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>21.9</td>\n",
|
|||
|
" <td>20.7</td>\n",
|
|||
|
" <td>33.8</td>\n",
|
|||
|
" <td>30.1</td>\n",
|
|||
|
" <td>(CONTRACTS OF 5,000 BUSHELS)</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>A10</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>WHEAT-SRW - CHICAGO BOARD OF TRADE</td>\n",
|
|||
|
" <td>240220</td>\n",
|
|||
|
" <td>2024-02-20</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>396470</td>\n",
|
|||
|
" <td>51309</td>\n",
|
|||
|
" <td>73366</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>23.2</td>\n",
|
|||
|
" <td>25.0</td>\n",
|
|||
|
" <td>35.4</td>\n",
|
|||
|
" <td>35.5</td>\n",
|
|||
|
" <td>(CONTRACTS OF 5,000 BUSHELS)</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>A10</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>WHEAT-SRW - CHICAGO BOARD OF TRADE</td>\n",
|
|||
|
" <td>240213</td>\n",
|
|||
|
" <td>2024-02-13</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>396009</td>\n",
|
|||
|
" <td>48951</td>\n",
|
|||
|
" <td>86037</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>24.1</td>\n",
|
|||
|
" <td>26.7</td>\n",
|
|||
|
" <td>38.3</td>\n",
|
|||
|
" <td>38.6</td>\n",
|
|||
|
" <td>(CONTRACTS OF 5,000 BUSHELS)</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>A10</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>WHEAT-SRW - CHICAGO BOARD OF TRADE</td>\n",
|
|||
|
" <td>240206</td>\n",
|
|||
|
" <td>2024-02-06</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>419546</td>\n",
|
|||
|
" <td>57414</td>\n",
|
|||
|
" <td>84652</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>24.2</td>\n",
|
|||
|
" <td>27.0</td>\n",
|
|||
|
" <td>38.6</td>\n",
|
|||
|
" <td>36.6</td>\n",
|
|||
|
" <td>(CONTRACTS OF 5,000 BUSHELS)</td>\n",
|
|||
|
" <td>001602</td>\n",
|
|||
|
" <td>CBT</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>A10</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>5 rows × 191 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Market_and_Exchange_Names As_of_Date_In_Form_YYMMDD \\\n",
|
|||
|
"0 WHEAT-SRW - CHICAGO BOARD OF TRADE 240305 \n",
|
|||
|
"1 WHEAT-SRW - CHICAGO BOARD OF TRADE 240227 \n",
|
|||
|
"2 WHEAT-SRW - CHICAGO BOARD OF TRADE 240220 \n",
|
|||
|
"3 WHEAT-SRW - CHICAGO BOARD OF TRADE 240213 \n",
|
|||
|
"4 WHEAT-SRW - CHICAGO BOARD OF TRADE 240206 \n",
|
|||
|
"\n",
|
|||
|
" Report_Date_as_YYYY-MM-DD CFTC_Contract_Market_Code CFTC_Market_Code \\\n",
|
|||
|
"0 2024-03-05 001602 CBT \n",
|
|||
|
"1 2024-02-27 001602 CBT \n",
|
|||
|
"2 2024-02-20 001602 CBT \n",
|
|||
|
"3 2024-02-13 001602 CBT \n",
|
|||
|
"4 2024-02-06 001602 CBT \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Region_Code CFTC_Commodity_Code Open_Interest_All \\\n",
|
|||
|
"0 0 1 401311 \n",
|
|||
|
"1 0 1 373389 \n",
|
|||
|
"2 0 1 396470 \n",
|
|||
|
"3 0 1 396009 \n",
|
|||
|
"4 0 1 419546 \n",
|
|||
|
"\n",
|
|||
|
" Prod_Merc_Positions_Long_All Prod_Merc_Positions_Short_All ... \\\n",
|
|||
|
"0 50034 74289 ... \n",
|
|||
|
"1 43686 75295 ... \n",
|
|||
|
"2 51309 73366 ... \n",
|
|||
|
"3 48951 86037 ... \n",
|
|||
|
"4 57414 84652 ... \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_4_TDR_Long_Other Conc_Net_LE_4_TDR_Short_Other \\\n",
|
|||
|
"0 20.5 18.7 \n",
|
|||
|
"1 21.9 20.7 \n",
|
|||
|
"2 23.2 25.0 \n",
|
|||
|
"3 24.1 26.7 \n",
|
|||
|
"4 24.2 27.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_8_TDR_Long_Other Conc_Net_LE_8_TDR_Short_Other \\\n",
|
|||
|
"0 32.4 28.2 \n",
|
|||
|
"1 33.8 30.1 \n",
|
|||
|
"2 35.4 35.5 \n",
|
|||
|
"3 38.3 38.6 \n",
|
|||
|
"4 38.6 36.6 \n",
|
|||
|
"\n",
|
|||
|
" Contract_Units CFTC_Contract_Market_Code_Quotes \\\n",
|
|||
|
"0 (CONTRACTS OF 5,000 BUSHELS) 001602 \n",
|
|||
|
"1 (CONTRACTS OF 5,000 BUSHELS) 001602 \n",
|
|||
|
"2 (CONTRACTS OF 5,000 BUSHELS) 001602 \n",
|
|||
|
"3 (CONTRACTS OF 5,000 BUSHELS) 001602 \n",
|
|||
|
"4 (CONTRACTS OF 5,000 BUSHELS) 001602 \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Market_Code_Quotes CFTC_Commodity_Code_Quotes CFTC_SubGroup_Code \\\n",
|
|||
|
"0 CBT 1 A10 \n",
|
|||
|
"1 CBT 1 A10 \n",
|
|||
|
"2 CBT 1 A10 \n",
|
|||
|
"3 CBT 1 A10 \n",
|
|||
|
"4 CBT 1 A10 \n",
|
|||
|
"\n",
|
|||
|
" FutOnly_or_Combined \n",
|
|||
|
"0 FutOnly \n",
|
|||
|
"1 FutOnly \n",
|
|||
|
"2 FutOnly \n",
|
|||
|
"3 FutOnly \n",
|
|||
|
"4 FutOnly \n",
|
|||
|
"\n",
|
|||
|
"[5 rows x 191 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 140,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "e8cae63ae3b3b510",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"### For Copper\n",
|
|||
|
"\n",
|
|||
|
"* This is not the final version (!)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 154,
|
|||
|
"id": "813a190783166944",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:27:04.071662Z",
|
|||
|
"start_time": "2024-03-09T11:27:04.056034Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"\n",
|
|||
|
"# Filter for rows where \"Market_and_Exchange_Names\" matches either of the specified values\n",
|
|||
|
"copper_df = df[df[\"Market_and_Exchange_Names\"].isin([\"COPPER-GRADE #1 - COMMODITY EXCHANGE INC.\", \"COPPER- #1 - COMMODITY EXCHANGE INC.\"])].copy()\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"# After filtering, you can standardize the \"Market_and_Exchange_Names\" if you want all of them to have the same name\n",
|
|||
|
"# This is optional and based on your specific requirement to 'merge' under a unified label\n",
|
|||
|
"copper_df[\"Market_and_Exchange_Names\"] = \"COPPER-GRADE #1 - COMMODITY EXCHANGE INC.\"\n",
|
|||
|
"\n",
|
|||
|
"copper_df[\"Report_Date_as_YYYY-MM-DD\"] = pd.to_datetime(df[\"Report_Date_as_YYYY-MM-DD\"], format='%Y-%m-%d')\n",
|
|||
|
"copper_df = copper_df.set_index(\"Report_Date_as_YYYY-MM-DD\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 155,
|
|||
|
"id": "e884267fcd65fb7c",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:27:08.228288Z",
|
|||
|
"start_time": "2024-03-09T11:27:08.181704Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"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>Market_and_Exchange_Names</th>\n",
|
|||
|
" <th>As_of_Date_In_Form_YYMMDD</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Region_Code</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code</th>\n",
|
|||
|
" <th>Open_Interest_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Long_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Short_All</th>\n",
|
|||
|
" <th>Swap_Positions_Long_All</th>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Short_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Short_Other</th>\n",
|
|||
|
" <th>Contract_Units</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_SubGroup_Code</th>\n",
|
|||
|
" <th>FutOnly_or_Combined</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>Report_Date_as_YYYY-MM-DD</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",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-03-05</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240305</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>198561</td>\n",
|
|||
|
" <td>25549</td>\n",
|
|||
|
" <td>55033</td>\n",
|
|||
|
" <td>40929</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-27</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240227</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>189805</td>\n",
|
|||
|
" <td>23953</td>\n",
|
|||
|
" <td>56233</td>\n",
|
|||
|
" <td>41435</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-20</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240220</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>229777</td>\n",
|
|||
|
" <td>38874</td>\n",
|
|||
|
" <td>60100</td>\n",
|
|||
|
" <td>44483</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-13</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240213</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>257761</td>\n",
|
|||
|
" <td>47634</td>\n",
|
|||
|
" <td>57264</td>\n",
|
|||
|
" <td>46061</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-06</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240206</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>245784</td>\n",
|
|||
|
" <td>34349</td>\n",
|
|||
|
" <td>61265</td>\n",
|
|||
|
" <td>45534</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>5 rows × 190 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Market_and_Exchange_Names \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-02-27 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-02-20 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-02-13 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-02-06 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"\n",
|
|||
|
" As_of_Date_In_Form_YYMMDD \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 240305 \n",
|
|||
|
"2024-02-27 240227 \n",
|
|||
|
"2024-02-20 240220 \n",
|
|||
|
"2024-02-13 240213 \n",
|
|||
|
"2024-02-06 240206 \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Contract_Market_Code CFTC_Market_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 085692 CMX \n",
|
|||
|
"2024-02-27 085692 CMX \n",
|
|||
|
"2024-02-20 085692 CMX \n",
|
|||
|
"2024-02-13 085692 CMX \n",
|
|||
|
"2024-02-06 085692 CMX \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Region_Code CFTC_Commodity_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 1 85 \n",
|
|||
|
"2024-02-27 1 85 \n",
|
|||
|
"2024-02-20 1 85 \n",
|
|||
|
"2024-02-13 1 85 \n",
|
|||
|
"2024-02-06 1 85 \n",
|
|||
|
"\n",
|
|||
|
" Open_Interest_All Prod_Merc_Positions_Long_All \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 198561 25549 \n",
|
|||
|
"2024-02-27 189805 23953 \n",
|
|||
|
"2024-02-20 229777 38874 \n",
|
|||
|
"2024-02-13 257761 47634 \n",
|
|||
|
"2024-02-06 245784 34349 \n",
|
|||
|
"\n",
|
|||
|
" Prod_Merc_Positions_Short_All \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 55033 \n",
|
|||
|
"2024-02-27 56233 \n",
|
|||
|
"2024-02-20 60100 \n",
|
|||
|
"2024-02-13 57264 \n",
|
|||
|
"2024-02-06 61265 \n",
|
|||
|
"\n",
|
|||
|
" Swap_Positions_Long_All ... \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD ... \n",
|
|||
|
"2024-03-05 40929 ... \n",
|
|||
|
"2024-02-27 41435 ... \n",
|
|||
|
"2024-02-20 44483 ... \n",
|
|||
|
"2024-02-13 46061 ... \n",
|
|||
|
"2024-02-06 45534 ... \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_4_TDR_Long_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 0.0 \n",
|
|||
|
"2024-02-27 0.0 \n",
|
|||
|
"2024-02-20 0.0 \n",
|
|||
|
"2024-02-13 0.0 \n",
|
|||
|
"2024-02-06 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_4_TDR_Short_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 0.0 \n",
|
|||
|
"2024-02-27 0.0 \n",
|
|||
|
"2024-02-20 0.0 \n",
|
|||
|
"2024-02-13 0.0 \n",
|
|||
|
"2024-02-06 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_8_TDR_Long_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 0.0 \n",
|
|||
|
"2024-02-27 0.0 \n",
|
|||
|
"2024-02-20 0.0 \n",
|
|||
|
"2024-02-13 0.0 \n",
|
|||
|
"2024-02-06 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_8_TDR_Short_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 0.0 \n",
|
|||
|
"2024-02-27 0.0 \n",
|
|||
|
"2024-02-20 0.0 \n",
|
|||
|
"2024-02-13 0.0 \n",
|
|||
|
"2024-02-06 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Contract_Units \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-02-27 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-02-20 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-02-13 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-02-06 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Contract_Market_Code_Quotes \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 085692 \n",
|
|||
|
"2024-02-27 085692 \n",
|
|||
|
"2024-02-20 085692 \n",
|
|||
|
"2024-02-13 085692 \n",
|
|||
|
"2024-02-06 085692 \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Market_Code_Quotes \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 CMX \n",
|
|||
|
"2024-02-27 CMX \n",
|
|||
|
"2024-02-20 CMX \n",
|
|||
|
"2024-02-13 CMX \n",
|
|||
|
"2024-02-06 CMX \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Commodity_Code_Quotes CFTC_SubGroup_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 85 N25 \n",
|
|||
|
"2024-02-27 85 N25 \n",
|
|||
|
"2024-02-20 85 N25 \n",
|
|||
|
"2024-02-13 85 N25 \n",
|
|||
|
"2024-02-06 85 N25 \n",
|
|||
|
"\n",
|
|||
|
" FutOnly_or_Combined \n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 FutOnly \n",
|
|||
|
"2024-02-27 FutOnly \n",
|
|||
|
"2024-02-20 FutOnly \n",
|
|||
|
"2024-02-13 FutOnly \n",
|
|||
|
"2024-02-06 FutOnly \n",
|
|||
|
"\n",
|
|||
|
"[5 rows x 190 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 155,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"copper_df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 156,
|
|||
|
"id": "c175c46af208157b",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:27:12.043766Z",
|
|||
|
"start_time": "2024-03-09T11:27:12.003480Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"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>Market_and_Exchange_Names</th>\n",
|
|||
|
" <th>As_of_Date_In_Form_YYMMDD</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Market_Code</th>\n",
|
|||
|
" <th>CFTC_Region_Code</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code</th>\n",
|
|||
|
" <th>Open_Interest_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Long_All</th>\n",
|
|||
|
" <th>Prod_Merc_Positions_Short_All</th>\n",
|
|||
|
" <th>Swap_Positions_Long_All</th>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_4_TDR_Short_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Long_Other</th>\n",
|
|||
|
" <th>Conc_Net_LE_8_TDR_Short_Other</th>\n",
|
|||
|
" <th>Contract_Units</th>\n",
|
|||
|
" <th>CFTC_Contract_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Market_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_Commodity_Code_Quotes</th>\n",
|
|||
|
" <th>CFTC_SubGroup_Code</th>\n",
|
|||
|
" <th>FutOnly_or_Combined</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>Report_Date_as_YYYY-MM-DD</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",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-01-30</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240130</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>229699</td>\n",
|
|||
|
" <td>35413</td>\n",
|
|||
|
" <td>64279</td>\n",
|
|||
|
" <td>44220</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-01-23</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240123</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>233110</td>\n",
|
|||
|
" <td>44371</td>\n",
|
|||
|
" <td>57517</td>\n",
|
|||
|
" <td>46296</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-01-16</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240116</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>219315</td>\n",
|
|||
|
" <td>41761</td>\n",
|
|||
|
" <td>58746</td>\n",
|
|||
|
" <td>45403</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-01-09</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240109</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>206716</td>\n",
|
|||
|
" <td>30374</td>\n",
|
|||
|
" <td>56720</td>\n",
|
|||
|
" <td>43049</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-01-02</th>\n",
|
|||
|
" <td>COPPER-GRADE #1 - COMMODITY EXCHANGE INC.</td>\n",
|
|||
|
" <td>240102</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>190752</td>\n",
|
|||
|
" <td>17545</td>\n",
|
|||
|
" <td>57597</td>\n",
|
|||
|
" <td>42626</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>(CONTRACTS OF 25,000 POUNDS)</td>\n",
|
|||
|
" <td>085692</td>\n",
|
|||
|
" <td>CMX</td>\n",
|
|||
|
" <td>85</td>\n",
|
|||
|
" <td>N25</td>\n",
|
|||
|
" <td>FutOnly</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>5 rows × 190 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Market_and_Exchange_Names \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-01-23 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-01-16 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-01-09 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"2024-01-02 COPPER-GRADE #1 - COMMODITY EXCHANGE INC. \n",
|
|||
|
"\n",
|
|||
|
" As_of_Date_In_Form_YYMMDD \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 240130 \n",
|
|||
|
"2024-01-23 240123 \n",
|
|||
|
"2024-01-16 240116 \n",
|
|||
|
"2024-01-09 240109 \n",
|
|||
|
"2024-01-02 240102 \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Contract_Market_Code CFTC_Market_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 085692 CMX \n",
|
|||
|
"2024-01-23 085692 CMX \n",
|
|||
|
"2024-01-16 085692 CMX \n",
|
|||
|
"2024-01-09 085692 CMX \n",
|
|||
|
"2024-01-02 085692 CMX \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Region_Code CFTC_Commodity_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 1 85 \n",
|
|||
|
"2024-01-23 1 85 \n",
|
|||
|
"2024-01-16 1 85 \n",
|
|||
|
"2024-01-09 1 85 \n",
|
|||
|
"2024-01-02 1 85 \n",
|
|||
|
"\n",
|
|||
|
" Open_Interest_All Prod_Merc_Positions_Long_All \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 229699 35413 \n",
|
|||
|
"2024-01-23 233110 44371 \n",
|
|||
|
"2024-01-16 219315 41761 \n",
|
|||
|
"2024-01-09 206716 30374 \n",
|
|||
|
"2024-01-02 190752 17545 \n",
|
|||
|
"\n",
|
|||
|
" Prod_Merc_Positions_Short_All \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 64279 \n",
|
|||
|
"2024-01-23 57517 \n",
|
|||
|
"2024-01-16 58746 \n",
|
|||
|
"2024-01-09 56720 \n",
|
|||
|
"2024-01-02 57597 \n",
|
|||
|
"\n",
|
|||
|
" Swap_Positions_Long_All ... \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD ... \n",
|
|||
|
"2024-01-30 44220 ... \n",
|
|||
|
"2024-01-23 46296 ... \n",
|
|||
|
"2024-01-16 45403 ... \n",
|
|||
|
"2024-01-09 43049 ... \n",
|
|||
|
"2024-01-02 42626 ... \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_4_TDR_Long_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 0.0 \n",
|
|||
|
"2024-01-23 0.0 \n",
|
|||
|
"2024-01-16 0.0 \n",
|
|||
|
"2024-01-09 0.0 \n",
|
|||
|
"2024-01-02 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_4_TDR_Short_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 0.0 \n",
|
|||
|
"2024-01-23 0.0 \n",
|
|||
|
"2024-01-16 0.0 \n",
|
|||
|
"2024-01-09 0.0 \n",
|
|||
|
"2024-01-02 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_8_TDR_Long_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 0.0 \n",
|
|||
|
"2024-01-23 0.0 \n",
|
|||
|
"2024-01-16 0.0 \n",
|
|||
|
"2024-01-09 0.0 \n",
|
|||
|
"2024-01-02 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Conc_Net_LE_8_TDR_Short_Other \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 0.0 \n",
|
|||
|
"2024-01-23 0.0 \n",
|
|||
|
"2024-01-16 0.0 \n",
|
|||
|
"2024-01-09 0.0 \n",
|
|||
|
"2024-01-02 0.0 \n",
|
|||
|
"\n",
|
|||
|
" Contract_Units \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-01-23 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-01-16 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-01-09 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"2024-01-02 (CONTRACTS OF 25,000 POUNDS) \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Contract_Market_Code_Quotes \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 085692 \n",
|
|||
|
"2024-01-23 085692 \n",
|
|||
|
"2024-01-16 085692 \n",
|
|||
|
"2024-01-09 085692 \n",
|
|||
|
"2024-01-02 085692 \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Market_Code_Quotes \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 CMX \n",
|
|||
|
"2024-01-23 CMX \n",
|
|||
|
"2024-01-16 CMX \n",
|
|||
|
"2024-01-09 CMX \n",
|
|||
|
"2024-01-02 CMX \n",
|
|||
|
"\n",
|
|||
|
" CFTC_Commodity_Code_Quotes CFTC_SubGroup_Code \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 85 N25 \n",
|
|||
|
"2024-01-23 85 N25 \n",
|
|||
|
"2024-01-16 85 N25 \n",
|
|||
|
"2024-01-09 85 N25 \n",
|
|||
|
"2024-01-02 85 N25 \n",
|
|||
|
"\n",
|
|||
|
" FutOnly_or_Combined \n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-01-30 FutOnly \n",
|
|||
|
"2024-01-23 FutOnly \n",
|
|||
|
"2024-01-16 FutOnly \n",
|
|||
|
"2024-01-09 FutOnly \n",
|
|||
|
"2024-01-02 FutOnly \n",
|
|||
|
"\n",
|
|||
|
"[5 rows x 190 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 156,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"copper_df.tail()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "edb063af2e9080f9",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"The data is filtered down for the commodity in scope."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 157,
|
|||
|
"id": "b9a15b47ce6f7702",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:27:23.901870Z",
|
|||
|
"start_time": "2024-03-09T11:27:23.863022Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['Pct_of_Open_Interest_All',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Long_All',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Short_All',\n",
|
|||
|
" 'Pct_of_OI_Swap_Long_All',\n",
|
|||
|
" 'Pct_of_OI_Swap_Short_All',\n",
|
|||
|
" 'Pct_of_OI_Swap_Spread_All',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Long_All',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Short_All',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Spread_All',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Long_All',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Short_All',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Spread_All',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Long_All',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Short_All',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Long_All',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Short_All',\n",
|
|||
|
" 'Pct_of_Open_Interest_Old',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Short_Old',\n",
|
|||
|
" 'Pct_of_Open_Interest_Other',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Short_Other',\n",
|
|||
|
" 'Pct_of_OI_Swap_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_Swap_Short_Other',\n",
|
|||
|
" 'Pct_of_OI_Swap_Spread_Other',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Short_Other',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Spread_Other',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Short_Other',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Spread_Other',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Short_Other',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Long_Other',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Short_Other']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 157,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"open_interest_pct_columns = [col for col in copper_df.columns if 'pct' in col.lower()]\n",
|
|||
|
"open_interest_pct_columns"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 158,
|
|||
|
"id": "a1de9add52a1b195",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:27:24.707306Z",
|
|||
|
"start_time": "2024-03-09T11:27:24.666095Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['Pct_of_Open_Interest_Old',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Other_Rept_Spread_Old',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_Tot_Rept_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_NonRept_Short_Old']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 158,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"open_interest_pct_old_columns = [col for col in df.columns if 'pct' in col.lower() and col.endswith('_Old')]\n",
|
|||
|
"open_interest_pct_old_columns"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "ee4e807283d4829f",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"Columns of interest filtered down from the data set."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 160,
|
|||
|
"id": "c1683c4a417cca92",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:28:18.890283Z",
|
|||
|
"start_time": "2024-03-09T11:28:18.822733Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"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>Pct_of_Open_Interest_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Prod_Merc_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Prod_Merc_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Tot_Rept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Tot_Rept_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_NonRept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_NonRept_Short_Old</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>Report_Date_as_YYYY-MM-DD</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>2024-03-05</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>12.9</td>\n",
|
|||
|
" <td>27.7</td>\n",
|
|||
|
" <td>20.6</td>\n",
|
|||
|
" <td>4.4</td>\n",
|
|||
|
" <td>2.0</td>\n",
|
|||
|
" <td>26.0</td>\n",
|
|||
|
" <td>30.4</td>\n",
|
|||
|
" <td>15.1</td>\n",
|
|||
|
" <td>9.7</td>\n",
|
|||
|
" <td>8.1</td>\n",
|
|||
|
" <td>5.6</td>\n",
|
|||
|
" <td>92.0</td>\n",
|
|||
|
" <td>93.3</td>\n",
|
|||
|
" <td>8.0</td>\n",
|
|||
|
" <td>6.7</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-27</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>12.6</td>\n",
|
|||
|
" <td>29.6</td>\n",
|
|||
|
" <td>21.8</td>\n",
|
|||
|
" <td>4.7</td>\n",
|
|||
|
" <td>2.2</td>\n",
|
|||
|
" <td>28.7</td>\n",
|
|||
|
" <td>26.1</td>\n",
|
|||
|
" <td>12.8</td>\n",
|
|||
|
" <td>8.0</td>\n",
|
|||
|
" <td>11.5</td>\n",
|
|||
|
" <td>5.2</td>\n",
|
|||
|
" <td>91.5</td>\n",
|
|||
|
" <td>92.2</td>\n",
|
|||
|
" <td>8.5</td>\n",
|
|||
|
" <td>7.8</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-20</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>16.9</td>\n",
|
|||
|
" <td>26.2</td>\n",
|
|||
|
" <td>19.4</td>\n",
|
|||
|
" <td>3.1</td>\n",
|
|||
|
" <td>2.8</td>\n",
|
|||
|
" <td>27.5</td>\n",
|
|||
|
" <td>32.2</td>\n",
|
|||
|
" <td>11.6</td>\n",
|
|||
|
" <td>7.3</td>\n",
|
|||
|
" <td>9.5</td>\n",
|
|||
|
" <td>7.4</td>\n",
|
|||
|
" <td>92.9</td>\n",
|
|||
|
" <td>92.8</td>\n",
|
|||
|
" <td>7.1</td>\n",
|
|||
|
" <td>7.2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-13</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>18.5</td>\n",
|
|||
|
" <td>22.2</td>\n",
|
|||
|
" <td>17.9</td>\n",
|
|||
|
" <td>2.3</td>\n",
|
|||
|
" <td>2.6</td>\n",
|
|||
|
" <td>20.3</td>\n",
|
|||
|
" <td>37.3</td>\n",
|
|||
|
" <td>14.2</td>\n",
|
|||
|
" <td>10.1</td>\n",
|
|||
|
" <td>5.7</td>\n",
|
|||
|
" <td>9.8</td>\n",
|
|||
|
" <td>93.3</td>\n",
|
|||
|
" <td>94.2</td>\n",
|
|||
|
" <td>6.7</td>\n",
|
|||
|
" <td>5.8</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-06</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>14.0</td>\n",
|
|||
|
" <td>24.9</td>\n",
|
|||
|
" <td>18.5</td>\n",
|
|||
|
" <td>3.1</td>\n",
|
|||
|
" <td>4.7</td>\n",
|
|||
|
" <td>20.5</td>\n",
|
|||
|
" <td>29.5</td>\n",
|
|||
|
" <td>17.5</td>\n",
|
|||
|
" <td>8.5</td>\n",
|
|||
|
" <td>5.0</td>\n",
|
|||
|
" <td>9.7</td>\n",
|
|||
|
" <td>93.4</td>\n",
|
|||
|
" <td>94.6</td>\n",
|
|||
|
" <td>6.6</td>\n",
|
|||
|
" <td>5.4</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Pct_of_Open_Interest_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 100.0 \n",
|
|||
|
"2024-02-27 100.0 \n",
|
|||
|
"2024-02-20 100.0 \n",
|
|||
|
"2024-02-13 100.0 \n",
|
|||
|
"2024-02-06 100.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Prod_Merc_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 12.9 \n",
|
|||
|
"2024-02-27 12.6 \n",
|
|||
|
"2024-02-20 16.9 \n",
|
|||
|
"2024-02-13 18.5 \n",
|
|||
|
"2024-02-06 14.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Prod_Merc_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 27.7 \n",
|
|||
|
"2024-02-27 29.6 \n",
|
|||
|
"2024-02-20 26.2 \n",
|
|||
|
"2024-02-13 22.2 \n",
|
|||
|
"2024-02-06 24.9 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Swap_Long_Old Pct_of_OI_Swap_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 20.6 4.4 \n",
|
|||
|
"2024-02-27 21.8 4.7 \n",
|
|||
|
"2024-02-20 19.4 3.1 \n",
|
|||
|
"2024-02-13 17.9 2.3 \n",
|
|||
|
"2024-02-06 18.5 3.1 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Swap_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 2.0 \n",
|
|||
|
"2024-02-27 2.2 \n",
|
|||
|
"2024-02-20 2.8 \n",
|
|||
|
"2024-02-13 2.6 \n",
|
|||
|
"2024-02-06 4.7 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 26.0 \n",
|
|||
|
"2024-02-27 28.7 \n",
|
|||
|
"2024-02-20 27.5 \n",
|
|||
|
"2024-02-13 20.3 \n",
|
|||
|
"2024-02-06 20.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 30.4 \n",
|
|||
|
"2024-02-27 26.1 \n",
|
|||
|
"2024-02-20 32.2 \n",
|
|||
|
"2024-02-13 37.3 \n",
|
|||
|
"2024-02-06 29.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 15.1 \n",
|
|||
|
"2024-02-27 12.8 \n",
|
|||
|
"2024-02-20 11.6 \n",
|
|||
|
"2024-02-13 14.2 \n",
|
|||
|
"2024-02-06 17.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 9.7 \n",
|
|||
|
"2024-02-27 8.0 \n",
|
|||
|
"2024-02-20 7.3 \n",
|
|||
|
"2024-02-13 10.1 \n",
|
|||
|
"2024-02-06 8.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 8.1 \n",
|
|||
|
"2024-02-27 11.5 \n",
|
|||
|
"2024-02-20 9.5 \n",
|
|||
|
"2024-02-13 5.7 \n",
|
|||
|
"2024-02-06 5.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 5.6 \n",
|
|||
|
"2024-02-27 5.2 \n",
|
|||
|
"2024-02-20 7.4 \n",
|
|||
|
"2024-02-13 9.8 \n",
|
|||
|
"2024-02-06 9.7 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Tot_Rept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 92.0 \n",
|
|||
|
"2024-02-27 91.5 \n",
|
|||
|
"2024-02-20 92.9 \n",
|
|||
|
"2024-02-13 93.3 \n",
|
|||
|
"2024-02-06 93.4 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Tot_Rept_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 93.3 \n",
|
|||
|
"2024-02-27 92.2 \n",
|
|||
|
"2024-02-20 92.8 \n",
|
|||
|
"2024-02-13 94.2 \n",
|
|||
|
"2024-02-06 94.6 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_NonRept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 8.0 \n",
|
|||
|
"2024-02-27 8.5 \n",
|
|||
|
"2024-02-20 7.1 \n",
|
|||
|
"2024-02-13 6.7 \n",
|
|||
|
"2024-02-06 6.6 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_NonRept_Short_Old \n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 6.7 \n",
|
|||
|
"2024-02-27 7.8 \n",
|
|||
|
"2024-02-20 7.2 \n",
|
|||
|
"2024-02-13 5.8 \n",
|
|||
|
"2024-02-06 5.4 "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 160,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"columns = open_interest_pct_old_columns\n",
|
|||
|
"filtered_copper_df = copper_df[columns].copy()\n",
|
|||
|
"filtered_copper_df.head()\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 162,
|
|||
|
"id": "eb7bed9ce96a6571",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:28:57.288352Z",
|
|||
|
"start_time": "2024-03-09T11:28:57.240551Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"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>Pct_of_Open_Interest_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Prod_Merc_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Prod_Merc_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Swap_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_M_Money_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Other_Rept_Spread_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Tot_Rept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_Tot_Rept_Short_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_NonRept_Long_Old</th>\n",
|
|||
|
" <th>Pct_of_OI_NonRept_Short_Old</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>Report_Date_as_YYYY-MM-DD</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>2024-03-05</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>12.9</td>\n",
|
|||
|
" <td>27.7</td>\n",
|
|||
|
" <td>20.6</td>\n",
|
|||
|
" <td>4.4</td>\n",
|
|||
|
" <td>2.0</td>\n",
|
|||
|
" <td>26.0</td>\n",
|
|||
|
" <td>30.4</td>\n",
|
|||
|
" <td>15.1</td>\n",
|
|||
|
" <td>9.7</td>\n",
|
|||
|
" <td>8.1</td>\n",
|
|||
|
" <td>5.6</td>\n",
|
|||
|
" <td>92.0</td>\n",
|
|||
|
" <td>93.3</td>\n",
|
|||
|
" <td>8.0</td>\n",
|
|||
|
" <td>6.7</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-27</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>12.6</td>\n",
|
|||
|
" <td>29.6</td>\n",
|
|||
|
" <td>21.8</td>\n",
|
|||
|
" <td>4.7</td>\n",
|
|||
|
" <td>2.2</td>\n",
|
|||
|
" <td>28.7</td>\n",
|
|||
|
" <td>26.1</td>\n",
|
|||
|
" <td>12.8</td>\n",
|
|||
|
" <td>8.0</td>\n",
|
|||
|
" <td>11.5</td>\n",
|
|||
|
" <td>5.2</td>\n",
|
|||
|
" <td>91.5</td>\n",
|
|||
|
" <td>92.2</td>\n",
|
|||
|
" <td>8.5</td>\n",
|
|||
|
" <td>7.8</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-20</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>16.9</td>\n",
|
|||
|
" <td>26.2</td>\n",
|
|||
|
" <td>19.4</td>\n",
|
|||
|
" <td>3.1</td>\n",
|
|||
|
" <td>2.8</td>\n",
|
|||
|
" <td>27.5</td>\n",
|
|||
|
" <td>32.2</td>\n",
|
|||
|
" <td>11.6</td>\n",
|
|||
|
" <td>7.3</td>\n",
|
|||
|
" <td>9.5</td>\n",
|
|||
|
" <td>7.4</td>\n",
|
|||
|
" <td>92.9</td>\n",
|
|||
|
" <td>92.8</td>\n",
|
|||
|
" <td>7.1</td>\n",
|
|||
|
" <td>7.2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-13</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>18.5</td>\n",
|
|||
|
" <td>22.2</td>\n",
|
|||
|
" <td>17.9</td>\n",
|
|||
|
" <td>2.3</td>\n",
|
|||
|
" <td>2.6</td>\n",
|
|||
|
" <td>20.3</td>\n",
|
|||
|
" <td>37.3</td>\n",
|
|||
|
" <td>14.2</td>\n",
|
|||
|
" <td>10.1</td>\n",
|
|||
|
" <td>5.7</td>\n",
|
|||
|
" <td>9.8</td>\n",
|
|||
|
" <td>93.3</td>\n",
|
|||
|
" <td>94.2</td>\n",
|
|||
|
" <td>6.7</td>\n",
|
|||
|
" <td>5.8</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2024-02-06</th>\n",
|
|||
|
" <td>100.0</td>\n",
|
|||
|
" <td>14.0</td>\n",
|
|||
|
" <td>24.9</td>\n",
|
|||
|
" <td>18.5</td>\n",
|
|||
|
" <td>3.1</td>\n",
|
|||
|
" <td>4.7</td>\n",
|
|||
|
" <td>20.5</td>\n",
|
|||
|
" <td>29.5</td>\n",
|
|||
|
" <td>17.5</td>\n",
|
|||
|
" <td>8.5</td>\n",
|
|||
|
" <td>5.0</td>\n",
|
|||
|
" <td>9.7</td>\n",
|
|||
|
" <td>93.4</td>\n",
|
|||
|
" <td>94.6</td>\n",
|
|||
|
" <td>6.6</td>\n",
|
|||
|
" <td>5.4</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Pct_of_Open_Interest_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 100.0 \n",
|
|||
|
"2024-02-27 100.0 \n",
|
|||
|
"2024-02-20 100.0 \n",
|
|||
|
"2024-02-13 100.0 \n",
|
|||
|
"2024-02-06 100.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Prod_Merc_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 12.9 \n",
|
|||
|
"2024-02-27 12.6 \n",
|
|||
|
"2024-02-20 16.9 \n",
|
|||
|
"2024-02-13 18.5 \n",
|
|||
|
"2024-02-06 14.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Prod_Merc_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 27.7 \n",
|
|||
|
"2024-02-27 29.6 \n",
|
|||
|
"2024-02-20 26.2 \n",
|
|||
|
"2024-02-13 22.2 \n",
|
|||
|
"2024-02-06 24.9 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Swap_Long_Old Pct_of_OI_Swap_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 20.6 4.4 \n",
|
|||
|
"2024-02-27 21.8 4.7 \n",
|
|||
|
"2024-02-20 19.4 3.1 \n",
|
|||
|
"2024-02-13 17.9 2.3 \n",
|
|||
|
"2024-02-06 18.5 3.1 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Swap_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 2.0 \n",
|
|||
|
"2024-02-27 2.2 \n",
|
|||
|
"2024-02-20 2.8 \n",
|
|||
|
"2024-02-13 2.6 \n",
|
|||
|
"2024-02-06 4.7 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 26.0 \n",
|
|||
|
"2024-02-27 28.7 \n",
|
|||
|
"2024-02-20 27.5 \n",
|
|||
|
"2024-02-13 20.3 \n",
|
|||
|
"2024-02-06 20.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 30.4 \n",
|
|||
|
"2024-02-27 26.1 \n",
|
|||
|
"2024-02-20 32.2 \n",
|
|||
|
"2024-02-13 37.3 \n",
|
|||
|
"2024-02-06 29.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_M_Money_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 15.1 \n",
|
|||
|
"2024-02-27 12.8 \n",
|
|||
|
"2024-02-20 11.6 \n",
|
|||
|
"2024-02-13 14.2 \n",
|
|||
|
"2024-02-06 17.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 9.7 \n",
|
|||
|
"2024-02-27 8.0 \n",
|
|||
|
"2024-02-20 7.3 \n",
|
|||
|
"2024-02-13 10.1 \n",
|
|||
|
"2024-02-06 8.5 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 8.1 \n",
|
|||
|
"2024-02-27 11.5 \n",
|
|||
|
"2024-02-20 9.5 \n",
|
|||
|
"2024-02-13 5.7 \n",
|
|||
|
"2024-02-06 5.0 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Other_Rept_Spread_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 5.6 \n",
|
|||
|
"2024-02-27 5.2 \n",
|
|||
|
"2024-02-20 7.4 \n",
|
|||
|
"2024-02-13 9.8 \n",
|
|||
|
"2024-02-06 9.7 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Tot_Rept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 92.0 \n",
|
|||
|
"2024-02-27 91.5 \n",
|
|||
|
"2024-02-20 92.9 \n",
|
|||
|
"2024-02-13 93.3 \n",
|
|||
|
"2024-02-06 93.4 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_Tot_Rept_Short_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 93.3 \n",
|
|||
|
"2024-02-27 92.2 \n",
|
|||
|
"2024-02-20 92.8 \n",
|
|||
|
"2024-02-13 94.2 \n",
|
|||
|
"2024-02-06 94.6 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_NonRept_Long_Old \\\n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 8.0 \n",
|
|||
|
"2024-02-27 8.5 \n",
|
|||
|
"2024-02-20 7.1 \n",
|
|||
|
"2024-02-13 6.7 \n",
|
|||
|
"2024-02-06 6.6 \n",
|
|||
|
"\n",
|
|||
|
" Pct_of_OI_NonRept_Short_Old \n",
|
|||
|
"Report_Date_as_YYYY-MM-DD \n",
|
|||
|
"2024-03-05 6.7 \n",
|
|||
|
"2024-02-27 7.8 \n",
|
|||
|
"2024-02-20 7.2 \n",
|
|||
|
"2024-02-13 5.8 \n",
|
|||
|
"2024-02-06 5.4 "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 162,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"columns = [\"Pct_of_OI_Prod_Merc_Long_Old\", \"Pct_of_OI_Prod_Merc_Short_Old\"]\n",
|
|||
|
"filtered_copper_df_producers = copper_df[columns].copy()\n",
|
|||
|
"filtered_copper_df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "3d3ff0847b3496e8",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Automated Compass Analysis\n",
|
|||
|
"\n",
|
|||
|
"* 5th of March vs. our target %"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 181,
|
|||
|
"id": "cb03cf7bb2c92a61",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T12:02:45.277418Z",
|
|||
|
"start_time": "2024-03-09T12:02:45.200217Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Pct_of_Open_Interest_Old 100.0\n",
|
|||
|
"Pct_of_OI_Prod_Merc_Long_Old 12.9\n",
|
|||
|
"Pct_of_OI_Prod_Merc_Short_Old 27.7\n",
|
|||
|
"Pct_of_OI_Swap_Long_Old 20.6\n",
|
|||
|
"Pct_of_OI_Swap_Short_Old 4.4\n",
|
|||
|
"Pct_of_OI_Swap_Spread_Old 2.0\n",
|
|||
|
"Pct_of_OI_M_Money_Long_Old 26.0\n",
|
|||
|
"Pct_of_OI_M_Money_Short_Old 30.4\n",
|
|||
|
"Pct_of_OI_M_Money_Spread_Old 15.1\n",
|
|||
|
"Pct_of_OI_Other_Rept_Long_Old 9.7\n",
|
|||
|
"Pct_of_OI_Other_Rept_Short_Old 8.1\n",
|
|||
|
"Pct_of_OI_Other_Rept_Spread_Old 5.6\n",
|
|||
|
"Pct_of_OI_Tot_Rept_Long_Old 92.0\n",
|
|||
|
"Pct_of_OI_Tot_Rept_Short_Old 93.3\n",
|
|||
|
"Pct_of_OI_NonRept_Long_Old 8.0\n",
|
|||
|
"Pct_of_OI_NonRept_Short_Old 6.7\n",
|
|||
|
"Short_MA NaN\n",
|
|||
|
"Long_MA NaN\n",
|
|||
|
"Name: 2024-03-05 00:00:00, dtype: float64\n",
|
|||
|
"False\n",
|
|||
|
"False\n",
|
|||
|
"\n",
|
|||
|
"Long OI % -- Producer Signal as qualified market indicator : 12.9\n",
|
|||
|
"Market likelihood -- Bullish: False\n",
|
|||
|
"Market likelihood -- Bearish: False\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"compare_data = filtered_copper_df.loc['2024-03-05']\n",
|
|||
|
"print(compare_data)\n",
|
|||
|
"\n",
|
|||
|
"\"\"\"\n",
|
|||
|
"Analyse-Compass (Ray Dalio)\n",
|
|||
|
"% Open Interest \n",
|
|||
|
"Bullish / Bearish ranges\n",
|
|||
|
"\n",
|
|||
|
"25-20%\t/ 40-50%\n",
|
|||
|
"\"\"\"\n",
|
|||
|
"\n",
|
|||
|
"Pct_of_OI_Prod_Merc_Long_Old = compare_data[\"Pct_of_OI_Prod_Merc_Long_Old\"] \n",
|
|||
|
"in_range_bull = 20 <= Pct_of_OI_Prod_Merc_Long_Old <= 25\n",
|
|||
|
"print(in_range_bull)\n",
|
|||
|
"\n",
|
|||
|
"Pct_of_OI_Prod_Merc_Short_Old = compare_data[\"Pct_of_OI_Prod_Merc_Short_Old\"] \n",
|
|||
|
"in_range_bear = 40 <= Pct_of_OI_Prod_Merc_Short_Old <= 50\n",
|
|||
|
"print(in_range_bear)\n",
|
|||
|
"\n",
|
|||
|
"print()\n",
|
|||
|
"print(\"Long OI % -- Producer Signal as qualified market indicator : {}\".format(compare_data[\"Pct_of_OI_Prod_Merc_Long_Old\"]))\n",
|
|||
|
"print(\"Market likelihood -- Bullish: {}\".format(in_range_bull))\n",
|
|||
|
"print(\"Market likelihood -- Bearish: {}\".format(in_range_bear))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "5da29ce146ef71f2",
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## COT Trend Analysis for signal changes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 166,
|
|||
|
"id": "596c61dcbf4ac7a2",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:35:01.969254Z",
|
|||
|
"start_time": "2024-03-09T11:35:01.531144Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAJUCAYAAAD5IdzqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1zV5fvH8ddhb2QpIshwISrurblHuUdqmZbfdmlpZTZdTdulla1fqblz58w0U3MroiJu3MgG2XDO/fvjwxScjHPA6/l4+Cg+Z93nwwHO+9z3fV06pZRCCCGEEEIIIUSJmBl7AEIIIYQQQghRGUi4EkIIIYQQQohSIOFKCCGEEEIIIUqBhCshhBBCCCGEKAUSroQQQgghhBCiFEi4EkIIIYQQQohSIOFKCCGEEEIIIUqBhCshhBBCCCGEKAUSroQQQgghhBCiFEi4EkKIUrJhwwaaNGmCjY0NOp2OhIQEYw9JlLMnnngCBwcHYw9D3Of8/Px44oknjD0MIe5LEq6EMEG//fYbOp0u75+NjQ1169Zl7NixXLt2zdjDK7GwsDCmTp1KRESEsYdSamJjYxk2bBi2trZ8++23zJs3D3t7+1ve5tixYzz22GPUqFEDa2trvLy8GDlyJMeOHSunUZeMn58fffv2vafbrlu3jqlTp5bugMqAKb9W9Xo9v/76K507d8bV1RVra2v8/PwYM2YM+/fvv+v7M+XnWlaysrL45ptvaNmyJY6Ojjg4ONCyZUu++eYbsrKyjD28PP/880+hvwm3+ieEMC4LYw9ACHFz06dPx9/fn/T0dHbs2MH333/PunXrOHr0KHZ2dsYe3j0LCwtj2rRpdO7cGT8/P2MPp1Ts27eP69ev895779G9e/fbXn/58uU88sgjuLq68uSTT+Lv709ERAS//PILf/zxB4sWLWLQoEHlMHLjWLduHd9++63JByxTfa2mpaUxePBgNmzYwAMPPMBbb72Fq6srERERLFmyhDlz5nDhwgW8vb3v+D5N9bmWlZSUFPr06cO2bdvo27cvTzzxBGZmZmzYsIGXX36Z5cuXs3bt2tt+SFIe6tevz7x58wode/PNN3FwcODtt98ucv0TJ05gZiafnwthDBKuhDBhDz74IC1atADgqaeews3NjS+++IJVq1bxyCOPlOi+U1NTK3RAMzVRUVEAVKlS5bbXPXPmDKNGjSIgIIB///0XDw+PvMtefvllOnbsyKhRowgNDSUgIKCshlzpKKVIT0/H1tbW2EMpcxMnTmTDhg18+eWXjB8/vtBlU6ZM4csvvzTOwMqBwWAgMzMTGxubEt3PK6+8wrZt25g5cyZjx47NO/7888/z7bffMnbsWF577TW+//77kg75jt3sNVytWjUee+yxQsc+/vhj3N3dixwHsLa2LtNxCiFuQQkhTM6vv/6qALVv375Cx//8808FqA8++CDv2Lx581SzZs2UjY2NcnFxUcOHD1cXLlwodLtOnTqpBg0aqP3796uOHTsqW1tb9fLLLyullEpLS1NTpkxRderUUdbW1srT01MNGjRInT59Ou/2er1effnllyooKEhZW1urqlWrqmeeeUbFxcUVehxfX1/Vp08ftX37dtWyZUtlbW2t/P391Zw5c4o8txv/bd26VSml1MqVK9VDDz2kqlevrqysrFRAQICaPn26ys7OLnKeZs2apfz9/ZWNjY1q2bKl+vfff1WnTp1Up06dCl0vPT1dTZ48WdWqVUtZWVkpb29vNXHiRJWenn5H348lS5bknWM3Nzc1cuRIdenSpULn98bn8/jjj9/0/p599lkFqH///bfYy7dt26YA9eyzz+YdmzJligLU8ePH1cMPP6wcHR2Vq6ureumll1RaWlqR+7ib18WxY8dU586dla2trfLy8lIzZsy4o/OS+/3Ode7cOQWoTz/9VP3www8qICBAWVlZqRYtWqi9e/fmXe/xxx8v9jWQ625fbxs2bFDNmzdX1tbW6ssvv1RKKRUfH69efvll5e3traysrFStWrXUxx9/rPR6faH7WLhwoWrWrJlycHBQjo6OqmHDhuqrr75SSt3+tVqcxx9/XNnb26szZ86onj17Kjs7O1W9enU1bdo0ZTAYlFJKGQwG5evrq/r371/k9mlpacrJyUk988wzN32MixcvKgsLC9WjR4+bXqegiIgI9fzzz6u6desqGxsb5erqqoYOHarOnTuXd507ea7r1q1THTp0UHZ2dsrBwUE99NBD6ujRo0Ueb8mSJap+/frK2tpaNWjQQC1fvlw9/vjjytfXt9D1kpOT1SuvvJL3Papbt6769NNP885TLkC9+OKL6vfff1dBQUHKwsJCLV++vMTn0NzcXHXt2vWm1+nSpYuysLBQFy9eVEop1aBBA9W5c+ci19Pr9crLy0sNGTKk0LGSvoZvp0GDBkV+1xW834K/g3K/v9u3b1fjxo1T7u7uytnZWT3zzDMqIyNDxcfHq1GjRqkqVaqoKlWqqIkTJxb5PtzpcxLififhSggTdLNw9fXXXytAzZ49Wyml1Pvvv690Op0aPny4+u6779S0adOUu7u78vPzU/Hx8Xm369Spk/L09FQeHh5q3Lhx6ocfflArV65U2dnZqlu3bgpQI0aMULNmzVIfffSR6tq1q1q5cmXe7Z966illYWGhnn76aTV79mw1adIkZW9vr1q2bKkyMzPzrufr66vq1aunqlWrpt566y01a9Ys1axZM6XT6fLehJ05c0a99NJLClBvvfWWmjdvnpo3b56KjIxUSik1cOBANWzYMPXpp5+q77//Xj388MMKUK+99lqhc/Hdd98pQHXs2FF988036pVXXlGurq6qVq1ahd5w6PX6vDe548ePVz/88IMaO3assrCwUAMGDLjj70XLli3Vl19+qd544w1la2tb6Bxv2rRJPfPMMwpQ06dPV/PmzVP//fffTe/Ty8tL+fn53fJx/fz8lLe3d97XueGqUaNGql+/fmrWrFnqscceU4AaNWpUodvezevCy8tL+fj4qJdffll99913qmvXrgpQ69atu+25uVm4atq0qapdu7aaMWOG+uSTT5S7u7vy9vbOe638999/qkePHgrI+/7Pmzcv737u5vVWu3Zt5eLiot544w01e/ZstXXrVpWSkqKCg4OVm5ubeuutt9Ts2bPV6NGjlU6ny/tQQSnt+waobt26qW+//VZ9++23auzYserhhx9WSt3+tVqcxx9/XNnY2Kg6deqoUaNGqVmzZqm+ffsqQL377rt513v77beVpaWlio2NLXT7JUuW3DJ4K6XUjz/+qAA1d+7c23yHNEuXLlWNGzdWkydPVj/++KN66623lIuLi/L19VUpKSl39Fznzp2rdDqd6t27t5o5c6aaMWOG8vPzU1WqVCkU0v7880+l0+lUcHCw+uKLL9S7776rXFxcVMOGDQuFK4PBoLp27ap0Op166qmn1KxZs1S/fv0UoMaPH19o/ICqX7++8vDwUNOmTVPffvutOnToUKmcw99+++2m18n92f/pp5+UUkpNnz5dmZmZqatXrxa6Xu6HIUuXLs07VtLX8J24l3DVpEkT1bt3b/Xtt9+qUaNGKUC9/vrrqkOHDurRRx9V3333Xd7rteCHYnfznIS430m4EsIE5f4h3Lx5s4qOjlYXL15UixYtUm5ubsrW1lZdunRJRUREKHNz80KzWEopdeTIEWVhYVHoeO7MSm4oy/V///d/ClBffPFFkTHkfmq5fft2Baj58+cXunzDhg1Fjvv6+hZ5UxMVFaWsra3Vq6++mnds6dKlN50BSE1NLXLs2WefVXZ2dnkzTRkZGcrNzU21bNlSZWVl5V3vt99+U0ChNxzz5s1TZmZmavv27YXuc/bs2QpQO3fuLPJ4uTIzM1XVqlVVw4YNC80O5c4gTp48Oe/YzQLxjRISEhRw22DXv39/BaikpCSlVH64uvGT+hdeeEEB6vDhw0opdU+vi4Jv0jMyMpSnp2ehT+Fv5mbhys3NrdCn2atWrVKAWrNmTd6xF198sdBsVa57eb1t2LCh0HXfe+89ZW9vr06ePFno+BtvvKHMzc3zZvB
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"# Assuming 'df' is your DataFrame and it's already indexed by \"Report_Date_as_YYYY-MM-DD\" with datetime format\n",
|
|||
|
"columns_to_plot = [\n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Long_Old', \n",
|
|||
|
" 'Pct_of_OI_Prod_Merc_Short_Old',\n",
|
|||
|
" 'Pct_of_OI_Swap_Short_Old', \n",
|
|||
|
" 'Pct_of_OI_Swap_Long_Old',\n",
|
|||
|
" 'Pct_of_OI_M_Money_Long_Old', \n",
|
|||
|
" 'Pct_of_OI_M_Money_Short_Old'\n",
|
|||
|
"]\n",
|
|||
|
"\n",
|
|||
|
"# Plotting\n",
|
|||
|
"ax = filtered_copper_df[columns_to_plot].plot(kind='line', figsize=(10, 6), title='Percentage of Open Interest by Category Over Time')\n",
|
|||
|
"ax.set_xlabel('Date')\n",
|
|||
|
"ax.set_ylabel('Percentage of Open Interest')\n",
|
|||
|
"\n",
|
|||
|
"plt.show()\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 170,
|
|||
|
"id": "7f0f0826f62e9212",
|
|||
|
"metadata": {
|
|||
|
"ExecuteTime": {
|
|||
|
"end_time": "2024-03-09T11:42:25.972848Z",
|
|||
|
"start_time": "2024-03-09T11:42:25.657720Z"
|
|||
|
},
|
|||
|
"collapsed": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "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
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"\n",
|
|||
|
"# Example column\n",
|
|||
|
"column = 'Pct_of_OI_Prod_Merc_Long_Old'\n",
|
|||
|
"\n",
|
|||
|
"# Calculate moving averages\n",
|
|||
|
"filtered_copper_df['Short_MA'] = filtered_copper_df[column].rolling(window=5).mean() # Short-term moving average (e.g., 5 days)\n",
|
|||
|
"filtered_copper_df['Long_MA'] = filtered_copper_df[column].rolling(window=20).mean() # Long-term moving average (e.g., 20 days)\n",
|
|||
|
"\n",
|
|||
|
"# Plot the original data and moving averages\n",
|
|||
|
"plt.figure(figsize=(10, 6))\n",
|
|||
|
"plt.plot(filtered_copper_df.index, filtered_copper_df[column], label='Original Data', alpha=0.5)\n",
|
|||
|
"plt.plot(filtered_copper_df.index, filtered_copper_df['Short_MA'], label='Short-term MA', alpha=0.75)\n",
|
|||
|
"plt.plot(filtered_copper_df.index, filtered_copper_df['Long_MA'], label='Long-term MA', alpha=0.75)\n",
|
|||
|
"\n",
|
|||
|
"# Identifying the crossing points\n",
|
|||
|
"crossings = np.where(np.diff(np.sign(filtered_copper_df['Short_MA'] - filtered_copper_df['Long_MA'])))[0]\n",
|
|||
|
"plt.scatter(filtered_copper_df.index[crossings], filtered_copper_df[column].iloc[crossings], color='red', label='Trend Change')\n",
|
|||
|
"\n",
|
|||
|
"plt.xlabel('Date')\n",
|
|||
|
"plt.ylabel('Percentage of Open Interest')\n",
|
|||
|
"plt.title(f'Trend Changes in {column}')\n",
|
|||
|
"plt.legend()\n",
|
|||
|
"plt.show()\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"kernelspec": {
|
|||
|
"display_name": "Python 3",
|
|||
|
"language": "python",
|
|||
|
"name": "python3"
|
|||
|
},
|
|||
|
"language_info": {
|
|||
|
"codemirror_mode": {
|
|||
|
"name": "ipython",
|
|||
|
"version": 2
|
|||
|
},
|
|||
|
"file_extension": ".py",
|
|||
|
"mimetype": "text/x-python",
|
|||
|
"name": "python",
|
|||
|
"nbconvert_exporter": "python",
|
|||
|
"pygments_lexer": "ipython2",
|
|||
|
"version": "2.7.6"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 5
|
|||
|
}
|