diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/Dawn/__init__.py | 2 | ||||
| -rw-r--r-- | python/Dawn/models.py | 33 | ||||
| -rw-r--r-- | python/Dawn/templates/base.html | 16 | ||||
| -rw-r--r-- | python/Dawn/templates/future_blotter.html | 40 | ||||
| -rw-r--r-- | python/Dawn/views.py | 31 |
5 files changed, 108 insertions, 14 deletions
diff --git a/python/Dawn/__init__.py b/python/Dawn/__init__.py index a88b0301..87be366c 100644 --- a/python/Dawn/__init__.py +++ b/python/Dawn/__init__.py @@ -5,7 +5,7 @@ from sqlalchemy import MetaData app = Flask(__name__) app.config.from_envvar('CONF') -db = SQLAlchemy(app, metadata = MetaData(schema=app.config['SCHEMA'])) +db = SQLAlchemy(app, metadata=MetaData(schema=app.config['SCHEMA'])) if not app.debug: fh = logging.FileHandler(filename=app.config['LOGFILE']) diff --git a/python/Dawn/models.py b/python/Dawn/models.py index bb4ff002..4bda22d7 100644 --- a/python/Dawn/models.py +++ b/python/Dawn/models.py @@ -42,10 +42,15 @@ CDS_STRAT = ENUM('HEDGE_CSO', 'HEDGE_CLO', 'HEDGE_MAC', 'HEDGE_MBS', SWAPTION_STRAT = ENUM('IGPAYER', 'IGREC', 'HYPAYER', 'HYREC', name='swaption_strat') +FUTURE_STRAT = ENUM('M_STR_MAV', 'M_MTG_IO', 'M_STR_MEZZ', 'M_MTG_RW', 'SER_ITRXCURVE', + name='future_strat') + SWAPTION_TYPE = ENUM('PAYER', 'RECEIVER', name='swaption_type') REPO_TYPE = ENUM('REPO', 'REVERSE REPO', name='repo_type') +FUTURE_TYPE = ENUM('FUTURE', 'CFD', 'SYNTHETIC-FUTURE', 'LME-FORWARD', name='future_type') + CALL_NOTICE = ENUM('24H', '48H', '3D', '4D', '5D', '6D', '1W', '8D', '9D', '10D', '2W', '1M', '2M', name='call_notice') @@ -208,6 +213,34 @@ class SwaptionDeal(db.Model): currency = db.Column(CCY, nullable=False) counterparty = db.relationship(Counterparties) +class FutureDeal(db.Model): + __tablename__ = 'futures' + id = db.Column('id', db.Integer, primary_key=True) + dealid = db.Column(db.String(28)) + lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now()) + action = db.Column(ACTION) + folder = db.Column(FUTURE_STRAT, nullable=False) + custodian = db.Column(db.String(12), default='INTBR', nullable=False) + cashaccount = db.Column(db.String(10), default='IANSCLMAFU', nullable=False) + cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'), + info={'choices': [('IBKRNY', 'Interactive Brokers')], + 'label': 'counterparty'}, nullable=False) + trade_date = db.Column(db.Date, nullable=False) + settle_date = db.Column(db.Date, nullable=False) + buysell = db.Column(db.Boolean, nullable=False, info={'choices':[(0, 'sell'), (1, 'buy')], + 'coerce': lambda x: bool(int(x)) \ + if x is not None else x}) + bbg_ticker = db.Column(db.String(32), nullable=False) + quantity = db.Column(db.Float, nullable=False) + price = db.Column(db.Float, nullable=False) + commission = db.Column(db.Float) + swap_type = db.Column(FUTURE_TYPE, nullable=False) + security_desc = db.Column(db.String(32), nullable=False) + maturity = db.Column(db.Date, nullable=False) + currency = db.Column(CCY, nullable=False) + exchange = db.Column(db.String(3), default='CME', nullable=False) + counterparty = db.relationship(Counterparties) + BaseModelForm = model_form_factory(FlaskForm) class ModelForm(BaseModelForm): @classmethod diff --git a/python/Dawn/templates/base.html b/python/Dawn/templates/base.html index fea79a92..a17f98d3 100644 --- a/python/Dawn/templates/base.html +++ b/python/Dawn/templates/base.html @@ -24,9 +24,10 @@ aria-expanded="false">Blotter <span class="caret"></span> </a> <ul class="dropdown-menu"> - <li><a href="{{url_for('list_trades', kind = 'bond')}}">Bonds</a></li> - <li><a href="{{url_for('list_trades', kind = 'cds')}}">CDS</a></li> - <li><a href="{{url_for('list_trades', kind = 'swaption')}}">Swaptions</a></li> + <li><a href="{{url_for('list_trades', kind='bond')}}">Bonds</a></li> + <li><a href="{{url_for('list_trades', kind='cds')}}">CDS</a></li> + <li><a href="{{url_for('list_trades', kind='swaption')}}">Swaptions</a></li> + <li><a href="{{url_for('list_trades', kind='future')}}">Futures</a></li> </ul> </li> <li class="dropdown"> @@ -37,9 +38,10 @@ aria-expanded="false">Book <span class="caret"></span> </a> <ul class="dropdown-menu"> - <li><a href="{{url_for('trade_manage', kind = 'bond')}}">Bonds</a></li> - <li><a href="{{url_for('trade_manage', kind = 'cds')}}">CDS</a></li> - <li><a href="{{url_for('trade_manage', kind = 'swaption')}}">Swaptions</a></li> + <li><a href="{{url_for('trade_manage', kind='bond')}}">Bonds</a></li> + <li><a href="{{url_for('trade_manage', kind='cds')}}">CDS</a></li> + <li><a href="{{url_for('trade_manage', kind='swaption')}}">Swaptions</a></li> + <li><a href="{{url_for('trade_manage', kind='future')}}">Futures</a></li> </ul> </li> <li class="dropdown"> @@ -51,7 +53,7 @@ </a> <ul class="dropdown-menu"> <li><a href="../counterparties">List</a></li> - <li><a href="{{url_for('edit_counterparty', cpcode= None)}}">New</a></li> + <li><a href="{{url_for('edit_counterparty', cpcode=None)}}">New</a></li> </ul> </li> </ul> diff --git a/python/Dawn/templates/future_blotter.html b/python/Dawn/templates/future_blotter.html new file mode 100644 index 00000000..a436651a --- /dev/null +++ b/python/Dawn/templates/future_blotter.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% block content %} +<table class="table table-striped"> + <thead> + <tr> + <td>Deal ID</td> + <td>Trade Date</td> + <td>Settle Date</td> + <td>Buy/Sell</td> + <td>Quantity</td> + <td>Type</td> + <td>Maturity</td> + <td>Price</td> + <td>Commission</td> + <td>Description</td> + <td>Ticker</td> + <td>Counterparty</td> + <td>Strategy</td> + </tr> + </thead> + {% for trade in trades %} + <tr> + <td><a href="{{url_for('trade_manage', tradeid=trade.id, kind='future')}}">{{trade.dealid}}</a></td> + <td>{{trade.trade_date}}</td> + <td>{{trade.settle_date}}</td> + <td>{% if trade.buysell %}Buy{% else %}Sell{% endif %}</td> + <td>{{trade.quantity}}</td> + <td>{{trade.swap_type}}</td> + <td>{{trade.maturity}}</td> + <td>{{trade.price}}</td> + <td>{{trade.commission}}</td> + <td>{{trade.security_desc}}</td> + <td>{{trade.bbg_ticker}}</td> + <td><a href="{{url_for('edit_counterparty', + cpcode=trade.counterparty.code)}}">{{trade.counterparty.name}}</a></td> + <td>{{trade.folder}}</td> + </tr> + {% endfor %} +</table> +{% endblock %} diff --git a/python/Dawn/views.py b/python/Dawn/views.py index d1cbee24..dc2e2c25 100644 --- a/python/Dawn/views.py +++ b/python/Dawn/views.py @@ -1,6 +1,6 @@ from flask import (request, render_template, redirect, url_for, send_from_directory, send_file, g, jsonify) -from .models import ModelForm, BondDeal, CDSDeal, SwaptionDeal, Counterparties +from .models import ModelForm, BondDeal, CDSDeal, SwaptionDeal, FutureDeal, Counterparties from sqlalchemy.exc import IntegrityError from wtforms.fields import BooleanField import pandas as pd @@ -20,9 +20,17 @@ fed_cal = get_calendar('USFederalHolidayCalendar') bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday) bus_day = CustomBusinessDay(calendar=bond_cal()) -def cp_choices(): - return Counterparties.query.order_by('name').\ - with_entities(Counterparties.code, Counterparties.name) +def cp_choices(kind='bond'): + if kind == 'bond': + return (Counterparties.query.order_by('name'). + with_entities(Counterparties.code, Counterparties.name)) + elif kind == 'future': + return [] + elif kind == 'cds': + return (Counterparties.query. + order_by('name'). + filter(Counterparties.name.ilike('%CDS%')). + with_entities(Counterparties.code, Counterparties.name)) def get_queue(): q = getattr(g, 'queue', None) @@ -75,6 +83,12 @@ class SwaptionForm(ModelForm): include_foreign_keys = True exclude = ['dealid', 'lastupdate'] +class FutureForm(ModelForm): + upload_globeop = BooleanField(label="Upload to globeop?") + class Meta: + model = FutureDeal + include_foreign_keys = True + exclude = ['dealid', 'lastupdate'] def get_deal(kind): if kind == 'cds': @@ -83,6 +97,8 @@ def get_deal(kind): return BondDeal elif kind == 'swaption': return SwaptionDeal + elif kind == 'future': + return FutureDeal else: raise RuntimeError('Unknown Deal type') @@ -93,6 +109,8 @@ def _get_form(kind): return BondForm elif kind == 'swaption': return SwaptionForm + elif kind == 'future': + return FutureForm else: raise RuntimeError('Unknown Deal type') @@ -144,7 +162,8 @@ def save_ticket(trade, old_ticket_name): def trade_manage(tradeid, kind): trade = get_trade(tradeid, kind) form = _get_form(kind)() - form.cp_code.choices = form.cp_code.choices + list(cp_choices()) + + form.cp_code.choices = form.cp_code.choices + list(cp_choices(kind)) if kind == 'bond': old_ticket_name = trade.ticket if form.validate_on_submit(): @@ -169,7 +188,7 @@ def trade_manage(tradeid, kind): return redirect(url_for('list_trades', kind=kind)) else: form = get_form(trade, kind) - form.cp_code.choices = form.cp_code.choices + list(cp_choices()) + form.cp_code.choices = form.cp_code.choices + list(cp_choices(kind)) return render_template('trade_entry.html', form=form, action_url = url_for('trade_manage', tradeid=tradeid, kind=kind)) |
