aboutsummaryrefslogtreecommitdiffstats
path: root/tranches_insight/tranches_insight.py
diff options
context:
space:
mode:
Diffstat (limited to 'tranches_insight/tranches_insight.py')
-rw-r--r--tranches_insight/tranches_insight.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/tranches_insight/tranches_insight.py b/tranches_insight/tranches_insight.py
index 1e08a09a..13928c7c 100644
--- a/tranches_insight/tranches_insight.py
+++ b/tranches_insight/tranches_insight.py
@@ -1,24 +1,30 @@
from flask import Flask, render_template, jsonify, request
-import os, csv
+import os, csv, yaml
app = Flask(__name__)
+basedir = "/home/share/CorpCDOs"
@app.route("/_data")
def get_corr():
index = request.args.get("i")
series = request.args.get("s")
tenor = request.args.get("t")
- basedir = "/home/share/CorpCDOs/Tranche_Data/Runs/"
data = []
- with open(os.path.join(basedir, "{0}{1}.{2}.csv".format(index, series, tenor))) as fh:
+ with open(os.path.join(basedir, "Tranche_data", "Runs",
+ "{0}{1}.{2}.csv".format(index, series, tenor))) as fh:
csvreader = csv.DictReader(fh)
for line in csvreader:
- data.append([line["date"], float(line['3 Corr']), float(line['7 Corr']),
- float(line['10 Corr']), float(line['15 Corr'])])
- return jsonify(data=data)
+ date = line["date"].replace("-","/")
+ corrkeys = [k for k in line.keys() if k.endswith("Corr")]
+ corrkeys = sorted(corrkeys, key=lambda x: int(x.split(" ")[0]))
+ data.append([date] + [line[k] for k in corrkeys])
+ return jsonify(labels=["Date"] + corrkeys, data=data)
@app.route("/")
def main():
- return render_template("index.html", labels=["Date", "3 Corr", "7 Corr", "10 Corr", "15 Corr"])
+ with open(os.path.join(basedir, "code", "etc", "runs.yml")) as fh:
+ runs = yaml.load(fh)
+ index_list = [[name[:2], name[2:], tenor] for name, tenor in zip(runs['name'], runs['tenor'])]
+ return render_template("index.html", index_list=index_list)
if __name__ == "__main__":
app.run(debug=True)