diff options
Diffstat (limited to 'python/Dawn/views.py')
| -rw-r--r-- | python/Dawn/views.py | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py index c33e12f2..983e7ca9 100644 --- a/python/Dawn/views.py +++ b/python/Dawn/views.py @@ -483,7 +483,7 @@ def list_trades(kind): else: Orig_cp = aliased(Counterparties) Term_cp = aliased(Counterparties) - if kind not in ["swaption"]: + if kind not in ["cds", "swaption"]: trade_list = Deal.query.order_by(Deal.trade_date.desc(), Deal.id.desc()) else: trade_list = ( @@ -495,33 +495,11 @@ def list_trades(kind): func.coalesce(Deal.termination_date, Deal.trade_date).label( "trade_date" ), - (func.coalesce(Deal.termination_date, Deal.settle_date)).label( - "settle_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"), + func.coalesce(Term_cp.code, Orig_cp.code).label("cp_code"), + func.coalesce(Term_cp.name, Orig_cp.name).label("name"), case( [ (Deal.termination_cp.is_(None), "New"), @@ -536,6 +514,50 @@ def list_trades(kind): Deal.dealid, ) ) + if kind == "swaption": + trade_list = trade_list.add_columns( + case( + [(Deal.termination_cp.is_(None), Deal.settle_date)], else_=None + ).label("settle_date"), + 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 + * (2 * Deal.buysell.cast(db.Integer) - 1.0), + ) + ], + else_=-Deal.termination_fee, + ) + ).label("fee"), + ) + elif kind == "cds": + trade_list = trade_list.add_columns( + case( + [(Deal.termination_cp.is_(None), Deal.protection.cast(db.String))], + else_=case([(Deal.protection == "Buyer", "Seller")], else_="Buyer"), + ).label("protection"), + Deal.orig_attach, + Deal.orig_detach, + Deal.attach, + Deal.detach, + ( + case( + [(Deal.termination_cp.is_(None), Deal.upfront)], + else_=-Deal.termination_fee, + ) + ).label("upfront"), + Deal.ref, + ) return render_template(f"{kind}_blotter.html", trades=trade_list) |
