def getMarkets(filename, trigger): global marketdata, markets global tradedate, settle print('\ngetMarkets') mkt = MarketFile(filename).read update = True if marketdata: update = not (mkt['timestamp'] == marketdata.get('timestamp', ' ')) if update: marketdata = mkt mm, dd, yy = marketdata.get('tradedate', (None, None, None)) tradedate = ql.toDate(dd, mm, yy) if not tradedate: tradedate = ql.Date.todaysDate() mm, dd, yy = marketdata.get('swapsettle', (None, None, None)) swapsettle = ql.toDate(dd, mm, yy) if not swapsettle: swapsettle = ql.TARGET().advance(tradedate, 2, ql.Days) if not markets: print("initializing curves") markets = marketcurves() markets.update(tradedate, swapsettle, marketdata) return marketdata.get('timestamp', None)
global markets try: spreaddata = dict(zip(tenors, spreaddata)) markets.modelCurve(spreaddata) except: raise return ('model') if __name__ == '__main__': print("\n\nRunning script....\n") getMarkets('pfile.close', 1) print("\nTest...") call = ql.Call(ql.toDate(1, 1, 2021), 100.0) bnd = ql.SimpleBond(.05, ql.toDate(1,1,2040), callfeature=call) asw = bnd.assetSwap() val = asw.value(markets.govt.termstructure, vol=.16) print(" one...") spreaddata = {} for tenor in markets.mmascale.bonds: ratio = markets.bma.parRatio(tenor) bnd = ql.SimpleBond(.05, markets.mmascale.bonds[tenor].maturity, callfeature = call) asw = bnd.assetSwap() yld = markets.mmascale.bondyields[tenor] prc = bnd.toPrice(yld)
from os import path import bgpy.QL as QL from bgpy.xldb import XLOut from alprion import DROPBOX, SHAREDDATA dt = QL.Date(1, 1, 1988) fileout = XLOut(path.join(DROPBOX, "Analysis", "HolidayHistory.xls")) calendars = (QL.USGovernmentBond, QL.USNYSE, QL.UnitedStates()) nullCal = QL.TARGET() enddt = QL.Date(31, 12, 2049) row_n = 1 while dt <= enddt: dt = nullCal.advance(dt, 1, QL.Days, QL.Following) fileout.write(QL.toPyDate(dt), row_n, 0, 0, format="date") for col_n in range(len(calendars)): fileout.write(calendars[col_n].isBusinessDay(dt), row_n, col_n + 1, 0) row_n += 1 print("\nNumber of rows: %s" % row_n) fileout.save()