def strength(self, value): check_numeric(value, "Strength") if self.discount < 0: strength_positive = 1.0 * value / -self.discount <= 0 strength_not_multiple = (1.0 * value / -self.discount) % 1 != 0 if strength_positive or strength_not_multiple: raise ValueError( "When discount is negative, strength value must be equal to a multiple of the discount value." ) elif self.discount < 1: if value <= -self.discount: raise ValueError( "When discount is between 0 and 1, strength value must be greater than the negative of the discount" ) self._strength = value
def _sample(self, n, initial=1.0): """Generate a realization of a diffusion process using Euler-Maruyama.""" check_positive_integer(n) check_numeric(initial, "Initial") delta_t = 1.0 * self.t / n gns = self._sample_gaussian_noise(n) s = [initial] t = 0 for k in range(n): t += delta_t initial += (self._speed(t) * (self._mean(t) - initial) * delta_t + self._vol(t) * initial**self._volexp(initial) * gns[k]) s.append(initial) return np.array(s)
def drift(self, value): check_numeric(value, "Drift") self._drift = value
def discount(self, value): check_numeric(value, "Discount") if value >= 1: raise ValueError("Discount value must be less than 1.") self._discount = value
def beta(self, value): check_numeric(value, "beta") self._beta = value
def test_check_numeric(number_fixture, parameter_name_fixture): if not isinstance(number_fixture, (int, float)): with pytest.raises(TypeError): check_numeric(number_fixture, parameter_name_fixture) else: assert check_numeric(number_fixture, parameter_name_fixture) is None
def drift(self, value): check_numeric(value, "Drift coefficient.") self._drift = ensure_single_arg_constant_function(value) self.speed = ensure_single_arg_constant_function(-value)
def b(self, value): check_numeric(value, "Time end") self._b = value