コード例 #1
0
    def test_libor_update_duplicate_date(self):
        key = signed_object.generate_signing_key()
        store = ObjectStore()
        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-24',
                rates={
                    'Overnight': 0.1,
                    'OneWeek': 0.1,
                    'OneMonth': 0.1,
                    'TwoMonth': 0.1,
                    'ThreeMonth': 0.1,
                    'SixMonth': 0.1,
                    'OneYear': 0.1
                },
                signature='G38pbExUmKqKzdC07QJS1OJSglnpLKGr+PMu4muigey37CdT2P'
                          '7d0PBQxmaWNjtsADdPxQAS5FhtHOQbtD41fkU=')

        transaction = BondTransaction()
        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError:
            self.fail('This transaction should be valid')

        transaction.apply(store)

        try:
            transaction.check_valid(store)
            self.fail('This transaction should be invalid')
        except InvalidTransactionError:
            pass
コード例 #2
0
 def test_create_bond_valid(self):
     transaction = BondTransaction({
         "UpdateType":
         "CreateBond",
         'Updates': [{
             "UpdateType": "CreateBond",
             "amount_outstanding": 42671000000,
             'corporate_debt_ratings': {
                 "Fitch": "AAA",
                 "Moodys": "AAA",
                 "S&P": "AA+"
             },
             "coupon_rate": 1.375,
             "coupon_type": "Fixed",
             "coupon_frequency": "Quarterly",
             "cusip": "912828R77",
             "face_value": 1000,
             "isin": "US912828R770",
             "first_settlement_date": "01/11/2012",
             "first_coupon_date": "03/01/2012",
             "maturity_date": "01/11/2022",
             "issuer": "T"
         }]
     })
     transaction.sign_object(self.key)
     try:
         transaction.check_valid(self.store)
         transaction.apply(self.store)
     except InvalidTransactionError:
         self.fail("This should be valid")
コード例 #3
0
    def test_create_settlement_ref_count(self):
        org = self.store.lookup("organization:name", "First Bank")["ref-count"]
        org2 = self.store.lookup("organization:name",
                                 "Second Bank")["ref-count"]
        transaction = BondTransaction({
            "UpdateType":
            "CreateSettlement",
            'Updates': [{
                "UpdateType":
                "CreateSettlement",
                "order_id":
                "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })

        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        new_org = self.store.lookup("organization:name",
                                    "First Bank")["ref-count"]
        new_org2 = self.store.lookup("organization:name",
                                     "Second Bank")["ref-count"]

        self.assertEquals(org + 1, new_org)
        self.assertEquals(org2 + 1, new_org)
コード例 #4
0
    def test_create_holding_refcounts(self):
        org = self.store.lookup("organization:name", "Test Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        org_refcount_before = org["ref-count"]
        bond_refcount_before = bond["ref-count"]

        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Bond",
                "asset_id": bond["object-id"],
                "amount": 10000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org = self.store.lookup("organization:name", "Test Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")

        self.assertEquals(org_refcount_before + 1, org["ref-count"])
        self.assertEquals(bond_refcount_before + 1, bond["ref-count"])
コード例 #5
0
    def test_generate_coupons_coupon(self):
        self._set_clock(2015, 4, 1, 1)
        signingkey = signed_object.generate_signing_key()
        ident = signed_object.generate_identifier(signingkey)
        node = Node(identifier=ident,
                    signingkey=signingkey,
                    address=("localhost", 10021))
        node.is_peer = True
        path = tempfile.mkdtemp()
        gossip = Gossip(node)
        journal = Journal(node,
                          gossip,
                          gossip.dispatcher,
                          consensus=DevModeConsensus(),
                          data_directory=path)
        journal.global_store.TransactionStores['/BondTransaction'] = \
            self.store
        # creates a redemption
        updates = Family._generate_coupons(journal)

        self.assertNotEquals(updates, [])

        transaction = BondTransaction(updates[0])
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        org_usd_holding = self.store["34d813716009ca1786222a44347ccff"
                                     "258a4ab6029d936664fde0d13f23992b5"]
        self.assertEquals(org_usd_holding["amount"], 25000.0)
コード例 #6
0
    def test_create_coupon(self):
        date = datetime.datetime(2015, 4, 1)
        self._set_clock(2015, 4, 1, 1)
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        coupon = Family._create_coupon(self.store, bond, org, date)
        self.assertIsNotNone(coupon)
        transaction = BondTransaction(coupon)
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        org_usd_holding = self.store["34d813716009ca1786222a44347ccff"
                                     "258a4ab6029d936664fde0d13f23992b5"]
        self.assertEquals(org_usd_holding["amount"], 25000.0)

        date = datetime.datetime(2015, 7, 1)
        self._set_clock(2015, 7, 1, 2)
        coupon = Family._create_coupon(self.store, bond, org, date)
        self.assertIsNotNone(coupon)
        transaction = BondTransaction(coupon)
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        org_usd_holding = self.store["34d813716009ca1786222a44347ccff"
                                     "258a4ab6029d936664fde0d13f23992b5"]
        self.assertEquals(org_usd_holding["amount"], 50000.0)
コード例 #7
0
    def test_coupon_exists(self):
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        date = datetime.datetime(2015, 4, 1)
        self._set_clock(2015, 4, 1, 1)
        self.assertFalse(Family._coupon_exists(self.store, bond, org, date))

        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        self.assertTrue(Family._coupon_exists(self.store, bond, org, date))
コード例 #8
0
    def test_create_holding_valid(self):
        org = self.store.lookup("organization:name", "Test Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Currency",
                "asset_id":
                "USD",
                "amount":
                10000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b6"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Bond",
                "asset_id":
                bond["object-id"],
                "amount":
                10000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")
コード例 #9
0
    def test_create_quote_diff_submitted(self):
        key = signed_object.generate_signing_key()
        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Isin": "US912828R770",
                "BidPrice": "98-05.875",
                "BidQty": 25000,
                "AskPrice": "98-06.875",
                "AskQty": 25000
            }]
        })
        transaction.sign_object(key)
        try:
            transaction.check_valid(self.store)
            self.fail("Signed by an unauthorized participant")
        except InvalidTransactionError:
            pass

        transaction = BondTransaction({
            "UpdateType": "CreateOrganization",
            'Updates': [{"UpdateType": "CreateOrganization",
                         "name": "NewBank",
                         "ticker": "F",
                         "pricing_source": "EFGH",
                         "industry": "Test",
                         "authorization": []
                         }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        key = signed_object.generate_signing_key()
        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "EFGH",
                "Isin": "US912828R770",
                "BidPrice": "98-05.875",
                "BidQty": 25000,
                "AskPrice": "98-06.875",
                "AskQty": 25000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Signed by an unauthorized participant")
        except InvalidTransactionError:
            pass
コード例 #10
0
    def test_create_settlement_status(self):
        org2 = self.store.lookup("organization:name", "Second Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrder",
            'Updates': [{
                "UpdateType":
                "CreateOrder",
                "Action":
                "Buy",
                "OrderType":
                "Limit",
                "FirmId":
                org2["object-id"],
                "Isin":
                "US912828R770",
                "Quantity":
                100000,
                "LimitPrice":
                "98-05.875",
                "LimitYield":
                0.015,
                "object_id":
                "765432116009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        # quote-id
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType":
            "CreateSettlement",
            'Updates': [{
                "UpdateType":
                "CreateSettlement",
                "order_id":
                "765432116009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })

        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Order is not matched")
        except:
            pass
コード例 #11
0
 def _set_clock(self, year, month, day, num):
     date = time.mktime(datetime.date(year, month, day).timetuple())
     transaction = BondTransaction({
         'Updates': [{
             'UpdateType': 'Clock',
             'Blocknum': num,
             'PreviousBlockId': 0,
             'Timestamp': date
         }]
     })
     transaction.sign_object(self.key)
     transaction.check_valid(self.store)
     transaction.apply(self.store)
コード例 #12
0
 def test_delete_quote(self):
     transaction = BondTransaction({
         "UpdateType": "DeleteQuote",
         'Updates': [{
             "UpdateType": "DeleteQuote",
             "ObjectId": "3932250c4877136ee99bf76e5ffbb50b7f"
             "bd46d6788340d29422abcdabcdabcd"
         }]
     })
     try:
         transaction.sign_object(self.key)
         transaction.check_valid(self.store)
         transaction.apply(self.store)
     except InvalidTransactionError:
         self.fail("This should be valid")
コード例 #13
0
    def test_matching_no_quotes(self):
        signingkey = signed_object.generate_signing_key()
        ident = signed_object.generate_identifier(signingkey)
        node = Node(identifier=ident, signingkey=signingkey,
                    address=("localhost", 10003))
        node.is_peer = True
        path = tempfile.mkdtemp()
        gossip = Gossip(node)
        journal = Journal(node,
                          gossip,
                          gossip.dispatcher,
                          consensus=DevModeConsensus(),
                          data_directory=path)

        org2 = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType": "CreateOrder",
            'Updates': [{
                "UpdateType": "CreateOrder",
                "Action": "Buy",
                "OrderType": "Market",
                "FirmId": org2["object-id"],
                "Isin": bond["isin"],
                "Quantity": 100000,
                "object_id": "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        journal.global_store.TransactionStores['/BondTransaction'] = \
            self.store
        matched_orders = _generate_match_orders(journal)
        self.assertEquals(matched_orders, [])
コード例 #14
0
    def test_create_quote_ref_count(self):
        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Cusip": "912828R77",
                "BidPrice": "98-05.875",
                "BidQty": 24000,
                "AskPrice": "98-06.875",
                "AskQty": 24000
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        firm = self.store.lookup("organization:pricing-source", "ABCD")
        self.assertEquals(firm["ref-count"], 2)
コード例 #15
0
    def test_create_quote_valid(self):
        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Isin": "US912828R770",
                "BidPrice": "98-05.875",
                "BidQty": 25000,
                "AskPrice": "98-06.875",
                "AskQty": 25000
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Cusip": "912828R77",
                "BidPrice": "98-05.875",
                "BidQty": 24000,
                "AskPrice": "98-06.875",
                "AskQty": 24000
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Cusip": "912828R77",
                "Isin": "US912828R770",
                "BidPrice": "98-05.875",
                "BidQty": 23000,
                "AskPrice": "98-06.875",
                "AskQty": 23000
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")
コード例 #16
0
    def test_matching_no_order(self):
        signingkey = signed_object.generate_signing_key()
        ident = signed_object.generate_identifier(signingkey)
        node = Node(identifier=ident, signingkey=signingkey,
                    address=("localhost", 10004))
        node.is_peer = True
        path = tempfile.mkdtemp()
        gossip = Gossip(node)
        journal = Journal(node,
                          gossip,
                          gossip.dispatcher,
                          consensus=DevModeConsensus(),
                          data_directory=path)
        transaction = BondTransaction({
            "UpdateType": "CreateQuote",
            'Updates': [{
                "UpdateType": "CreateQuote",
                "Firm": "ABCD",
                "Isin": "US912828R770",
                "BidPrice": "101",
                "BidQty": 250000,
                "AskPrice": "101",
                "AskQty": 250000,
                "object_id": "555553716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        journal.global_store.TransactionStores['/BondTransaction'] = \
            self.store
        matched_orders = _generate_match_orders(journal)
        self.assertEquals(matched_orders, [])
コード例 #17
0
    def test_create_redemption(self):
        self._set_clock(2016, 4, 1, 1)
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:cusip", "912828R77")
        coupon = Family._create_redemption(self.store, bond, org)
        self.assertIsNotNone(coupon)
        transaction = BondTransaction(coupon)
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        first_bond = self.store["34d813716009ca1786222a44347ccff258a4ab6029" +
                                "d936664fde0d13f239org1"]["amount"]
        second_bond = self.store["34d813716009ca1786222a44347ccff258a4ab6029" +
                                 "d936664fde0d13f23992b7"]["amount"]
        first_usd = self.store["34d813716009ca1786222a44347ccff258a4ab6029" +
                               "d936664fde0d13f23992b5"]["amount"]
        second_usd = self.store["34d813716009ca1786222a44347ccff258a4ab6029" +
                                "d936664fde0d13f23org1"]["amount"]
        self.assertEquals(first_bond, 200000)
        self.assertEquals(second_bond, 0)
        self.assertEquals(first_usd, 100000)
        self.assertEquals(second_usd, 100000000 - 100000)
コード例 #18
0
    def test_libor_update_duplicate_date(self):
        key = signed_object.generate_signing_key()
        store = ObjectStore()
        libor_key = TestCreateLIBORUpdate.libor_key
        libor_public_key = signing.generate_pubkey(libor_key)
        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-24',
                rates={
                    'Overnight': 0.1,
                    'OneWeek': 0.1,
                    'OneMonth': 0.1,
                    'TwoMonth': 0.1,
                    'ThreeMonth': 0.1,
                    'SixMonth': 0.1,
                    'OneYear': 0.1
                },
                libor_public_key=libor_public_key)
        update.sign_update_object(libor_key)

        transaction = BondTransaction()
        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError:
            self.fail('This transaction should be valid')

        transaction.apply(store)

        try:
            transaction.check_valid(store)
            self.fail('This transaction should be invalid')
        except InvalidTransactionError:
            pass
コード例 #19
0
    def test_create_receipt_update_valid(self):
        self._set_clock(2015, 4, 1, 1)
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:isin", "US912828R770")
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        self._set_clock(2016, 1, 2, 2)
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:isin", "US912828R770")
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Redemption',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id']
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")
コード例 #20
0
    def setUp(self):
        self.key = signed_object.generate_signing_key()
        participant = CreateParticipantUpdate("CreateParticipant", "testuser")
        object_id = participant._object_id
        transaction = BondTransaction({})
        transaction._updates = [participant]
        self.store = ObjectStore()
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
        sub = self.store.lookup("participant:username",
                                "testuser")["object-id"]

        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "Test Bank",
                "ticker":
                "T",
                "pricing_source":
                "ABCD",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
コード例 #21
0
    def test_libor_update(self):
        key = signed_object.generate_signing_key()
        store = ObjectStore()
        libor_key = TestCreateLIBORUpdate.libor_key
        libor_public_key = signing.generate_pubkey(libor_key)
        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-24',
                rates={
                    'Overnight': 0.1,
                    'OneWeek': 0.1,
                    'OneMonth': 0.1,
                    'TwoMonth': 0.1,
                    'ThreeMonth': 0.1,
                    'SixMonth': 0.1,
                    'OneYear': 0.1
                },
                libor_public_key=libor_public_key)
        update.sign_update_object(libor_key)
        transaction = BondTransaction()
        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError as e:
            self.fail('This transaction should be valid\n error:' + str(e))

        try:
            store.lookup('libor:date', '2016-05-24')
            self.fail('LIBOR data for 2016-05-24 should not be in store')
        except KeyError:
            pass

        transaction.apply(store)

        self.assertIsNotNone(store.lookup('libor:date', '2016-05-24'))

        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-25',
                rates={
                    'Overnight': '0.1',
                    'OneWeek': '-0.1',
                    'OneMonth': '0',
                    'TwoMonth': 0.1,
                    'ThreeMonth': -0.1,
                    'SixMonth': 0,
                    'OneYear': 1
                },
                libor_public_key=libor_public_key)
        update.sign_update_object(libor_key)

        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError as e:
            self.fail('This transaction should be valid\n error: ' + str(e))

        try:
            store.lookup('libor:date', '2016-05-25')
            self.fail('LIBOR data for 2016-05-25 should not be in store')
        except KeyError:
            pass

        transaction.apply(store)

        self.assertIsNotNone(store.lookup('libor:date', '2016-05-25'))
コード例 #22
0
    def test_create_settlement_holding_bond_id(self):
        transaction = BondTransaction({
            "UpdateType":
            "CreateQuote",
            'Updates': [{
                "UpdateType":
                "CreateQuote",
                "Firm":
                "ABCD",
                "Isin":
                "US912828R770",
                "BidPrice":
                "103",
                "BidQty":
                250000,
                "AskPrice":
                "2",
                "AskQty":
                250000,
                "object_id":
                "666663716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org2 = self.store.lookup("organization:name", "Second Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrder",
            'Updates': [{
                "UpdateType":
                "CreateOrder",
                "Action":
                "Buy",
                "OrderType":
                "Limit",
                "FirmId":
                org2["object-id"],
                "Isin":
                "US912828R770",
                "Quantity":
                100000000,
                "LimitPrice":
                "98-05.875",
                "LimitYield":
                0.015,
                "QuoteId":
                "666663716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7",
                "object_id":
                "765432116009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        # quote-id
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType":
            "CreateSettlement",
            'Updates': [{
                "UpdateType":
                "CreateSettlement",
                "order_id":
                "765432116009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })

        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Quoting firm does not have enough bonds")
        except:
            pass
コード例 #23
0
    def test_create_settlement_valid_buy_and_sell(self):
        transaction = BondTransaction({
            "UpdateType":
            "CreateSettlement",
            'Updates': [{
                "UpdateType":
                "CreateSettlement",
                "order_id":
                "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })

        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bonds_first_bank = self.store['34d813716009ca1786222a44347cc'
                                      'ff258a4ab6029d936664fde0d13f23'
                                      '992b7']["amount"]
        bonds_second_bank = self.store['34d813716009ca1786222a44347ccff258a4'
                                       'ab6029d936664fde0d13f23'
                                       '992b8']["amount"]
        currency_first_bank = self.store['34d813716009ca1786222a44347ccff258a'
                                         '4ab6029d936664fde0d13f23'
                                         '992b5']["amount"]
        currency_second_bank = self.store["34d813716009ca1786222a44347ccff258"
                                          "a4ab6029d936664fde0d13f2"
                                          "3992b6"]["amount"]
        self.assertEquals(bonds_first_bank, 2400000)
        self.assertEquals(bonds_second_bank, 100000)
        self.assertEquals(currency_first_bank, 101000)
        self.assertEquals(currency_second_bank, 2500000 - 101000)

        org2 = self.store.lookup("organization:name", "Second Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrder",
            'Updates': [{
                "UpdateType":
                "CreateOrder",
                "Action":
                "Sell",
                "OrderType":
                "Limit",
                "FirmId":
                org2["object-id"],
                "Isin":
                "US912828R770",
                "Quantity":
                100000,
                "LimitPrice":
                "98-05.875",
                "LimitYield":
                0.015,
                "QuoteId":
                "555553716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7",
                "object_id":
                "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23sell"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType":
            "CreateSettlement",
            'Updates': [{
                "UpdateType":
                "CreateSettlement",
                "order_id":
                "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23sell"
            }]
        })

        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bonds_first_bank = self.store['34d813716009ca1786222a44347cc'
                                      'ff258a4ab6029d936664fde0d13f23'
                                      '992b7']["amount"]
        bonds_second_bank = self.store['34d813716009ca1786222a44347ccff258a4'
                                       'ab6029d936664fde0d13f23'
                                       '992b8']["amount"]
        currency_first_bank = self.store['34d813716009ca1786222a44347ccff258a'
                                         '4ab6029d936664fde0d13f23'
                                         '992b5']["amount"]
        currency_second_bank = self.store["34d813716009ca1786222a44347ccff258"
                                          "a4ab6029d936664fde0d13f2"
                                          "3992b6"]["amount"]
        self.assertEquals(bonds_first_bank, 2500000)
        self.assertEquals(bonds_second_bank, 0)
        self.assertEquals(currency_first_bank, 0)
        self.assertEquals(currency_second_bank, 2500000)
コード例 #24
0
    def setUp(self):
        self.key = signed_object.generate_signing_key()
        participant = CreateParticipantUpdate("CreateParticipant", "testuser")
        object_id = participant._object_id
        transaction = BondTransaction({})
        transaction._updates = [participant]
        self.store = ObjectStore()
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
        sub = self.store.lookup("participant:username",
                                "testuser")["object-id"]

        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'Clock',
                'Blocknum': 0,
                'PreviousBlockId': 0,
                'Timestamp': time.time()
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        # add another organization
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "First Bank",
                "ticker":
                "T",
                "pricing_source":
                "ABCD",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "Second Bank",
                "ticker":
                "I",
                "pricing_source":
                "EFGH",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateBond",
            'Updates': [{
                "UpdateType": "CreateBond",
                "amount_outstanding": 42671000000,
                'corporate_debt_ratings': {
                    "Fitch": "AAA",
                    "Moodys": "AAA",
                    "S&P": "AA+"
                },
                "coupon_rate": 1.375,
                "coupon_type": "Fixed",
                "coupon_frequency": "Quarterly",
                "cusip": "912828R77",
                "face_value": 1000,
                "isin": "US912828R770",
                "first_settlement_date": "01/11/2012",
                "first_coupon_date": "03/01/2012",
                "maturity_date": "01/11/2022",
                "issuer": "T"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        org = self.store.lookup("organization:name", "First Bank")
        # add holding?
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Currency",
                "asset_id":
                "USD",
                "amount":
                0,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b5"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Bond",
                "asset_id":
                bond["object-id"],
                "amount":
                2500000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org2 = self.store.lookup("organization:name", "Second Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org2["object-id"],
                "asset_type":
                "Currency",
                "asset_id":
                "USD",
                "amount":
                2500000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b6"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org2["object-id"],
                "asset_type":
                "Bond",
                "asset_id":
                bond["object-id"],
                "amount":
                0,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b8"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            "UpdateType":
            "CreateQuote",
            'Updates': [{
                "UpdateType":
                "CreateQuote",
                "Firm":
                "ABCD",
                "Isin":
                "US912828R770",
                "BidPrice":
                "101",
                "BidQty":
                250000,
                "AskPrice":
                "101",
                "AskQty":
                250000,
                "object_id":
                "555553716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        try:
            transaction.sign_object(self.key)
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org2 = self.store.lookup("organization:name", "Second Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrder",
            'Updates': [{
                "UpdateType":
                "CreateOrder",
                "Action":
                "Buy",
                "OrderType":
                "Limit",
                "FirmId":
                org2["object-id"],
                "Isin":
                bond["isin"],
                "Quantity":
                100000,
                "LimitPrice":
                "98-05.875",
                "LimitYield":
                0.015,
                "QuoteId":
                "555553716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7",
                "object_id":
                "123453716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        # quote-id
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")
コード例 #25
0
    def test_create_receipt_update_double_receipts(self):
        self._set_clock(2015, 4, 1, 1)
        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:isin", "US912828R770")
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Same object Id")
        except InvalidTransactionError:
            pass

        org = self.store.lookup("organization:name", "Second Bank")
        bond = self.store.lookup("bond:isin", "US912828R770")
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType':
                'CreateReceipt',
                'PaymentType':
                'Coupon',
                'BondID':
                bond['object-id'],
                'PayeeID':
                org['object-id'],
                'CouponDate':
                "04/01/2015",
                'ObjectId':
                "b7d0717678424ac017a3ba414e547f3691beeb"
                "7d343141225afe05c5d663fnew"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Double coupon for period")
        except InvalidTransactionError:
            pass
コード例 #26
0
    def test_create_holding_duplicate(self):
        org = self.store.lookup("organization:name", "Test Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Currency",
                "asset_id": "USD",
                "amount": 10000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org = self.store.lookup("organization:name", "Test Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Currency",
                "asset_id": "USD",
                "amount": 10000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Same Holding")
        except InvalidTransactionError:
            pass

        org = self.store.lookup("organization:name", "Test Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Currency",
                "asset_id": "USD",
                "amount": 100
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Same Asset Type")
        except InvalidTransactionError:
            pass

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Bond",
                "asset_id": bond["object-id"],
                "amount": 10000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Bond",
                "asset_id": bond["object-id"],
                "amount": 10000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Same Holding")
        except InvalidTransactionError:
            pass

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType": "CreateHolding",
                "owner_id": org["object-id"],
                "asset_type": "Bond",
                "asset_id": bond["object-id"],
                "amount": 1000
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Same asset-id")
        except InvalidTransactionError:
            pass
コード例 #27
0
    def setUp(self):
        self.key = signed_object.generate_signing_key()
        participant = CreateParticipantUpdate("CreateParticipant", "testuser")
        object_id = participant._object_id
        transaction = BondTransaction({})
        transaction._updates = [participant]
        self.store = ObjectStore()
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
        sub = self.store.lookup("participant:username",
                                "testuser")["object-id"]
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'Clock',
                'Blocknum': 0,
                'PreviousBlockId': 0,
                'Timestamp': time.time()
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "Test Bank",
                "ticker":
                "T",
                "pricing_source":
                "ABCD",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateBond",
            'Updates': [{
                "UpdateType": "CreateBond",
                "amount_outstanding": 42671000000,
                'corporate_debt_ratings': {
                    "Fitch": "AAA",
                    "Moodys": "AAA",
                    "S&P": "AA+"
                },
                "coupon_rate": 1.375,
                "coupon_type": "Fixed",
                "coupon_frequency": "Quarterly",
                "cusip": "912828R77",
                "face_value": 1000,
                "isin": "US912828R770",
                "first_settlement_date": "01/11/2012",
                "first_coupon_date": "03/01/2012",
                "maturity_date": "01/11/2022",
                "issuer": "T"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
コード例 #28
0
    def setUp(self):
        self.key = signed_object.generate_signing_key()
        participant = CreateParticipantUpdate("CreateParticipant", "testuser")
        object_id = participant._object_id
        transaction = BondTransaction({})
        transaction._updates = [participant]
        self.store = ObjectStore()
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)
        sub = self.store.lookup("participant:username",
                                "testuser")["object-id"]

        self._set_clock(1994, 10, 4, 0)

        # add another organization
        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "First Bank",
                "ticker":
                "T",
                "pricing_source":
                "ABCD",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateOrganization",
            'Updates': [{
                "UpdateType":
                "CreateOrganization",
                "name":
                "Second Bank",
                "ticker":
                "I",
                "pricing_source":
                "EFGH",
                "industry":
                "Test",
                "authorization": [{
                    "ParticipantId": sub,
                    "Role": "marketmaker"
                }]
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        transaction = BondTransaction({
            "UpdateType":
            "CreateBond",
            'Updates': [{
                "UpdateType": "CreateBond",
                "amount_outstanding": 42671000000,
                'corporate_debt_ratings': {
                    "Fitch": "AAA",
                    "Moodys": "AAA",
                    "S&P": "AA+"
                },
                "coupon_rate": 1,
                "coupon_type": "Fixed",
                "coupon_frequency": "Quarterly",
                "cusip": "912828R77",
                "face_value": 1000,
                "isin": "US912828R770",
                "first_settlement_date": "01/11/2012",
                "first_coupon_date": "03/01/2012",
                "maturity_date": "01/01/2016",
                "issuer": "T"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        transaction.apply(self.store)

        org = self.store.lookup("organization:name", "Second Bank")
        # add holding?
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Currency",
                "asset_id":
                "USD",
                "amount":
                0,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b5"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org["object-id"],
                "asset_type":
                "Bond",
                "asset_id":
                bond["object-id"],
                "amount":
                100000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23992b7"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org1 = self.store.lookup("organization:name", "First Bank")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org1["object-id"],
                "asset_type":
                "Currency",
                "asset_id":
                "USD",
                "amount":
                100000000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f23org1"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        bond = self.store.lookup("bond:cusip", "912828R77")
        transaction = BondTransaction({
            "UpdateType":
            "CreateHolding",
            'Updates': [{
                "UpdateType":
                "CreateHolding",
                "owner_id":
                org1["object-id"],
                "asset_type":
                "Bond",
                "asset_id":
                bond["object-id"],
                "amount":
                100000,
                "object_id":
                "34d813716009ca1786222a44347ccff258a4ab6029" +
                "d936664fde0d13f239org1"
            }]
        })
        transaction.sign_object(self.key)
        transaction.check_valid(self.store)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")
コード例 #29
0
    def test_libor_update(self):
        key = signed_object.generate_signing_key()
        store = ObjectStore()
        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-24',
                rates={
                    'Overnight': 0.1,
                    'OneWeek': 0.1,
                    'OneMonth': 0.1,
                    'TwoMonth': 0.1,
                    'ThreeMonth': 0.1,
                    'SixMonth': 0.1,
                    'OneYear': 0.1
                },
                signature='G38pbExUmKqKzdC07QJS1OJSglnpLKGr+PMu4muigey37CdT2P7'
                          'd0PBQxmaWNjtsADdPxQAS5FhtHOQbtD41fkU=')

        transaction = BondTransaction()
        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError:
            self.fail('This transaction should be valid')

        try:
            store.lookup('libor:date', '2016-05-24')
            self.fail('LIBOR data for 2016-05-24 should not be in store')
        except KeyError:
            pass

        transaction.apply(store)

        self.assertIsNotNone(store.lookup('libor:date', '2016-05-24'))

        update = \
            CreateLIBORUpdate(
                update_type='CreateLIBOR',
                date='2016-05-25',
                rates={
                    'Overnight': '0.1',
                    'OneWeek': '-0.1',
                    'OneMonth': '0',
                    'TwoMonth': 0.1,
                    'ThreeMonth': -0.1,
                    'SixMonth': 0,
                    'OneYear': 1
                },
                signature='GzcrWBTv180bCZcKkluVOSPcqNbNrcLCj3FocJH9uliKkl+3yNR'
                          'yhj5DAIsTWOY2ZwrcDVEMOp1P1jJpfctst6I=')
        transaction._updates = [update]
        transaction.sign_object(key)

        try:
            transaction.check_valid(store)
        except InvalidTransactionError:
            self.fail('This transaction should be valid')

        try:
            store.lookup('libor:date', '2016-05-25')
            self.fail('LIBOR data for 2016-05-25 should not be in store')
        except KeyError:
            pass

        transaction.apply(store)

        self.assertIsNotNone(store.lookup('libor:date', '2016-05-25'))
コード例 #30
0
    def test_create_receipt_update_bad_libor(self):
        self._set_clock(2015, 4, 1, 1)
        bond = self.store.lookup("bond:isin", "US912828R770")
        org = self.store.lookup("organization:name", "Second Bank")
        bond["coupon-type"] = "Floating"
        self.store[bond["object-id"]] = bond
        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("No libor data available")
        except InvalidTransactionError:
            pass

        info = {
            'object-id': 'current_libor',
            'object-type': 'libor',
            'date': "2015-04-01",
            'rates': {
                'Overnight': 0.1,
                'OneWeek': 0.1,
                'OneMonth': 0.1,
                'TwoMonth': 0.1,
                'ThreeMonth': 0.1,
                'SixMonth': 0.1,
                'OneYear': 0.1
            },
            'signature': "Test"
        }
        self.store['current_libor'] = info

        bond["coupon-benchmark"] = "NoLibor"
        self.store[bond["object-id"]] = bond

        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            self.fail("Bad Benchmark")
        except InvalidTransactionError:
            pass

        bond["coupon-benchmark"] = "Overnight"
        self.store[bond["object-id"]] = bond

        transaction = BondTransaction({
            'Updates': [{
                'UpdateType': 'CreateReceipt',
                'PaymentType': 'Coupon',
                'BondID': bond['object-id'],
                'PayeeID': org['object-id'],
                'CouponDate': "04/01/2015"
            }]
        })
        transaction.sign_object(self.key)
        try:
            transaction.check_valid(self.store)
            transaction.apply(self.store)
        except InvalidTransactionError:
            self.fail("This should be valid")

        org_usd_holding = self.store["34d813716009ca1786222a44347ccff"
                                     "258a4ab6029d936664fde0d13f23992b5"]
        self.assertEquals(org_usd_holding["amount"], 27500.0)