def __init__(self, mean_of_log=None, cov_of_log=None, vol_of_log=None, dim=None, copy=True): if mean_of_log is not None and dim is not None and np.size(mean_of_log) == 1: mean_of_log = npu.col_of(dim, npu.to_scalar(mean_of_log)) if mean_of_log is None and vol_of_log is None and cov_of_log is None: self._dim = 1 if dim is None else dim mean_of_log = npu.col_of(self._dim, 0.) cov_of_log = np.eye(self._dim) vol_of_log = np.eye(self._dim) self._dim, self._mean_of_log, self._vol_of_log, self._cov_of_log = None, None, None, None # TODO We don't currently check whether cov_of_log and vol_of_log are consistent, i.e. that cov_of_log = np.dot(vol_of_log, vol_of_log.T) -- should we? if mean_of_log is not None: self._mean_of_log = npu.to_ndim_2(mean_of_log, ndim_1_to_col=True, copy=copy) self._dim = npu.nrow(self._mean_of_log) if cov_of_log is not None: self._cov_of_log = npu.to_ndim_2(cov_of_log, ndim_1_to_col=True, copy=copy) self._dim = npu.nrow(self._cov_of_log) if vol_of_log is not None: self._vol_of_log = npu.to_ndim_2(vol_of_log, ndim_1_to_col=True, copy=copy) self._dim = npu.nrow(self._vol_of_log) if self._mean_of_log is None: self._mean_of_log = npu.col_of(self._dim, 0.) if self._cov_of_log is None and self._vol_of_log is None: self._cov_of_log = np.eye(self._dim) self._vol_of_log = np.eye(self._dim) npc.check_col(self._mean_of_log) npc.check_nrow(self._mean_of_log, self._dim) if self._cov_of_log is not None: npc.check_nrow(self._cov_of_log, self._dim) npc.check_square(self._cov_of_log) if self._vol_of_log is not None: npc.check_nrow(self._vol_of_log, self._dim) if self._cov_of_log is None: self._cov_of_log = stats.vol_to_cov(self._vol_of_log) if self._vol_of_log is None: self._vol_of_log = stats.cov_to_vol(self._cov_of_log) npu.make_immutable(self._mean_of_log) npu.make_immutable(self._cov_of_log) npu.make_immutable(self._vol_of_log) mean = np.exp(self._mean_of_log + .5 * npu.col(*[self._cov_of_log[i,i] for i in range(self._dim)])) cov = np.array([[np.exp(self._mean_of_log[i,0] + self._mean_of_log[j,0] + .5 * (self._cov_of_log[i,i] + self._cov_of_log[j,j])) * (np.exp(self._cov_of_log[i,j]) - 1.) for j in range(self._dim)] for i in range(self._dim)]) vol = stats.cov_to_vol(cov) self._to_string_helper_LogNormalDistr = None self._str_LogNormalDistr = None super().__init__(mean, cov, vol, self._dim, copy)
def create_from_cov(initial_value=None, final_value=None, initial_time=0., final_time=1., cov=None): vol = None if cov is None else stats.cov_to_vol(cov) return BrownianBridge(initial_value=initial_value, final_value=final_value, initial_time=initial_time, final_time=final_time, vol=vol)
def create_multiscale_from_cov(transition_vector, cov): vol = None if cov is None else stats.cov_to_vol(cov) return create_multiscale_from_vol(transition, mean, vol)
def create_from_cov(transition=None, mean=None, cov=None): vol = None if cov is None else stats.cov_to_vol(cov) return OrnsteinUhlenbeckProcess(transition, mean, vol)
def create_from_pct_cov(pct_drift, pct_cov): pct_vol = None if pct_cov is None else stats.cov_to_vol(pct_cov) return GeometricBrownianMotion(pct_drift, pct_vol)
def create_from_cov(mean, cov): vol = None if cov is None else stats.cov_to_vol(cov) return WienerProcess(mean, vol)
def vol_n_minus_1(self): if self._vol_n_minus_1 is None: self._vol_n_minus_1 = stats.cov_to_vol(self.cov_n_minus_1) npu.make_immutable(self._vol_n_minus_1) return self._vol_n_minus_1
def vol_n(self): if self._vol_n is None: self._vol_n = stats.cov_to_vol(self.cov_n) npu.make_immutable(self._vol_n) return self._vol_n
def vol(self): if self._vol is None: self._vol = stats.cov_to_vol(self._cov) return self._vol