Skip to content

Commit

Permalink
include pool sampe 2
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Apr 23, 2024
1 parent e459df8 commit c744a7f
Show file tree
Hide file tree
Showing 10 changed files with 5,265 additions and 1,549 deletions.
14 changes: 10 additions & 4 deletions absbox/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, urllib3, getpass, enum
import json, urllib3, getpass, enum, os
from importlib.metadata import version
from json.decoder import JSONDecodeError
from dataclasses import dataclass
Expand Down Expand Up @@ -29,7 +29,7 @@
urllib3.disable_warnings()
console = Console()

__all__ = ["API", "Endpoints", "RunReqType", "RunResp", "MsgColor", "LibraryEndpoints"]
__all__ = ["API", "Endpoints", "RunReqType", "RunResp", "MsgColor", "LibraryEndpoints","EnginePath"]


class Endpoints(str, enum.Enum):
Expand Down Expand Up @@ -93,10 +93,16 @@ class LibraryEndpoints(str, enum.Enum):


class EnginePath(str, enum.Enum):
""" Shortcut engine path for client"""
""" Enum class representing shortcut engine paths for the client.
"""
LOCAL = "http://localhost:8081"
""" Use local default server """
PROD = "https://absbox.org/api/latest"
DEV = "https://absbox.org/api/dev"
NY_DEV = "https://spv.run/api/dev"
NY_PROD = "https://spv.run/api/latest"
USE_ENV = "USE_ENV"
""" USE_ENV (str): Use environment variable (`ABSBOX_SERVER`) for engine path """


class VersionMismatch(Exception):
Expand Down Expand Up @@ -153,7 +159,7 @@ def __post_init__(self) -> None:
:raises RuntimeError: Failed to get version info from server
:raises VersionMismatch: Failed to match version between client and server
"""
self.url = isValidUrl(self.url).rstrip("/")
self.url = isValidUrl(self.url).rstrip("/") if self.url != EnginePath.USE_ENV.value else os.environ.get("ABSBOX_SERVER")
console.print(f"{MsgColor.Info.value}Connecting engine server -> {self.url}")
try:
_r = requests.get(f"{self.url}/{Endpoints.Version.value}", verify=False, timeout=5, headers = {"Origin":"http://localhost:8001"}).text
Expand Down
13 changes: 8 additions & 5 deletions absbox/local/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from absbox.local.base import *

from absbox.validation import vDict, vList, vStr, vNum, vInt, vDate, vFloat, vBool
from schema import Or
from enum import Enum
import itertools
import functools
Expand All @@ -15,6 +16,7 @@
import pandas as pd
from pyspecter import query, S

numVal = Or(float,int)

def mkLiq(x):
''' make pricing method '''
Expand Down Expand Up @@ -1331,11 +1333,11 @@ def mkAssumpDefault(x):
''' New default assumption for performing assets '''
match x:
case {"CDR": r} if isinstance(r, list):
return mkTag(("DefaultVec", vList(r,float)))
return mkTag(("DefaultVec", vList(r, numVal)))
case {"CDR": r}:
return mkTag(("DefaultCDR", vNum(r)))
case {"ByAmount": (bal, rs)}:
return mkTag(("DefaultByAmt", (vNum(bal), vList(rs,float))))
case {"ByAmount": (bal, rs)} | {"ByAmt": (bal, rs)}:
return mkTag(("DefaultByAmt", (vNum(bal), vList(rs,numVal))))
case "DefaultAtEnd":
return mkTag(("DefaultAtEnd"))
case _ :
Expand All @@ -1346,7 +1348,7 @@ def mkAssumpPrepay(x):
''' New prepayment assumption for performing assets '''
match x:
case {"CPR": r} if isinstance(r, list):
return mkTag(("PrepaymentVec", vList(r, float)))
return mkTag(("PrepaymentVec", vList(r, numVal)))
case {"CPR": r}:
return mkTag(("PrepaymentCPR", vNum(r)))
case _ :
Expand Down Expand Up @@ -1388,7 +1390,8 @@ def mkAssumpRecovery(x):
case {"Rate":r,"Lag":lag}:
return mkTag(("Recovery",[vNum(r),vInt(lag)]))
case {"Rate":r,"Timing":ts}:
return mkTag(("RecoveryTiming",[vNum(r),vList(ts, float)]))
assert sum(ts)==1.0,f"Recvoery timing should sum up to 100%,but current sum up to {sum(ts)}"
return mkTag(("RecoveryTiming",[vNum(r),vList(ts, numVal)]))
case {"Rate":r, "ByDays": lst}:
return mkTag(("RecoveryByDays",[vNum(r),lst]))
case _:
Expand Down
Loading

0 comments on commit c744a7f

Please sign in to comment.