Ejemplo n.º 1
0
    def setUp(self):
        self.settlement_days = 3
        self.face_amount = 100.0
        self.redemption = 100.0
        self.issue_date = CAL.Date(2,1,2008)
        self.maturity_date = CAL.Date(2,1,2018)
        self.calendar = CAL.UnitedStates(CAL.UnitedStates.GovernmentBond)
        self.day_counter = CAL.ActualActual(CAL.ActualActual.Bond)
        self.sched = CAL.Schedule(self.issue_date, self.maturity_date,
                                       CAL.Period(CAL.Semiannual), self.calendar,
                                       CAL.Unadjusted, CAL.Unadjusted,
                                       CAL.DateGeneration.Backward, False)
        self.coupons = [0.05]

        self.bond = CAL.FixedRateBond(self.settlement_days, self.face_amount,
                                           self.sched, self.coupons, self.day_counter,
                                           CAL.Following, self.redemption,
                                           self.issue_date)

        self.flat_forward = CAL.FlatForward(self.issue_date,
                                            self.coupons[0], self.day_counter,
                                            CAL.Compounded, CAL.Semiannual)
        self.term_structure_handle = CAL.RelinkableYieldTermStructureHandle(self.flat_forward)
        bondEngine = CAL.DiscountingBondEngine(self.term_structure_handle)
        self.bond.setPricingEngine(bondEngine)
Ejemplo n.º 2
0
    def runTest(self):
        "Testing date arithmetics"
        date = CAL.Date_minDate()

        dold = date.dayOfMonth()
        mold = date.month()
        yold = date.year()

        while date < CAL.Date_maxDate():
            date += 1

            d = date.dayOfMonth()
            m = date.month()
            y = date.year()

            # check if skipping any date
            if not ((d == dold + 1 and m == mold and y == yold) or
                    (d == 1 and m == mold + 1 and y == yold) or
                    (d == 1 and m == 1 and y == yold + 1)):
                self.fail("""
wrong day, month, year increment
    date: %(t)s
    day, month, year: %(d)d, %(m)d, %(y)d
    previous:         %(dold)d, %(mold)d, %(yold)d
                """ % locals())
            dold = d
            mold = m
            yold = y
Ejemplo n.º 3
0
    def testObservable(self):
        "Testing observability of stocks"
        global flag
        flag = None
        me1 = CAL.SimpleQuote(0.0)
        h = CAL.RelinkableQuoteHandle(me1)
        s = CAL.Stock(h)
        s.NPV()

        obs = CAL.Observer(raiseFlag)
        obs.registerWith(s)

        me1.setValue(3.14)
        if not flag:
            self.fail("Observer was not notified of instrument change")

        s.NPV()
        flag = None
        me2 = CAL.SimpleQuote(0.0)
        h.linkTo(me2)
        if not flag:
            self.fail("Observer was not notified of instrument change")

        s.NPV()
        flag = None
        s.freeze()
        me2.setValue(2.71)
        if flag:
            self.fail("Observer was notified of frozen instrument change")
        s.unfreeze()
        if not flag:
            self.fail("Observer was not notified of instrument change")
Ejemplo n.º 4
0
def calcuatingBondAnalytics(settlementDate,
                            startDate,
                            maturity,
                            period,
                            coupons,
                            benchmarkYield=0.03,
                            repeat=1):

    yieldDayCounter = CAL.Actual365NoLeap()
    compoundingMethod = CAL.Compounded
    frequency = CAL.Annual

    # Do the unnecessary repeating to test on performance
    for i in xrange(repeat):
        myBond = CAL.CTBFixedBond(issueDate=startDate,
                                  settlementDays=1,
                                  faceAmount=100.0,
                                  startDate=startDate,
                                  maturity=maturity,
                                  tenor=period,
                                  coupons=coupons)

        # Bond analytics
        cleanPrice = myBond.cleanPrice(benchmarkYield, yieldDayCounter,
                                       compoundingMethod, frequency,
                                       settlementDate)
        accruedAmount = myBond.accruedAmount(settlementDate)
        conversionFactor1403 = myBond.conversionFactor(2014, CAL.March)
        conversionFactor1406 = myBond.conversionFactor(2014, CAL.June)
        conversionFactor1409 = myBond.conversionFactor(2014, CAL.September)
        macaulayDuration = CAL.BondFunctions.duration(
            myBond, benchmarkYield, yieldDayCounter, compoundingMethod,
            frequency, CAL.Duration.Macaulay, settlementDate)
        modifiedDuration = CAL.BondFunctions.duration(
            myBond, benchmarkYield, yieldDayCounter, compoundingMethod,
            frequency, CAL.Duration.Modified, settlementDate)
        convexity = CAL.BondFunctions.convexity(myBond, benchmarkYield,
                                                yieldDayCounter,
                                                compoundingMethod, frequency,
                                                settlementDate)
        PV01 = -CAL.BondFunctions.basisPointValue(
            myBond, benchmarkYield, yieldDayCounter, compoundingMethod,
            frequency, settlementDate)

    return {
        "Benchmark Yield": round(benchmarkYield, 4),
        "Clean Price": round(cleanPrice, 4),
        "Accrued Interest": round(accruedAmount, 4),
        "CF (TF1403)": round(conversionFactor1403, 4),
        "CF (TF1406)": round(conversionFactor1406, 4),
        "CF (TF1409)": round(conversionFactor1409, 4),
        "Macaulay Duration": round(macaulayDuration, 4),
        "Modified Duration": round(modifiedDuration, 4),
        "Convexity": round(convexity, 4),
        "PV01": round(PV01, 4)
    }
Ejemplo n.º 5
0
 def testObservable(self):
     "Testing observability of market elements"
     global flag
     flag = None
     me = CAL.SimpleQuote(0.0)
     obs = CAL.Observer(raiseFlag)
     obs.registerWith(me)
     me.setValue(3.14)
     if not flag:
         self.fail("Observer was not notified of market element change")
Ejemplo n.º 6
0
 def testDirtyPrice(self):
     """ Testing FixedRateBond dirty price. """
     self.assertEqual(round(self.bond.dirtyPrice(0.05, self.day_counter, CAL.Compounded,
                                                 CAL.Semiannual, self.issue_date), 4),
                      99.9964)
     self.assertEqual(round(self.bond.dirtyPrice(0.05, self.day_counter, CAL.Compounded,
                                                 CAL.Semiannual, self.issue_date +
                                                 CAL.Period(1,CAL.Months)), 4),
                      100.4179)
     self.assertEqual(round(self.bond.dirtyPrice(0.06, self.day_counter, CAL.Compounded,
                                                 CAL.Semiannual, self.issue_date +
                                                 CAL.Period(1,CAL.Months)), 4),
                      93.0244)
Ejemplo n.º 7
0
    def testCleanPrice(self):
        """ Testing FixedRateBond clean price. """
        self.assertEqual(round(self.bond.cleanPrice(0.05, self.day_counter, CAL.Compounded,
                                                    CAL.Semiannual, self.issue_date), 4),
                         99.9964)
        self.assertEqual(round(self.bond.cleanPrice(0.05, self.day_counter, CAL.Compounded,
                                                    CAL.Semiannual, self.issue_date +
                                                    CAL.Period(1, CAL.Months)), 4),
                         99.9921)

        self.assertEqual(round(self.bond.cleanPrice(0.06, self.day_counter, CAL.Compounded,
                                                    CAL.Semiannual, self.issue_date +
                                                    CAL.Period(1,CAL.Months)), 4),
                         92.5985)
Ejemplo n.º 8
0
 def testObservableHandle(self):
     "Testing observability of market element handles"
     global flag
     flag = None
     me1 = CAL.SimpleQuote(0.0)
     h = CAL.RelinkableQuoteHandle(me1)
     obs = CAL.Observer(raiseFlag)
     obs.registerWith(h)
     me1.setValue(3.14)
     if not flag:
         self.fail("Observer was not notified of market element change")
     flag = None
     me2 = CAL.SimpleQuote(0.0)
     h.linkTo(me2)
     if not flag:
         self.fail("Observer was not notified of market element change")
Ejemplo n.º 9
0
    def setUp(self):
        self.settlement_days = 3
        self.face_amount = 100.0
        self.redemption = 100.0
        self.quote_handle = CAL.QuoteHandle(CAL.SimpleQuote(100.0))

        self.issue_date = CAL.Date(2, 1, 2008)
        self.maturity_date = CAL.Date(2, 1, 2018)
        self.calendar = CAL.UnitedStates(CAL.UnitedStates.GovernmentBond)
        self.day_counter = CAL.ActualActual(CAL.ActualActual.Bond)
        self.sched = CAL.Schedule(self.issue_date, self.maturity_date,
                                  CAL.Period(CAL.Semiannual), self.calendar,
                                  CAL.Unadjusted, CAL.Unadjusted,
                                  CAL.DateGeneration.Backward, False)
        self.coupons = [0.05]

        self.bond_helper = CAL.FixedRateBondHelper(
            self.quote_handle, self.settlement_days, self.face_amount,
            self.sched, self.coupons, self.day_counter, CAL.Following,
            self.redemption, self.issue_date)
Ejemplo n.º 10
0
    def key_dvice_by_two_and_shift_in_ks_and_shift_in_ks(key):

        c = key[:len(key) // 2]
        d = key[len(key) // 2:]
        print("1c :", c)
        print("1d :", d)
        print()
        shift_len = 7
        ks_cal = CAL.CAL()
        c = ks_cal.shift_cal(c, shift_len)
        print("2c :", c)
        d = ks_cal.shift_cal(d, shift_len)
        print("2d :", d)
        res = []
        res.append(c)
        res.append(d)
        res = "".join(res)
        return res
Ejemplo n.º 11
0
 def testTrapezoid(self):
     "Testing trapezoid integration"
     self.singleTest(CAL.TrapezoidIntegralDefault(1.0e-4, 1000))
Ejemplo n.º 12
0
 def testSegment(self):
     "Testing segment integration"
     self.singleTest(CAL.SegmentIntegral(10000))
Ejemplo n.º 13
0
def convo():
    os.system("say -v " + voice + " How can I be of service?")
    # obtain audio from the microphone
    counter = 0
    r = sr.Recognizer()
    userIn = ""
    with sr.Microphone() as source:
        print("Say something!")
        audio = r.listen(source)

    # recognize speech using Google Speech Recognition
    try:
        # for testing purposes, we're just using the default API key
        # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        # instead of `r.recognize_google(audio)`
        userIn = str(r.recognize_google(audio))
    except sr.UnknownValueError:
        counter = counter + 1
        userIn = "noR"
        if (counter == 2):
            counter = 0
            say("Good Bye")
            userIn = "shutdown"
    except sr.RequestError as e:
        counter = counter + 1
        userIn = "noR"
        if (counter == 2):
            counter = 0
            say("Good Bye")
            userIn = "shutdown"
    print(userIn)
    userIn = userIn.lower()
    if ("hello" in userIn):
        say("Hi " + name + ", I am Jacbism how can I help you")
    elif (userIn == "shutdown"):
        say("Good Bye")
    elif ("info on" in userIn or "information on" in userIn
          or "information about" in userIn or "look up" in userIn):
        begin = userIn.find("info")
        index = userIn.find(" ", userIn.find(" ", begin + 1) + 1)
        say("Pulling up information on " + userIn[index:])
        Web.infoOn(userIn[index:])
    elif ("video" in userIn):
        begin = userIn.find("video")
        index = userIn.find(" ", userIn.find(" ", begin + 1) + 1)
        say("Pulling up videos on " + userIn[index:])
        Web.openInWeb(Web.getYoutubeLink(userIn[index:]))
    elif ("play" in userIn):
        if "on youtube" in userIn:
            s = userIn[userIn.find(" ", userIn.find("play")):]
            s = s.replace("on youtube", "")
            say("Playing " + s)
            Web.music(s)
            return
        s = Web.getSubject(userIn)
        print s
        say("Playing " + s)
        Web.music(s)
    elif (len(userIn) == 0):
        counter = counter + 1
        if (counter == 2):
            counter = 0
            say("Good Bye")
            userIn = "shutdown"
    elif ("definition" in userIn or "mean" in userIn):
        s = Web.definition(userIn)
        say(s)
    elif ("nor" == userIn):
        pass
    elif ("remind me to" in userIn):
        index = userIn.find("remind me to")
        begin = userIn.find(" ", index + len("remind me to"))
        re = userIn[begin:]
        if "comes out" in userIn:
            re = re.replace("watch", "")
            re = re.replace("go to", "")
            re = re.replace("when it comes out", "") + "film "
            re = "Watch " + re + Web.getMovieDate(re)

            re = re.replace("film", "")

        CAL.createEvent(re)
        print re
        say("ok i will remind you to " + re)
    elif ("give me searches" in userIn):
        userIn.strip()
        userIn = userIn[len("give me searches for"):]
        if ("youtube" in userIn):
            userIn = userIn.replace("on youtube", "")
            userIn = userIn.replace("youtube", "")
            say("Getting searches for " + userIn + "on youtube")
            Web.youtubeSearchs(userIn)
            return
        say("Getting searches for " + userIn + "on google")
        Web.openInWeb(Web.googLink(userIn))
    elif ("open" in userIn and "chrome" in userIn):
        say("Opening new Window in chrome")
        Web.openWindow()

    else:
        s = Web.getAnswer(userIn)
        if Config.firebaseR:
            if len(s) > 0:
                say(s)
                return
            s = fire.getMyRespPyth(userIn)
            if len(s) > 0:
                say(s)
                return
            s = fire.getMyResp(userIn)
            if len(s) > 0:
                say(s)
                return
            if Config.randomR:
                say(fire.getRandomResponse())
                return
        say("I did not understand that, If you can add that to my database, that would be great."
            )
Ejemplo n.º 14
0
            frequency, settlementDate)

    return {
        "Benchmark Yield": round(benchmarkYield, 4),
        "Clean Price": round(cleanPrice, 4),
        "Accrued Interest": round(accruedAmount, 4),
        "CF (TF1403)": round(conversionFactor1403, 4),
        "CF (TF1406)": round(conversionFactor1406, 4),
        "CF (TF1409)": round(conversionFactor1409, 4),
        "Macaulay Duration": round(macaulayDuration, 4),
        "Modified Duration": round(modifiedDuration, 4),
        "Convexity": round(convexity, 4),
        "PV01": round(PV01, 4)
    }


if __name__ == '__main__':

    # Benchmark bond 130020. Quote on Dec 25th, 2013. Settle on Dec 26, 2013
    settlementDate = CAL.Date(26, CAL.December, 2013)
    startDate = CAL.Date(17, CAL.October, 2013)
    maturity = CAL.Date(17, CAL.October, 2020)
    period = CAL.Period(1, CAL.Years)
    coupons = [0.0407]
    benchmarkYield = 0.047154
    repeat = 1000

    result = calcuatingBondAnalytics(settlementDate, startDate, maturity,
                                     period, coupons, benchmarkYield, repeat)

    pprint.pprint(result)
Ejemplo n.º 15
0
main_ks = KS.KS()
main_ks.main_ks()  #PC_key 하위 폴더에 있는 키들 세팅함.

string1 = "ghdwpakss"
main_ip = IP.IP()
cryptogram = main_ip.IP_main(string1)  #크립토그램, IP단계 암호문

print("cryptogram :", cryptogram)


def device_two_for_cry(cryptogram):
    L = cryptogram[:(len(cryptogram) // 2)]
    R = cryptogram[(len(cryptogram) // 2):]
    res = []
    res.append(L)
    res.append(R)
    return res


cry_list = device_two_for_cry(cryptogram)
R = cry_list[(len(cry_list) - 1)]
#여기서 분할하고 함수로 넘기기
main_e = E.E()
expanded_R = main_e.E_main(R)

this_round = 1
KS_key = main_ks.handover_key(this_round)

main_cal = CAL.CAL()
main_cal.XOR(expanded_R, KS_key)
Ejemplo n.º 16
0
 def testSimpson(self):
     "Testing Simpson integration"
     self.singleTest(CAL.SimpsonIntegral(1.0e-4, 1000))
Ejemplo n.º 17
0
Archivo: SPT.py Proyecto: shoekla/AVA
def getAndExecCommand():
    # obtain audio from the microphone
    counter = 0
    r = sr.Recognizer()
    userIn = ""
    with sr.Microphone() as source:
        print("print Command!")
        audio = r.listen(source)
    # recognize speech using Google Speech Recognition
    try:
        # for testing purposes, we're just using the default API key
        # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        # instead of `r.recognize_google(audio)`
        userIn = str(r.recognize_google(audio))
    except sr.UnknownValueError:
        counter = counter + 1
        userIn = "noR"
        if (counter == 2):
            counter = 0
            print("Good Bye")
            userIn = "shutdown"
    except sr.RequestError as e:
        counter = counter + 1
        userIn = "noR"
        if (counter == 2):
            counter = 0
            print("Good Bye")
            userIn = "shutdown"
    print "You Said: " + userIn

    userIn = userIn.lower()
    if ("hello" == userIn or "hey" == userIn or "hi" == userIn):
        print("Hi " + name + ", I am Ava, a beers personal assistant")
    elif (userIn == "shutdown"):
        print("Good Bye")
    elif ("info on" in userIn or "information on" in userIn
          or "information about" in userIn or "look up" in userIn):
        begin = userIn.find("info")
        index = userIn.find(" ", userIn.find(" ", begin + 1) + 1)
        print("Pulling up information on " + userIn[index:])
        Web.infoOn(userIn[index:])
    elif ("video" in userIn):
        begin = userIn.find("video")
        index = userIn.find(" ", userIn.find(" ", begin + 1) + 1)
        print("Pulling up videos on " + userIn[index:])
        Web.openInWeb(Web.getYoutubeLink(userIn[index:]))
    elif ("play" in userIn):
        if "on youtube" in userIn:
            s = userIn[userIn.find(" ", userIn.find("play")):]
            s = s.replace("on youtube", "")
            print("Playing " + s)
            Web.music(s)
            return
        s = Web.getSubject(userIn)
        print s
        print("Playing " + s)
        Web.music(s)
    elif (len(userIn) == 0):
        counter = counter + 1
        if (counter == 2):
            counter = 0
            print("Good Bye")
            userIn = "shutdown"
    elif ("definition" in userIn or "mean" in userIn):
        s = Web.definition(userIn)
        print(s)
    elif ("nor" == userIn):
        pass
    elif ("remind me to" in userIn):
        index = userIn.find("remind me to")
        begin = userIn.find(" ", index + len("remind me to"))
        re = userIn[begin:]
        if "comes out" in userIn:
            re = re.replace("watch", "")
            re = re.replace("go to", "")
            re = re.replace("when it comes out", "") + "film "
            re = "Watch " + re + Web.getMovieDate(re)

            re = re.replace("film", "")

        CAL.createEvent(re)
        print re
        print("ok i will remind you to " + re)
    elif ("give me searches" in userIn):
        userIn.strip()
        userIn = userIn[len("give me searches for"):]
        if ("youtube" in userIn):
            userIn = userIn.replace("on youtube", "")
            userIn = userIn.replace("youtube", "")
            print("Getting searches for " + userIn + "on youtube")
            Web.youtubeSearchs(userIn)
            return
        print("Getting searches for " + userIn + "on google")
        Web.openInWeb(Web.googLink(userIn))
    elif ("open" in userIn and "chrome" in userIn):
        print("Opening new Window in chrome")
        Web.openWindow()

    else:
        print("I did not understand that.")
Ejemplo n.º 18
0
Archivo: SPT.py Proyecto: shoekla/AVA
        print(s)
    elif ("nor" == userIn):
        pass
    elif ("remind me to" in userIn):
        index = userIn.find("remind me to")
        begin = userIn.find(" ", index + len("remind me to"))
        re = userIn[begin:]
        if "comes out" in userIn:
            re = re.replace("watch", "")
            re = re.replace("go to", "")
            re = re.replace("when it comes out", "") + "film "
            re = "Watch " + re + Web.getMovieDate(re)

            re = re.replace("film", "")

        CAL.createEvent(re)
        print re
        print("ok i will remind you to " + re)
    elif ("give me searches" in userIn):
        userIn.strip()
        userIn = userIn[len("give me searches for"):]
        if ("youtube" in userIn):
            userIn = userIn.replace("on youtube", "")
            userIn = userIn.replace("youtube", "")
            print("Getting searches for " + userIn + "on youtube")
            Web.youtubeSearchs(userIn)
        print("Getting searches for " + userIn + "on google")
        Web.openInWeb(Web.googLink(userIn))
    elif ("open" in userIn and "chrome" in userIn):
        print("Opening new Window in chrome")
        Web.openWindow()
Ejemplo n.º 19
0
 def testKronrod(self):
     "Testing Gauss-Kronrod integration"
     self.singleTest(CAL.GaussKronrodAdaptive(1.0e-4))
Ejemplo n.º 20
0
 def testCleanPriceFromZSpread(self):
     """ Testing FixedRateBond clean price derived from Z-spread. """
     self.assertEqual(round(CAL.cleanPriceFromZSpread(
                 self.bond, self.flat_forward, 0.01,
                 self.day_counter, CAL.Compounded, CAL.Semiannual,
                 self.issue_date + CAL.Period(1,CAL.Months)), 4), 92.5926)