def addFixings(): print '\n\n' curve = p.py_BuildCfetsCurve(curveName, anchorDate, indexName, tenors, rates, method, discCurveName=discCurveName) print 'Curve created: %s' % curve # Create a swap to get the index object att = { 'endDateTenor': '5Y', 'notional': 50000000.0, 'fixedRate': 0.035, 'discCurveId': curveName, 'fwdCurveId': curveName } p.py_CreateIRSwap(swapId, {'PredefinedConvention': 'CNY_REPO_7D'}, anchorDate, **att) fixings = readPilotScopeIndexFixings("../../data/fr007_fixing.csv") print '%s fixings loaded' % len(fixings) rc = p.py_IndexAddFixings(indexId, fixings.keys(), fixings.values()) print 'Fixings added to %s' % rc rc = p.py_IndexFixings(indexId, [datetime.date(2017, 12, 18)], fwdCurveId=curveName) print rc
def createSwap(swapId, startDate, term, fixRate, notional=100000000.0): '''Create a contract so that it has a payment endDate ''' att = {'endDateTenor': term, 'notional': notional, 'fixedRate': fixRate} rc = p.py_CreateIRSwap(swapId, {'PredefinedConvention': 'CNY_REPO_7D'}, startDate, **att) return rc
def _getIndexInfo(self, convention='CNY_REPO_7D'): # create a dummy contract, just to get the index object att = { 'endDateTenor': '1Y', 'notional': 50000000.0, 'fixedRate': 0.035 } dummyId = '_dummy' startDate = datetime.date(2017, 12, 1) p.py_CreateIRSwap(dummyId, {'PredefinedConvention': convention}, startDate, **att) info = p.py_SwapInfo([dummyId], 0, startDate) indexId = info['']['IndexObjectID'] indexInfo = info[indexId + '_Info'] print '\n\nIndex Info: %s' % indexInfo return indexInfo
def _addFR007IndexFixings(self): # create a dummy contract, just to get the index object att = { 'endDateTenor': '1Y', 'notional': 50000000.0, 'fixedRate': 0.035 } dummyId = '_dummy' startDate = datetime.date(2017, 12, 1) p.py_CreateIRSwap(dummyId, {'PredefinedConvention': 'CNY_REPO_7D'}, startDate, **att) info = p.py_SwapInfo([dummyId], 0, startDate) indexId = info['']['IndexObjectID'] # print '\n\nIndex object Id: %s' % indexId self.indexId = indexId fixings = self.readPeakIndexFixings("../../data/fr007_fixing.csv") # print '\n\n%s fixings loaded' % len(fixings) rc = p.py_IndexAddFixings(indexId, fixings.keys(), fixings.values())
def runSwapInfo(): # create a dummy swap, just to get the index object att = {'endDateTenor': '5Y', 'notional': 50000000.0, 'fixedRate': 0.035} dummyId = '_dummy' p.py_CreateIRSwap(dummyId, {'PredefinedConvention': 'CNY_REPO_7D'}, startDate, **att) rc = p.py_SwapInfo([dummyId], 0, startDate) print '\n\nSwap Info:' pprint.pprint(rc, width=1000) indexId = rc['']['IndexObjectID'] print '\n\nIndex object Id: %s' % indexId fixings = readPeakIndexFixings("../../data/fr007_fixing.csv") print '\n\n%s fixings loaded' % len(fixings) rc = p.py_IndexAddFixings(indexId, fixings.keys(), fixings.values()) print '\nFixings added to %s' % rc d = datetime.date(2017, 12, 18) rc = p.py_IndexFixings(indexId, [d]) print '\nFixings without curve for %s is %s' % (d, rc) rc = p.py_CreateIRSwap(swapId, {'PredefinedConvention': 'CNY_REPO_7D'}, startDate, **att) rc = p.py_SwapInfo([swapId], 0, anchorDate) print '\n\nSwapInfo:' pprint.pprint(rc, width=1000) curve = p.py_BuildCfetsCurve(curveName, anchorDate, indexName, tenors, rates, method, discCurveName=discCurveName) print '\n\nCurve created: %s' % curve d1 = startDate + datetime.timedelta(days=7) df = p.py_YieldTSDiscount(curveName, [startDate, d1], allowExtrapolation=True) print 'Discount factor for %s is %s' % ([startDate, d1], df) rc = p.py_IndexFixings(indexId, [d], fwdCurveId=curveName) print '\nFixings with curve for %s is %s' % (d, rc) npv = p.py_SwapLegNPV([swapId], curveName, discCurveName, anchorDate, True, debugLevel=2) print '\nSwap NPV = %s' % npv rc = p.py_SwapLegAnalysis(swapId, 0, afterDate=datetime.date(2018, 1, 25), forwardCurveId=curveName, discountCurveId='', afterDateInclusive=False, forecastTodaysFixing=True, useSqlFriendlyColHeaders=True, selectedColumns='All', toDate=datetime.date(2100, 12, 31)) print '\nSwapLegAnalysis:' pprint.pprint(rc, width=1000) rc = p.py_IndexName(indexId) print '\nIndex Name "%s"' % rc