Library Example

Connect to server

from absbox import LIBRARY
library_url = "https://ldn.spv.run/api"
library = LIBRARY(library_url)
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[2], line 2
      1 library_url = "https://ldn.spv.run/api"
----> 2 library = LIBRARY(library_url)

File <string>:4, in __init__(self, url)

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/absbox/library.py:71, in LIBRARY.__post_init__(self)
     68 def __post_init__(self):
     70     try:
---> 71         _r = requests.post(f"{self.url}/ack", verify=False)
     72     except Exception as e:
     73         raise AbsboxError(f"❌ Failed to connect to library server:{e}")

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/requests/api.py:115, in post(url, data, json, **kwargs)
    103 def post(url, data=None, json=None, **kwargs):
    104     r"""Sends a POST request.
    105 
    106     :param url: URL for the new :class:`Request` object.
   (...)    112     :rtype: requests.Response
    113     """
--> 115     return request("post", url, data=data, json=json, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs)
     55 # By using the 'with' statement we are sure the session is closed, thus we
     56 # avoid leaving sockets open which can trigger a ResourceWarning in some
     57 # cases, and look like a memory leak in others.
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/requests/sessions.py:592, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    587 send_kwargs = {
    588     "timeout": timeout,
    589     "allow_redirects": allow_redirects,
    590 }
    591 send_kwargs.update(settings)
--> 592 resp = self.send(prep, **send_kwargs)
    594 return resp

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/requests/sessions.py:706, in Session.send(self, request, **kwargs)
    703 start = preferred_clock()
    705 # Send the request
--> 706 r = adapter.send(request, **kwargs)
    708 # Total elapsed time of the request (approximately)
    709 elapsed = preferred_clock() - start

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/requests/adapters.py:645, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    642     timeout = TimeoutSauce(connect=timeout, read=timeout)
    644 try:
--> 645     resp = conn.urlopen(
    646         method=request.method,
    647         url=url,
    648         body=request.body,
    649         headers=request.headers,
    650         redirect=False,
    651         assert_same_host=False,
    652         preload_content=False,
    653         decode_content=False,
    654         retries=self.max_retries,
    655         timeout=timeout,
    656         chunked=chunked,
    657     )
    659 except (ProtocolError, OSError) as err:
    660     raise ConnectionError(err, request=request)

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    784 response_conn = conn if not release_conn else None
    786 # Make the request on the HTTPConnection object
--> 787 response = self._make_request(
    788     conn,
    789     method,
    790     url,
    791     timeout=timeout_obj,
    792     body=body,
    793     headers=headers,
    794     chunked=chunked,
    795     retries=retries,
    796     response_conn=response_conn,
    797     preload_content=preload_content,
    798     decode_content=decode_content,
    799     **response_kw,
    800 )
    802 # Everything went great!
    803 clean_exit = True

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/connectionpool.py:464, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    461 try:
    462     # Trigger any extra validation we need to do.
    463     try:
--> 464         self._validate_conn(conn)
    465     except (SocketTimeout, BaseSSLError) as e:
    466         self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/connectionpool.py:1093, in HTTPSConnectionPool._validate_conn(self, conn)
   1091 # Force connect early to allow us to validate the connection.
   1092 if conn.is_closed:
-> 1093     conn.connect()
   1095 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791
   1096 if not conn.is_verified and not conn.proxy_is_verified:

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/connection.py:759, in HTTPSConnection.connect(self)
    757 try:
    758     sock: socket.socket | ssl.SSLSocket
--> 759     self.sock = sock = self._new_conn()
    760     server_hostname: str = self.host
    761     tls_in_tls = False

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/connection.py:204, in HTTPConnection._new_conn(self)
    199 """Establish a socket connection and set nodelay settings on it.
    200 
    201 :return: New socket connection.
    202 """
    203 try:
--> 204     sock = connection.create_connection(
    205         (self._dns_host, self.port),
    206         self.timeout,
    207         source_address=self.source_address,
    208         socket_options=self.socket_options,
    209     )
    210 except socket.gaierror as e:
    211     raise NameResolutionError(self.host, self, e) from e

File ~/checkouts/readthedocs.org/user_builds/absbox-doc/envs/latest/lib/python3.11/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     71 if source_address:
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle
     75 err = None

KeyboardInterrupt: 
library.login("trial_1","iamhere")
#library.safeLogin("chinapublisher")
✅ login successfully, user -> trial_1,group -> trial_group_1

Query Deal Library

List all deals which are accessible to current user

library.query()
✅ query success
ID name period stage tags permission group
0 3 吉时代2025年第一期个人汽车抵押贷款资产支持证券 0 1 auto 700 3

Run Deal By Name

revol_asset = ["Mortgage"
                ,{"originBalance":2200,"originRate":["fix",0.02],"originTerm":48
                  ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"}
                  ,{"currentBalance":2200
                  ,"currentRate":0.02
                  ,"remainTerm":40
                  ,"status":"current"}]


i,r = library.run(("name","吉时代2025年第一期个人汽车抵押贷款资产支持证券")
            ,runAssump= [("revolving"
                         ,["constant",revol_asset]
                         ,("Pool",("Mortgage",{"CDR":0.00},None,None,None)
                                   ,None
                                   ,None))
                       ]
            ,read=True)
✅ run success with deal: 吉时代2025年第一期个人汽车抵押贷款资产支持证券|3

Run Deal By ID

i,r = library.run(("id",3)
            ,runAssump= [("revolving"
                         ,["constant",revol_asset]
                         ,("Pool",("Mortgage",{"CDR":0.00},None,None,None)
                                   ,None
                                   ,None))
                       ]
            ,read=True)
✅ run success with deal: 吉时代2025年第一期个人汽车抵押贷款资产支持证券|3

Run Info

i
{'time': {'load': '1.5590000000000002 ms', 'run': '31.668000000000003 ms'},
 'engine': 'http://localhost:8081 | 0.44.1',
 'deal': {'name': '吉时代2025年第一期个人汽车抵押贷款资产支持证券', 'id': 3}}

Run Result

The result object is same as the one return by api.run()

r['pool']['flow']['PoolConsol'].head(3)
Balance Principal Interest Prepayment Default Recovery Loss WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery CumLoss
Date
2025-03-14 3.984977e+09 5.150247e+08 11076764.20 0 0 0 0 0.000000 None None 5.150247e+08 0 0 0 0 0
2025-03-31 3.731465e+09 2.535123e+08 6738886.87 0 0 0 0 0.000000 None None 7.685370e+08 0 0 0 0 0
2025-04-30 4.258881e+09 2.493541e+08 6311620.99 0 0 0 0 0.010284 None None 1.017891e+09 0 0 0 0 0
r['bonds']['优先A1'].head(3)
balance interest principal rate cash intDue intOverInt factor memo
date
2025-04-26 1.600000e+09 3449424.65 0.0 0.0183 3449424.65 0 0 1.0 <PayInt:优先A1>
2025-05-26 1.600000e+09 2406575.34 0.0 0.0183 2406575.34 0 0 1.0 <PayInt:优先A1>
2025-06-26 1.600000e+09 2486794.52 0.0 0.0183 2486794.52 0 0 1.0 <PayInt:优先A1>