aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--risk_insight/insight.py11
-rw-r--r--risk_insight/static/indices.js35
-rw-r--r--risk_insight/static/tranches.js (renamed from risk_insight/static/main.js)2
-rw-r--r--risk_insight/templates/index.html7
-rw-r--r--risk_insight/templates/indices.html4
-rw-r--r--risk_insight/templates/tranches.html2
6 files changed, 49 insertions, 12 deletions
diff --git a/risk_insight/insight.py b/risk_insight/insight.py
index 37cb15ea..533ba2ac 100644
--- a/risk_insight/insight.py
+++ b/risk_insight/insight.py
@@ -51,20 +51,19 @@ def get_risk_numbers():
data=data)
@app.route("/_data_indices")
-def get_risk_numbers():
+def get_indices_quotes():
index = request.args.get("i")
series = request.args.get("s", 0, int)
tenor = request.args.get("t")
data = []
db = get_db()
- attach = get_attach_from_name(index, series)
sqlstr = "SELECT date, closeprice, modelprice, adjcloseprice, adjmodelprice " \
"from index_quotes WHERE index=%s and series=%s " \
"and tenor=%s ORDER BY date"
with db.cursor() as c:
c.execute(sqlstr, (index.upper(), series, tenor))
- data = [["%s/%s/%s" % (date.year, date.month, date.day)] + val for date, val in c]
- return jsonify(labels=["Date"] + ["{0}-{1} {2}".format(l, u, greek) for l, u in zip(attach[:-1], attach[1:])],
+ data = [["%s/%s/%s" % (date.year, date.month, date.day)] + val for date, *val in c]
+ return jsonify(labels=["Date", "Close", "FV", "AdjClose", "AdjFV"],
data=data)
@app.route("/tranches.html")
@@ -76,9 +75,9 @@ def tranches():
@app.route("/indices.html")
def indices():
- return render_template("indices.html")
+ return render_template("indices.html", series=[9, 10, 11, 13, 15, 17, 19, 21, 23])
-@app.route("/index.html")
+@app.route("/")
def main():
return render_template("index.html")
diff --git a/risk_insight/static/indices.js b/risk_insight/static/indices.js
new file mode 100644
index 00000000..ea5786af
--- /dev/null
+++ b/risk_insight/static/indices.js
@@ -0,0 +1,35 @@
+g = new Dygraph(document.getElementById("graph"),
+ [], // path to CSV file
+ { labels: [],
+ title: "Index quotes",
+ showRoller: true,
+ legend: "always"} // options
+ );
+
+function update_graph(g) {
+ return function(e) {
+ var payload = {i: document.getElementById('index').value,
+ s: document.getElementById('series').value,
+ t: document.getElementById('tenor').value};
+ $.getJSON("_data_indices",
+ payload,
+ function(data){
+ var newdata = data["data"].map(function(e){
+ f = e.slice(1);
+ f.unshift(new Date(e[0]));
+ return f});
+ g.updateOptions({'file': newdata, 'labels': data['labels']});
+ });
+ }
+};
+
+
+document.getElementById('index').
+ addEventListener('change', update_graph(g));
+document.getElementById('series').
+ addEventListener('change', update_graph(g));
+document.getElementById('tenor').
+ addEventListener('change', update_graph(g));
+
+var event = new Event('change');
+document.getElementById('index').dispatchEvent(event);
diff --git a/risk_insight/static/main.js b/risk_insight/static/tranches.js
index f4fe9b57..23493461 100644
--- a/risk_insight/static/main.js
+++ b/risk_insight/static/tranches.js
@@ -22,7 +22,7 @@ function update_graph(g) {
if( g.maindiv_.id == "graph1"){
payload['g'] = "skew";
}
- $.getJSON("_data",
+ $.getJSON("_data_tranches",
payload,
function(data){
var newdata = data["data"].map(function(e){
diff --git a/risk_insight/templates/index.html b/risk_insight/templates/index.html
index cde8d3dc..f4bfadfa 100644
--- a/risk_insight/templates/index.html
+++ b/risk_insight/templates/index.html
@@ -3,7 +3,10 @@
<head>
</head>
<body>
- <a href="tranches.html">Tranche Insights</a>
- <a href="indices.html">Index Insights</a>
+ <div>
+ <ul>
+ <li><a href="tranches.html">Tranche Insights</a></li>
+ <li><a href="indices.html">Index Insights</a></li>
+ </ul>
</body>
</html>
diff --git a/risk_insight/templates/indices.html b/risk_insight/templates/indices.html
index aedfa799..45d9404d 100644
--- a/risk_insight/templates/indices.html
+++ b/risk_insight/templates/indices.html
@@ -5,7 +5,7 @@
<script type="text/javascript" src="{{ url_for('static', filename='jquery-2.1.1.min.js') }}"></script>
</head>
<body>
- <div id="graph1"
+ <div id="graph"
style="width:800px; height:500px;float:left;margin:auto">
</div>
<div style="margin-top:5em;display:inline-block">
@@ -25,6 +25,6 @@
<option value="10yr">10yr</option>
</select>
</div>
-<script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
+<script type="text/javascript" src="{{ url_for('static', filename='indices.js') }}"></script>
</body>
</html>
diff --git a/risk_insight/templates/tranches.html b/risk_insight/templates/tranches.html
index d91f2730..0a8df9ac 100644
--- a/risk_insight/templates/tranches.html
+++ b/risk_insight/templates/tranches.html
@@ -38,6 +38,6 @@
<option value="el">Expected Loss</option>
</select>
</div>
-<script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
+<script type="text/javascript" src="{{ url_for('static', filename='tranches.js') }}"></script>
</body>
</html>