Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Commitment of Traders report on Oil ETF Performance

Look at the % change week by week of the Managed Money Long, Short, and Spread positions, and make decisions on the first trading day of the week based on those indicators.

2 responses

@Patrick: The result looks pretty promising. Would you please provide link for acquiring data source?

Thanks Adam.

2014 was a bad year for oil. But if you only test on 2015, and use the Managed Money Long indicator as a guide, the performance is really really good,
To keep 2014 sane, we have to look at shorts & Spreads as well.

The source file is from an external python script. I could really use help trying to load the raw file into Quantopian itself without having to parse it externally.
Raw file source -
http://www.cftc.gov/MarketReports/CommitmentsofTraders/HistoricalCompressed/index.htm

The external parser does 2 things.
1- Changes the date + 6 days. Because the report is released Friday night, but references the previous Tuesdays' data. We execute the buy on Monday morning based on the data in the report.

2- I only report the % difference between the current week & the previous week for the 3 columns I'm interested in. I couldn't do this in quantopian, because I cannot get history to work from within fetch_csv

That being said, there may be a poor man's way around that problem because there are also 3 columns in the report we could use:
Change_in_M_Money_Short_All Change_in_M_Money_Spread_All Change_in_Other_Rept_Long_All
They reference a value, but not a percentage.

Here's the crappy parsing script:

import csv  
import datetime

i = 0

print ("Report_Date_as_MM_DD_YYYY,C_name,M_Money_Positions_Long_ALL,M_Money_Positions_Short_ALL,M_Money_Positions_Spread_ALL")  
with open('c_year-3.csv') as csvfile:  
    readCSV = csv.reader(csvfile, delimiter=',')  
    dates = []  
    values = []  
    readCSV = list(readCSV)  
    for row in (readCSV):  
    name = row[0]  
        M_Money_Positions_Long_ALL = row[13]  
        M_Money_Positions_Short_ALL = row[14]  
    M_Money_Positions_Spread_ALL = row[15]

    date = row[2]  
    if date != 'Report_Date_as_MM_DD_YYYY':  
        last_week_row_csv = readCSV[(i + 1)]  
        print_date = datetime.datetime.strptime(date, '%m/%d/%Y') + datetime.timedelta(days=6)  
        try:  
            prev_M_Money_Positions_Short_ALL = last_week_row_csv[14]  
            diff_M_Money_Positions_Short_ALL =(float(M_Money_Positions_Short_ALL) / float(prev_M_Money_Positions_Short_ALL))  
                    prev_M_Money_Positions_Long_ALL = last_week_row_csv[13]  
                    diff_M_Money_Positions_Long_ALL =(float(M_Money_Positions_Long_ALL) / float(prev_M_Money_Positions_Long_ALL))  
            prev_M_Money_Positions_Spread_ALL = last_week_row_csv[15]  
                    diff_M_Money_Positions_Spread_ALL =(float(M_Money_Positions_Spread_ALL) / float(prev_M_Money_Positions_Spread_ALL))  
        except:  
            diff_M_Money_Positions_Short_ALL = 0  
            diff_M_Money_Positions_Long_ALL = 0  
            diff_M_Money_Positions_Spread_ALL = 0

        #print ("Date %s - Current - %s  , Previous - %s ") % (date,M_Money_Positions_Long_ALL, prev_M_Money_Positions_Long_ALL)  
            print ("%s" + "," + "%s" + "," + "%s" + "," +"%s" + "," + "%s") % (print_date,name,diff_M_Money_Positions_Long_ALL, diff_M_Money_Positions_Short_ALL, diff_M_Money_Positions_Spread_ALL)  
    i += 1