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)