コード例 #1
0
ファイル: eststoploss.py プロジェクト: mysteryyy/pythonbackup
def gen_sample_ret(period, size):
    alpha = wald.rvs(loc=alpha_mean, scale=alpha_conc)
    beta = norm.rvs(loc=beta_mean, scale=beta_var)
    scale = np.random.exponential(scale=scale_rate)
    scale = scale / period
    mean = halfnorm.rvs(loc=.1, scale=.1)
    mean = mean / period
    try:
        ret = norminvgauss.rvs(alpha, beta, mean, scale, size=size)
    except Exception as e:

        ret = norminvgauss.rvs(alpha, beta, mean, scale, size=size)
    return ret
コード例 #2
0
def gen_sample_ret():
    alpha = wald.rvs(loc=alpha_mean, scale=alpha_conc)
    beta = norm.rvs(loc=beta_mean, scale=beta_var)
    scale = np.random.exponential(scale=scale_rate)
    mean = halfnorm.rvs(loc=.1, scale=.08)
    ret = norminvgauss.rvs(alpha, beta, mean, scale)
    return ret
コード例 #3
0
ファイル: lab3.py プロジェクト: b14ckster/TeorVer
def distributions(size):
    n = norminvgauss.rvs(1, 0, size=size)
    l = laplace.rvs(size=size, scale=1 / m.sqrt(2), loc=0)
    p = poisson.rvs(10, size=size)
    c = cauchy.rvs(size=size)
    u = uniform.rvs(size=size, loc=-m.sqrt(3), scale=2 * m.sqrt(3))
    counted_distributions = [n, l, p, c, u]
    return counted_distributions
コード例 #4
0
ファイル: lab1.py プロジェクト: tmffv/MathStat
def normalNumbers():
    for size in sizes:
        fig, ax = plt.subplots(1, 1)
        ax.hist(norminvgauss.rvs(1, 0, size=size), histtype='stepfilled', alpha=0.5, color='blue', density=True)
        x = np.linspace(norminvgauss(1, 0).ppf(0.01), norminvgauss(1, 0).ppf(0.99), 100)
        ax.plot(x, norminvgauss(1, 0).pdf(x), '-')
        ax.set_title('NormalNumbers n = ' + str(size))
        ax.set_xlabel('NormalNumbers')
        ax.set_ylabel('density')
        plt.grid()
        plt.show()
    return
コード例 #5
0
def Gauss():
    for s in size:
        den = norminvgauss(1, 0)
        hist = norminvgauss.rvs(1, 0, size=s)
        fig, ax = plt.subplots(1, 1)
        ax.hist(hist, density=True, alpha=0.6)
        x = np.linspace(den.ppf(0.01), den.ppf(0.99), 100)
        ax.plot(x, den.pdf(x), LINE_TYPE, lw=1.5)
        ax.set_xlabel("NORMAL")
        ax.set_ylabel("DENSITY")
        ax.set_title("SIZE: " + str(s))
        plt.grid()
        plt.show()
コード例 #6
0
def Hist_Normal():
    normal_scale = 1  # Параметры
    normal_loc = 0
    normal_label = "Normal distribution"
    normal_color = "green"
    for size in selection_size:
        fig, ax = plt.subplots(1, 1)
        pdf = norminvgauss(normal_scale, normal_loc)
        random_values = norminvgauss.rvs(normal_scale, normal_loc, size=size)
        ax.hist(random_values,
                density=True,
                histtype=HIST_TYPE,
                alpha=hist_visibility,
                color=normal_color)
        Create_plot(ax, normal_label, pdf, size)
コード例 #7
0
ファイル: main.py プロジェクト: nikos72344/MathStat
def norminvgaussFunc():
    a, b = 1, 0

    for i in range(len(size)):
        n = size[i]
        fig, ax = plt.subplots(1, 1)
        ax.set_title("Нормальное распределение, n = " + str(n))
        x = np.linspace(norminvgauss.ppf(0.01, a, b),
                        norminvgauss.ppf(0.99, a, b), 100)
        ax.plot(x, norminvgauss.pdf(x, a, b), 'b-', lw=5, alpha=0.6)
        # rv = norminvgauss(a, b)
        # ax.plot(x, rv.pdf(x), 'k-', lw = 2, label = "frozen pdf")
        r = norminvgauss.rvs(a, b, size=n)
        ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
        plt.show()
コード例 #8
0
    def work(self, patient):
        #        slot = int(self.env.now_step // H.SLOT) # how many slots are there opening
        # print('Service Begin',self.env.now_step)
        if not patient.isRevisit():  # new patient
            # For simulator
            service_time = norminvgauss.rvs(7.405201799947, 7.189292406621,
                                            0.07906712903266, 1.7043134066555)
            patient.time[self.service_type,
                         1] = self.env.now_step  # service start time
            patient.time[
                self.service_type,
                2] = self.env.now_step + service_time  # service end time
            patient.time[self.service_type, -1] = self.id  # service id
            ## the check items which the patient need to be served
            patient.checklist = self.__check_list().copy()
            patient.check_list = patient.checklist.copy()
            patient.revisit = True  # change state
            ## predict time to revisit based on the checklist and env
            #            patient.scheduled_revisit_time = self.scheduled_revisit_time(patient)
            ## for finding next event
            self.finish_time = self.env.now_step + service_time  # service end time

            # For statistics
            #            self.realization[slot] = 1 if patient.schedule == True else 3 # record the type of patient at this slot
            # print('First Come',patient.schedule, patient.id)
            self.env.Save[self.service_type].append(patient)

        else:  # revisit patient
            # For simulator
            service_time = np.random.normal(7, 2)
            patient.time[-1, 1] = self.env.now_step  # service start time
            patient.time[
                -1, 2] = self.env.now_step + service_time  # service end time
            patient.time[-1, -1] = self.id  # service id
            ## for finding next event
            self.finish_time = self.env.now_step + service_time

            # For statistics
            self.env.Save[self.service_type].append(patient)
#            self.realization[slot] = 2 if patient.schedule == True else 4 # record the type of patient at this slot
# print('Revisit',patient.schedule, patient.id, patient.time[0,2])
# print(slot, self.realization[slot])
        return patient
コード例 #9
0
def gauss_distribution(select_size, loc=0, dist=1):
    return norminvgauss.rvs(dist, loc, size=select_size)
コード例 #10
0
        norminvgauss.pdf(x, a, b),
        'r-',
        lw=5,
        alpha=0.6,
        label='norminvgauss pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = norminvgauss(a, b)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = norminvgauss.ppf([0.001, 0.5, 0.999], a, b)
np.allclose([0.001, 0.5, 0.999], norminvgauss.cdf(vals, a, b))
# True

# Generate random numbers:

r = norminvgauss.rvs(a, b, size=1000)

# And compare the histogram:

ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()
コード例 #11
0
ファイル: gapsim.py プロジェクト: mysteryyy/pythonbackup
k1['Date'] = [i.date() for i in k1.index]
k1['VIX_Close'] = k1.VIX_Close.shift(1)
k1['VIX_Close_diff'] = ((k1.VIX_Close.shift(1) - k1.VIX_Close.shift(2)) /
                        k1.VIX_Close.shift(2)) * 100
k1 = k1.dropna()
k1 = feats.feattrans(k1)
k1['close_diff'] = (k1.Close.shift(1).diff()) / k1.Close.shift(2) * 100
#k1['close_diff5'] = ((k1.Close-k1.Close.shift(5))/k1.Close.shift(5))*100
k1['rsi20_diff'] = k1.rsi20.diff()
k1['rsi14_diff'] = k1.rsi14.diff()
k1['stoch20_diff'] = k1.stoch20.diff()
k1['dayret'] = ((k1.Close - k1.Open) / k1.Open) * 100
k1['gap'] = (k1.Open - k1.Close.shift(1)) / k1.Close.shift(1)
k1 = k1[k1.gap > 0]
nig = norminvgauss.fit(k1.dayret)
l = norminvgauss.rvs(nig[0], nig[1], nig[2], nig[3], size=100)
l = k1.dayret
a1 = []
a2 = []
s = 2000
for i in l:
    if (i < -2):
        r = 2
    elif (i > 1):
        r = -1
    else:
        r = -i
    s = s * (1 + r / 100)
    a2.append(r)
    a1.append(s)
plt.plot(a1)
コード例 #12
0
ファイル: lab2.py プロジェクト: b14ckster/TeorVer
count = 1000
names = ["Normal", "Laplace", "Poisson", "Cauchy", "Uniform"]

characteristics = [[[], [], [], [], []], [[], [], [], [], []],
                   [[], [], [], [], []]]
mean_characteristics = [[[], [], [], [], []], [[], [], [], [], []],
                        [[], [], [], [], []]]
mean_characteristics_sq = [[[], [], [], [], []], [[], [], [], [], []],
                           [[], [], [], [], []]]

functions = [mean, median, z_r, z_q, z_tr]

for i in range(len(sizes)):
    size = sizes[i]
    for k in range(count + 1):
        n = norminvgauss.rvs(1, 0, size=size)
        l = laplace.rvs(size=size, scale=1 / m.sqrt(2), loc=0)
        p = poisson.rvs(10, size=size)
        c = cauchy.rvs(size=size)
        u = uniform.rvs(size=size, loc=-m.sqrt(3), scale=2 * m.sqrt(3))
        distributions = [n, l, p, c, u]
        for num in range(len(distributions)):
            d = distributions[num]
            for s in range(len(functions)):
                if k == 0:
                    characteristics[i][num].append([])
                f = functions[s]
                value = f(d, size)
                characteristics[i][num][s].append(value)
    for num in range(len(distributions)):
        for s in range(len(functions)):