def full_matrix( func: Callable[[int, int], float], row_dimension: int, column_dimension: Optional[int] = None, ) -> Matrix: return Matrix( starmap( func, product(range(row_dimension), range(default(column_dimension, row_dimension)))), (row_dimension, default(column_dimension, row_dimension)), )
def pay(self, term=None, payment=None): """Creates a new mortgage instance assuming payments were made. :param term: The term during which payments were made. :param payment: The optional payment made, defaults to payment with respect to the interest. :return: The next mortgage instance. """ term = default(term, self.term) payment = default(payment, self.payment) return Mortgage( self.principal * self.int.to_factor(term) - payment * fa(self.int.to_sp(self.freq).rate, term * self.freq), self.int, self.freq, self.term, self.amort - term, )
def series_sum(start: int, end_inclusive: int, count: Optional[int] = None) -> int: """Calculates the series sum of the interval. :param start: The beginning value of the series. :param end_inclusive: The inclusive final value in the series. :param count: The number of values in the series, defaults to end_inclusive - begin + 1. :return: the series sum. """ return (start + end_inclusive) * default( count, abs(end_inclusive - start) + 1) // 2
def aw(cash_flows, i, total_life=None): """Calculates the annual worth of the supplied cash flows at the interest. :param cash_flows: The cash flows. :param i: The interest. :param total_life: The optional total life. :return: The annual worth. """ if isinstance(cash_flows, Iterator): return aw(tuple(cash_flows), i, total_life) else: return pw(cash_flows, i) * ap(i.to_ef().rate, default(total_life, life(cash_flows)))
def match(self, u, v): return default(u, self.u) == self.u and default(v, self.v) == self.v
def test_default(self) -> None: self.assertEqual(default(300, 100), 300) self.assertEqual(default(cast(Optional[int], None), 100), 100)