Beispiel #1
0
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
Beispiel #2
0
def runBondFuncs():
    scheduleId = 'bond_schedule'
    startDate = datetime.date(2017, 8, 8)
    endDate = datetime.date(2023, 8, 8)
    tenor = '6M'
    calendar = 'China.IB'
    rc = p.py_Schedule(scheduleId, startDate, endDate, tenor, calendar)
    print rc
    bondId = 'Test_Bond'
    bondType = 'IB'
    notional = [100000000.0]
    coupons = [3.7]
    issueDate = startDate
    rc = p.py_FixedRateBond(bondId, 'Test bond', bondType, notional, coupons,
                            scheduleId, issueDate, calendar)
    print 'Created Bond %s' % rc
    rc = p.py_BondNextCashflowDate(bondId)
    print 'Next payment date: %s' % rc
    rc = p.py_BondNextCashflowAmount(bondId)
    print 'Next coupon amount %.2d' % rc
    curve = p.py_BuildCfetsCurve(curveName,
                                 anchorDate,
                                 indexName,
                                 tenors,
                                 rates,
                                 method,
                                 discCurveName=discCurveName)
    print 'Curve created: %s' % curve
    rc = p.py_BondPV(bondId, curveName)
    print 'Bond PV is ', '{:,.2f}'.format(rc)
    rc = p.py_BondFlowAnalysis(bondId, datetime.date(2018, 1, 2))
    print rc
Beispiel #3
0
    def _createCFETSCurve(self, curveName, asofDate, mktdata):
        tenors, rates = mktdata
        curve = p.py_BuildCfetsCurve(curveName, asofDate, self.indexName,
                                     tenors, rates, 'LinearZero')
        #         print 'Curve created: %s' % curve

        #        double check index fixings
        #         rc = p.py_IndexFixings(self.indexId, [asofDate], fwdCurveId=curveName)
        #         print 'Fixing on %s is %f' % (asofDate, rc[0])
        return curve
Beispiel #4
0
 def _createCfetsCurve(self):
     curve = p.py_BuildCfetsCurve(self.cfetsCurveName, self.anchorDate,
                                  self.indexName, self.curveTenors,
                                  self.curveRates, self.curveMethod)
     print '\n\nCurve created: %s' % curve
     return curve
Beispiel #5
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