# (intra-day change) schedule has hash id, confirmed schedule is saved to db. # event needs to be confirmed by trader # event needs to be saved in db # how to deal with T+N trade? cash vs usable cash # how to deal with collateral? # how to deal with schedules from close event? # open event->settle or cancel event->close/maturity/default event->settle/recovery event => position change # need the concept of "roll" deal in order to drive the life cycle # need "trade blotter" to show live position, and allow user to close/collateral trades # instrument generates schedule, position is a list of amount and instrument pairs # events generate position # identify schedule by (dealID, instID, scheduleDate, amount, reason) EVENT_TYPE = enum(OPEN=0, OPEN_SETTLE=1, CLOSE=2, CLOSE_SETTLE=3, DEFAULT=4, CASH_FLOW=5, COUPON=6) class Book: def __init__(self, name_cn_short, name_cn_full, startDate=None, trader="", windcode=""): self.name_cn_full = name_cn_full self.name_cn_short = name_cn_short self.startDate = startDate self.trader = trader self.windcode = windcode class Deposit: def __init__(self, tradeDate, bookID, amount, yld, matDate, dcc, comment=""): self.tradeDate = tradeDate self.bookID = bookID
# -*- coding: utf-8 -*- from env import enum import hashlib InstType = enum(BOND=1, MMF=2, REPO=3, DEPOSITE=4, CASH=5) Market = enum(OTHER=0, IB=1, SH=2, SZ=3) Ccy = enum(CNY=1, CNH=2, USD=3) Role = enum(Trader=1,Sales=2,Risk=3,Research=4) Auth = enum(READ_ONLY=1, READ_WRITE=2, NO_VIEW=3) class Instrument: def __init__(self, id, insttype, ccy = Ccy.CNY, isOTC=True, maturityDate=None): self.id = id self.insttype = insttype self.ccy = ccy self.isOTC = isOTC self.maturityDate = maturityDate def Price(self, asOfDate): raise NotImplementedError('Pricing method has not been implemented') class Deposite(Instrument): def __init__(self, counterparty, maturityDate, ccy = Ccy.CNY): Instrument.__init__(self, counterparty.id, InstType.DEPOSITE, ccy, True, maturityDate) class Deal: def __init__(self, inst, tradeDate, amount, tradePrice, book, trader, settleDate=None): self.inst = inst self.tradeDate = tradeDate self.amount = amount self.tradePrice = tradePrice
# how to deal with T+N trade? cash vs usable cash # how to deal with collateral? # how to deal with schedules from close event? # open event->settle or cancel event->close/maturity/default event->settle/recovery event => position change # need the concept of "roll" deal in order to drive the life cycle # need "trade blotter" to show live position, and allow user to close/collateral trades # instrument generates schedule, position is a list of amount and instrument pairs # events generate position # identify schedule by (dealID, instID, scheduleDate, amount, reason) EVENT_TYPE = enum(OPEN=0, OPEN_SETTLE=1, CLOSE=2, CLOSE_SETTLE=3, DEFAULT=4, CASH_FLOW=5, COUPON=6) class Book: def __init__(self, name_cn_short, name_cn_full, startDate=None, trader='', windcode=''): self.name_cn_full = name_cn_full self.name_cn_short = name_cn_short self.startDate = startDate
# -*- coding: utf-8 -*- from env import enum import hashlib InstType = enum(BOND=1, MMF=2, REPO=3, DEPOSITE=4, CASH=5) Market = enum(OTHER=0, IB=1, SH=2, SZ=3) Ccy = enum(CNY=1, CNH=2, USD=3) Role = enum(Trader=1, Sales=2, Risk=3, Research=4) Auth = enum(READ_ONLY=1, READ_WRITE=2, NO_VIEW=3) class Instrument: def __init__(self, id, insttype, ccy=Ccy.CNY, isOTC=True, maturityDate=None): self.id = id self.insttype = insttype self.ccy = ccy self.isOTC = isOTC self.maturityDate = maturityDate def Price(self, asOfDate): raise NotImplementedError('Pricing method has not been implemented') class Deposite(Instrument): def __init__(self, counterparty, maturityDate, ccy=Ccy.CNY): Instrument.__init__(self, counterparty.id, InstType.DEPOSITE, ccy,