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_couponFreq_Zero(self): testData = cb.jsonFileOpen('zeroCouponFreq.json') self.assertEqual(cb.inputChecker(testData), 1)
def test_CouponTiming(self): testData = cb.jsonFileOpen('invalidCouponTiming.json') # inputChecker should return 1 if exception is caught self.assertEqual(cb.inputChecker(testData), 1)
def test_InvalidValues(self): testData = cb.jsonFileOpen('invalidTest.json') # inputChecker should return 6 if all invalid values caught self.assertEqual(cb.inputChecker(testData), 6)
def tests_nonDictYieldCurve(self): testData = cb.jsonFileOpen('nonDictYieldCurve.json') # inputChecker returns 1 if negative rate in yield curve is caught self.assertEqual(cb.inputChecker(testData), 1)
def test_NegativeYieldYear(self): testData = cb.jsonFileOpen('negativeYieldYear.json') # inputChecker returns 1 if negative year in yield curve is caught self.assertEqual(cb.inputChecker(testData), 1)
def test_NegativeValues(self): testData = cb.jsonFileOpen('negativeTest.json') # inputChecker should return 5 if all invalid values caught self.assertEqual(cb.inputChecker(testData), 5)