Esempio n. 1
0
    def __init__(self, cap: int, period: float) -> None:
        value_assert(cap > 0) and value_assert(period > 1e-6)

        self.cap = cap
        self.period = period

        self.__pool: int = cap
        self.__last: float = time()
Esempio n. 2
0
 def get_loan_at_usage(self, target_usage: float) -> float:
     value_assert(
         -1.0 <= target_usage <= 1.0,
         f"invalid {target_usage=:.4f}",
     )
     tu = src.security.bounds.Policy.MARGIN_USAGE.validate(target_usage)
     if tu > 0:
         return tu * self.max_loan
     # we interpret negative usage as a cash percentage -- therefore,
     # we will expect
     else:
         return tu * self.nlv
Esempio n. 3
0
 def of_acct_without_margin(cls, gpv: float, cash: float) -> MarginState:
     """
     Returns the MarginState giving correct behavior for accounts with no
     margin.
     """
     value_assert(
         cash >= 0.0,
         f"Tried to make marginless act with negative cash {cash=}",
     )
     return MarginState(
         gpv=gpv,
         cash=cash,
         min_maint_amt=gpv,
         min_margin_req=1.0,
         cushion=1.0,
     )
Esempio n. 4
0
 def __post_init__(self) -> None:
     # set min margin req
     value_assert(
         0.0 < self.min_margin_req <= 1.0,
         f"Invalid min margin req {self.min_margin_req:.4f}",
     )
     src.security.bounds.Policy.MARGIN_REQ.validate(self.min_margin_req)
     if self.min_maint_amt is not None:
         value_assert(self.min_maint_amt > 0, "Negative maintenance amount!")
         value_assert(
             self.nlv >= self.min_maint_amt,
             "Trying to create underwater margin state: "
             f"{self.nlv=:.2f} < {self.min_maint_amt:.2f}",
         )
     value_assert(self.cushion >= 1.0, "cushion < 1")
     value_assert(self.gpv >= 0, "Only positive gpv is supported.")