Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Storing Daily Results

Dear fellows,

I would like to export the performance data of my algorithms to study them locally. Since I couldn't find a simple way to get this data I am doing the following sequence of steps. They work but I would like to know if you have a better way to do it:

  1. On the leaderboard I select the algorithm that I want to get the data;
  2. In the Developer Tools of my browser, I select the "Elements" Tab, find the div element with the class "contest-user-view", right click and copy it;
  3. Paste it in a text editor and save the file with the name "YYYYMMDD_algo.html" (e.g. 20150601_algo.html);
  4. Run the following python script in my local computer:
# sudo pip install beautifulsoup4  
from bs4 import BeautifulSoup,NavigableString  
import glob  
import csv

folder = "/Users/myuser/folder_results/"  
files = glob.glob(folder + "*.html")

#Parse the HTML  
def get_results(trading,test):  
    result = {}  
    l_score = trading.find_all("div",{'class':'pane big top'})[0].get_text().split("\n")  
    result[l_score[2].replace(" ","_") + "_position"] = l_score[1]  
    result[l_score[2].replace(" ","_") + "_value"] = l_score[3]  
    score = trading.find_all("div",{'class':'pane big top'})[0]  
    for metric in trading.find_all("div",{'class':'col-xs-7 pane small'}):  
        l_metric = metric.get_text().split("\n")  
        result[l_metric[2].replace(" ","_") + "_position"] = l_metric[1]  
        result[l_metric[2].replace(" ","_") + "_value"] = l_metric[3]  
    return result

#Iterate thru all the algo results  
dates = []  
all_results = []  
for f in files:  
    result = {}  
    result["date"] = f.split("/")[-1].split("_")[0]  
    result["algorithm"] = f.split("/")[-1].split("_")[1].split(".html")[0]  
    if result["date"] not in dates:  
        dates.append(result["date"])  
    html = BeautifulSoup(open(f))  
    paper_trading =  html.findAll("div",{'class':'pane-group pane-group-left'})[0]  
    result["paper_results"] = get_results(paper_trading,"paper")  
    backtest_trading = html.findAll("div",{'class':'pane-group pane-group-right'})[0]  
    result["backtest_results"] = get_results(backtest_trading,"backtest")  
    l_consitency = html.findAll("div",{'class':'consistency'})[0].get_text().split("\n")  
    result["consistency"] = l_consitency[2]  
    all_results.append(result)  
#Save it as a csv file

last_date = max(dates)

i = 0  
with open(folder + str(last_date) + "_results.csv", 'wb') as csvfile:  
    results_writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)  
    header = []  
    for result in all_results:  
        row = []  
        for key in result:  
            if "results" in key:  
                for k in result[key]:  
                    if i == 0:  
                        header.append(key + "_" + k)  
                    row.append(result[key][k])  
            elif "date" in key:  
                if i == 0:  
                    header.append("date")  
                row.append(result[key])  
            elif "consistency" in key:  
                if i == 0:  
                    header.append("consistency")  
                row.append(result[key])  
            elif "algo" in key:  
                if i == 0:  
                    header.append("algo")  
                row.append(result[key])  
        if i == 0:  
            results_writer.writerow(header)  
        print row  
        results_writer.writerow(row)  
        i += 1  

After this I have a nice CSV file with the daily results per algorithm.

Hopefully we can find a nicer/simpler way to do this :P I am a bit lazy to do this every day...

Bests,

Fred

3 responses

How is this different from downloading the leaderboard CSV?

I didn't know about that button for downloading the leaderboard :) Thanks Paul!

If you're looking for deeper study of your results, make sure you check out get_backtest() in the research platform. Obviously, you can only look at yours, not everyone else's.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.