def _priceContract(self, curve, forecastTodaysFixing=False, **kwargs): npv = p.py_SwapLegNPV([self.contract], curve, curve, forecastTodaysFixing=forecastTodaysFixing, **kwargs) print 'Swap NPV = %s' % npv return npv
def _priceContract(self, contract, curve, discCurve=None, forecastTodaysFixing=False, **kwargs): discCurve = discCurve or curve npv = p.py_SwapLegNPV([contract], curve, discCurve, forecastTodaysFixing=forecastTodaysFixing, **kwargs) print 'Swap NPV = %s' % npv return npv
def calculateSmoothPV(self, contract, curve, discCurve=None, forecastTodaysFixing=False, **kwargs): """ calculate the PV using the smooth curve used by risk calculation. this should be the same as the base pv output from the risk calculation """ riskCurveId = '__smoothPV_' discCurve = discCurve or curve rc = self._buildSwapCurve(riskCurveId, self.endDate, self.indexName, curve, discCurve, self.riskTenors, self.startTenors) fwdCurveName, discCurveName, curveEngineName = rc[0] rc = p.py_SwapLegNPV([contract], fwdCurveName, discCurveName, forecastTodaysFixing=forecastTodaysFixing, **kwargs) p.py_DeleteObjects([riskCurveId]) return rc[0][0]
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