diff options
| -rw-r--r-- | tranches_insight/static/main.js | 21 | ||||
| -rw-r--r-- | tranches_insight/templates/index.html | 31 | ||||
| -rw-r--r-- | tranches_insight/tranches_insight.py | 20 |
3 files changed, 47 insertions, 25 deletions
diff --git a/tranches_insight/static/main.js b/tranches_insight/static/main.js new file mode 100644 index 00000000..74bc3cdd --- /dev/null +++ b/tranches_insight/static/main.js @@ -0,0 +1,21 @@ +g2 = new Dygraph(document.getElementById("graphdiv2"), + [], // path to CSV file + { labels: [], + title: "Correlation numbers" } // options + ); + +document.getElementById('dropdown'). + addEventListener('change', function(e) { + var index = this.value.split("."); + $.getJSON("_data", + {i: index[0], s: index[1], t: index[2]}, + function(data){ + var newdata = data["data"].map(function(e){ + f = e.slice(1); + f.unshift(new Date(e[0])); + return f}); + g2.updateOptions({'file': newdata, 'labels': data['labels']}); + }); + }); +var event = new Event('change'); +document.getElementById('dropdown').dispatchEvent(event); diff --git a/tranches_insight/templates/index.html b/tranches_insight/templates/index.html index a797bea4..d3cd66a3 100644 --- a/tranches_insight/templates/index.html +++ b/tranches_insight/templates/index.html @@ -6,23 +6,18 @@ </head> <body> <div id="graphdiv2" - style="width:800px; height:500px;"></div> -<script type="text/javascript"> - g2 = new Dygraph(document.getElementById("graphdiv2"), - [], // path to CSV file - { labels: {{labels|tojson|safe}}, - title: "Correlation numbers" } // options - ); - $.getJSON("_data", - {i:"IG",s:9, t:"10yr"}, - function(data){ - var newdata = data["data"].map(function(e){ - f = e.slice(1); - f.unshift(new Date(e[0])); - return f}); - console.log(newdata); - g2.updateOptions({'file': newdata}); - }) -</script> + style="width:800px; height:500px;"> +</div> +<div> + <select id="dropdown"> + {% for index in index_list %} + <option value="{{"{0}.{1}.{2}".format(*index)}}" + {% if loop.index==1 %}selected="selected"{% endif %}> + {{"{0}{1} {2}".format(*index)}} + </option> + {% endfor %} + </select> +</div> +<script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script> </body> </html> 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) |
