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:
- On the leaderboard I select the algorithm that I want to get the data;
- 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;
- Paste it in a text editor and save the file with the name "YYYYMMDD_algo.html" (e.g. 20150601_algo.html);
- 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