<jupyter_start><jupyter_text>Gamma sampled Wiener processsSuppose we want to construct a Wiener processwhere any given time interval follows the gamma distribution,This is to say, we are sampling the Wiener process according to a [gamma process](https://en.wikipedia.org/wiki/Gamma_process).We first implement the gamma process by subclassing `Process()` and using `gamma.rvs()` from `scipy.stats`<jupyter_code>from price_process.process import *
from scipy.stats import gamma
import numpy as np

class Gamma(Process):
    def __init__(self, alpha, beta, size, initial=0, T=1):
        super().__init__(size, initial=initial, T=T)
        self.alpha, self.beta = alpha, beta
        self.rvs = gamma.rvs(alpha, size=self.size, scale=1/self.beta)
        self.process = np.cumsum(self.rvs, axis=0)


shape = [1000, 5]
Gamma(.1, 1, shape).plot(r"$\Gamma(0.1, 1) process$")
Gaussian(shape).plot(r"$W_t$")<jupyter_output><empty_output><jupyter_text>Doing the resampling, and converting to an exponential process,where the LHS and RHS are equivalent upto interpolation (which is needed due to discretization error).<jupyter_code>wiener = Gaussian(shape).resample(Gamma(.3, 1, shape).process)
wiener.to_geometric(0, 0.05).plot()<jupyter_output><empty_output><jupyter_text>We can also take a look at the returns<jupyter_code>plt.stem(wiener.t,wiener.to_geometric(0, 0.05).returns(), markerfmt=" ")<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup