diff options
Diffstat (limited to 'python/Dawn')
| -rw-r--r-- | python/Dawn/templates/swaption_blotter.html | 8 | ||||
| -rw-r--r-- | python/Dawn/views.py | 57 |
2 files changed, 60 insertions, 5 deletions
diff --git a/python/Dawn/templates/swaption_blotter.html b/python/Dawn/templates/swaption_blotter.html index ec827059..75e05ca0 100644 --- a/python/Dawn/templates/swaption_blotter.html +++ b/python/Dawn/templates/swaption_blotter.html @@ -11,10 +11,11 @@ <td>Type</td> <td>Expiry</td> <td>Strike</td> - <td>Price</td> + <td>Fee</td> <td>Description</td> <td>Red Code</td> <td>Counterparty</td> + <td>Trade Type</td> <td>Strategy</td> </tr> </thead> @@ -28,11 +29,12 @@ <td>{{trade.option_type}}</td> <td>{{trade.expiration_date}}</td> <td>{{trade.strike}}</td> - <td>{{trade.price}}</td> + <td>{{"{0:,.2f}".format(trade.fee)}}</td> <td>{{trade.security_desc}}</td> <td>{{trade.security_id}}</td> <td><a href="{{url_for('edit_counterparty', - cpcode=trade.counterparty.code)}}">{{trade.counterparty.name}}</a></td> + cpcode=trade.cp_code)}}">{{trade.name}}</a></td> + <td>{{trade.trade_type}}</td> <td>{{trade.folder}}</td> </tr> {% endfor %} diff --git a/python/Dawn/views.py b/python/Dawn/views.py index e514c81d..63ddce28 100644 --- a/python/Dawn/views.py +++ b/python/Dawn/views.py @@ -32,6 +32,8 @@ from .models import ( Accounts, ) +from sqlalchemy import case, func +from sqlalchemy.orm import aliased from sqlalchemy.exc import IntegrityError from wtforms.fields import BooleanField @@ -479,8 +481,59 @@ def list_trades(kind): app.logger.error(e) abort(404) else: - trade_list = Deal.query.order_by(Deal.trade_date.desc(), Deal.id.desc()) - return render_template(f"{kind}_blotter.html", trades=trade_list.all()) + Orig_cp = aliased(Counterparties) + Term_cp = aliased(Counterparties) + if kind not in ["swaption", "cds"]: + trade_list = Deal.query.order_by(Deal.trade_date.desc(), Deal.id.desc()) + else: + trade_list = ( + Deal.query.join(Orig_cp, Deal.counterparty) + .join(Term_cp, Deal.termination_counterparty) + .with_entities( + Deal.id, + Deal.dealid, + func.coalesce(Deal.termination_date, Deal.trade_date).label( + "trade_date" + ), + Deal.notional, + Deal.option_type, + Deal.expiration_date, + Deal.strike, + case( + [(Deal.termination_cp.is_(None), Deal.buysell)], + else_=~Deal.buysell, + ).label("buysell"), + ( + case( + [ + ( + Deal.termination_cp.is_(None), + Deal.notional * Deal.price / 100, + ) + ], + else_=Deal.termination_fee, + ) + * case([(Deal.buysell, 1.0)], else_=-1.0) + ).label("fee"), + Deal.security_desc, + Deal.security_id, + func.coalesce(Orig_cp.code, Term_cp.code).label("cp_code"), + func.coalesce(Orig_cp.name, Term_cp.name).label("name"), + case( + [ + (Deal.termination_cp.is_(None), "New"), + (Deal.termination_cp == Deal.cp_code, "Termination"), + ], + else_="Assignment", + ).label("trade_type"), + Deal.folder, + ) + .order_by(Deal.trade_date.desc()) + .order_by( + func.coalesce(Deal.termination_date, Deal.trade_date), Deal.dealid + ) + ) + return render_template(f"{kind}_blotter.html", trades=trade_list) @app.route("/tickets/<int:tradeid>") |
