def main(): #with open( sys.argv[1] ) as jsonFile: #data = json.load( jsonFileName ) #test_jsonFileOpen( sys.argv[1] ) inputData = cb.jsonFileOpen( sys.argv[1] ) # check valid inputs if cb.inputChecker( inputData ) > 0: return 1 #first calculate coupon payment couponPay = cb.singleCouponPayment( inputData['parAmount'], inputData[ 'coupon' ], inputData[ 'couponFrequency' ] ) # calculate total number of periods totalPeriods = inputData[ 'yearsUntilMaturity' ] * inputData[ 'couponFrequency' ] # convert yield curve to two arrays for yield interpolation/extrapolation tenorArr, yieldArr = cb.dictToArr( inputData[ 'yieldCurve' ] ) # calculate bond yield from yield curve, return value in percentage. bondYield = cb.bondYieldCalc(tenorArr, yieldArr, inputData[ 'yearsUntilMaturity' ] ) # convert bondYield to decimal value bondYield/=100 # calculate discounted coupon value discountCouponTot = cb.couponVal( couponPay, totalPeriods, bondYield, inputData[ 'couponFrequency' ], inputData[ 'couponTiming' ] ) # calculate discounted bond value discountBondVal = cb.bondValCalc( inputData[ 'parAmount' ], bondYield, inputData[ 'couponFrequency' ], totalPeriods ) #add output of couponVal && bondVal to get present val presentVal = discountCouponTot + discountBondVal # print output print( '%.4f'%presentVal )
def test_couponVal_ZeroPeriod_End(self): self.assertEqual(float('%.4f' % cb.couponVal(15.0, 0, 0.01, 2, 'end')), 0.0000)
def test_couponVal_End(self): self.assertEqual(float('%.4f' % cb.couponVal(15.0, 4, 0.01, 2, 'end')), 59.2574)
def test_couponVal_ZeroPeriod_Start(self): self.assertEqual( float('%.4f' % cb.couponVal(15.0, 0, 0.01, 2, 'start')), 0.0000)
def test_couponVal_Start(self): self.assertEqual( float('%.4f' % cb.couponVal(15.0, 4, 0.01, 2, 'start')), 59.5537)