Exemple #1
0
def lift_test(train_path, Recovered_test0, Recovered_generate0):
    num_levels = 3
    num_lags = 0
    kernE = kernels.SignatureKernel(base_kernel = gpflow.kernels.Exponential(), \
                                    num_levels = num_levels, order = num_levels, num_lags = num_lags)

    recover_path1 = np.array(Recovered_test0)
    recover_path2 = np.array(Recovered_generate0)
    X = tf.constant([leadlag(p) for p in train_path], 'float64')
    Y = tf.constant([leadlag(p) for p in recover_path1], 'float64')
    Z = tf.constant([leadlag(p) for p in recover_path2], 'float64')
    H1_E = evaluation.Sig_TU2(X, Y, kernE)
    H2_E = evaluation.Sig_TU2(X, Z, kernE)
    return H1_E, H2_E
Exemple #2
0
    def randomise(self):
        self.derivatives = np.array(
            [self.random_derivative() for _ in range(self.n_points - 1)])
        prices = np.r_[0., self.derivatives.cumsum()]

        path = leadlag(prices)
        self.set_path(path)
Exemple #3
0
    def mutate(self, prob=0.1):
        for i in range(len(self.derivatives)):
            if np.random.random() < prob:
                self.derivatives[i] = self.random_derivative()

        prices = np.r_[0., np.cumsum(self.derivatives)]
        path = leadlag(prices)
        self.set_path(path)
    def _load_rough_bergomi(self, params):
        grid_points_dict = {"M": 28, "W": 5, "Y": 252}
        grid_points = grid_points_dict[self.freq]
        params["T"] = grid_points / grid_points_dict["Y"]

        paths = rough_bergomi(grid_points, **params)

        self.windows = [leadlag(path) for path in paths]
Exemple #5
0
def compare_ll_ta_plot(train_path, train_windows):
    f, p = plt.subplots(1, 2, figsize=(16, 3))
    batchsize = train_path.shape[0]
    idx = np.random.randint(0, batchsize)
    l1 = plot_helper_2dpath(p[0], leadlag(train_path[idx]), 'tab:blue')
    l2 = plot_helper_2dpath(p[1], (train_windows[idx]), 'tab:orange')
    p[0].legend((l1, ), ['lead-lag transformation'])
    p[1].legend((l2, ), ['Time augmentation'])
    for i in range(2):
        p[i].grid()
        p[i].set_xlabel('$X^{1}$')
        p[i].set_ylabel('$X^{2}$')
    plt.show()
    def _load_data(self):
        try:
            self.data = pdr.get_data_yahoo(self.ticker, self.start,
                                           self.end)["Close"]
        except:
            raise RuntimeError(
                f"Could not download data for {self.ticker} from {self.start} to {self.end}."
            )

        self.windows = []
        for _, window in self.data.resample(self.freq):
            values = window.values  # / window.values[0]
            path = leadlag(values)

            self.windows.append(path)
Exemple #7
0
def _load_rough_bergomi(params, freq, ll=False):
    grid_points_dict = {"M": 28, "W": 10, "Y": 252}
    grid_points = grid_points_dict[freq]
    N = grid_points - 1
    params["T"] = grid_points / grid_points_dict["Y"]
    paths = rough_bergomi(grid_points, **params)
    if ll:
        windows = np.array([leadlag(path) for path in paths])
        time = 0
    else:
        time = np.linspace(0, 1, N + 1)
        path_exp = paths[:, :, None]
        path_exp = np.array([
            np.concatenate([time[:, None], path0], axis=-1)
            for path0 in path_exp
        ])
        windows = path_exp
    return windows, paths, time
Exemple #8
0
    def __add__(self, other):
        """Breed."""

        derivatives = []
        for derivative1, derivative2 in zip(self.derivatives,
                                            other.derivatives):
            if np.random.random() < 0.5:
                derivatives.append(derivative1)
            else:
                derivatives.append(derivative2)

        prices = np.r_[0., np.cumsum(derivatives)]
        path = leadlag(prices)

        o = Organism(self.n_points, self.pip, self.n_pips)
        o.derivatives = derivatives
        o.set_path(path)

        return o