예제 #1
0
# Wavelet Analysis
y = np.empty(len(signal))
wavelet = Wavelets.Daubechie(signal=signal, nb_vanishing_moments=nb_moments)
for level in range(0, abs(j_max)):
    j = -1 - level
    # Compute Approximation & Details coefficients (Discrete Wavelet Transformation)
    [cA, cD] = wavelet.dwt(j)
    # Compute Approximation & Details values (Inverse Discrete Wavelet Transformation)
    [yA, yD] = wavelet.idwt(cA, cD, j)
    # Compute Reconstructed Signals
    y = y + yD
    if j == j_max:
        y = y + yA
    # Plot Details Values
    functions.initialize_subplot(ax=ax1,
                                 title='Details',
                                 xlabel="Time Series",
                                 ylabel="cD Values")
    ax1.plot(yD, label="Scale j={}".format(j))
    ax1.legend(loc="upper right")
    # Plot Approximations Values
    functions.initialize_subplot(ax=ax3,
                                 title='Approximations',
                                 xlabel="Time Series",
                                 ylabel="Approximation Values")
    ax3.plot(yA, label="Scale j={}".format(j))
    ax3.legend(loc="upper right")

# Plot Reconstructed Signal
functions.initialize_subplot(ax=ax2,
                             title='Signals',
                             xlabel="Time Series",
예제 #2
0
    # Compute Approximation & Details Coefficients (Discrete Wavelet Transformation)
    [cA, cD] = wavelet.dwt(j)
    # Compute Approximation & Details Values (Inverse Discrete Wavelet Transformation)
    [yA, yD] = wavelet.idwt(cA, cD, j)
    # Compute Denoised Approximation & Details Coefficients
    cD_denoised = wavelet.denoise(cD, threshold=threshold)
    # Compute Denoised Approximation & Details Values (Inverse Discrete Wavelet Transformation)
    [yA_denoised, yD_denoised] = wavelet.idwt(cA, cD_denoised, j)
    # Compute Reconstructed Signals
    y = y + yD
    y_denoised = y_denoised + yD_denoised
    if j == j_max:
        y = y + yA
        y_denoised = y_denoised + yA_denoised
    # Plot Details Values
    functions.initialize_subplot(ax=ax1, title='Details', xlabel="Time Series", ylabel="cD Values")
    ax1.plot(yD, label="Scale j={}".format(j))
    ax1.legend(loc="upper right")
    # Plot Denoised Details Values
    functions.initialize_subplot(ax=ax3, title='Denoised Details', xlabel="Time Series", ylabel="cD_denoised Values")
    ax3.plot(yD_denoised, label="Scale j={}".format(j))
    ax3.legend(loc="upper right")

# Plot Reconstructed Signal
functions.initialize_subplot(ax=ax2, title='Signals', xlabel="Time Series", ylabel='Stock Price')
ax2.plot(signal, label="Original Signal")
ax2.plot(y, label="Reconstructed Signal")
ax2.legend(loc="upper right")

# Plot Reconstructed Denoised Signal
functions.initialize_subplot(ax=ax4, title='Denoised Signals', xlabel="Time Series", ylabel='Stock Price')
예제 #3
0
    density_normal_y[i] = functions.normal_pdf(density_normal_x[i], 0, 1)
density_normal_y = density_normal_y / sum(density_normal_y)
density_normal_x = density_normal_x/100

# Initializing Graph Params
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(nrows=2, ncols=2)
fig.set_size_inches(16, 7.6)
fig.set_tight_layout(True)
fig.suptitle(str("Returns Density Estimation"), fontsize=16)

# Simulated Data - Non Parametric Density Estimation (Gaussian Kernel)
print("\n[INFO] {} - Computing the simulated returns density using the gaussian kernel estimator".format(functions.get_now()))
ax1.plot(density_normal_x, density_normal_y, label="Normal Density", linestyle='dashed')
for smoothing in smoothing_array:
    [density_kernel_x, density_kernel_y] = functions.compute_kernel_density(simulated_returns, smoothing=smoothing)
    functions.initialize_subplot(ax=ax1, title='Simulated Returns - Gaussian Kernel Estimator', xlabel="Returns")
    ax1.plot(density_kernel_x, density_kernel_y, label="Smoothing h={}".format(smoothing))
    ax1.legend(loc="upper right")

# Simulated Data - Wavelet Parameters
nb_moments = 6
j = 7
# Simulated Data - Wavelet Density Estimations (Wavelet Kernel & Thresholded)
wavelet = Wavelets.Daubechie(signal=simulated_returns, nb_vanishing_moments=nb_moments)
[density_wav_x, density_wav_linear_y] = wavelet.density(j, "linear")
[density_wav_x, density_wav_donoho_y] = wavelet.density(j, "donoho")
functions.initialize_subplot(ax=ax2, title='Simulated Returns - Wavelet Estimators (db_{} / j={})'.format(nb_moments, j), xlabel="Returns")
ax2.plot(density_normal_x, density_normal_y, label="Normal Density", linestyle='dashed')
ax2.plot(density_wav_x, density_wav_linear_y, label="Linear")
ax2.plot(density_wav_x, density_wav_donoho_y, label="Donoho")
ax2.legend(loc="upper right")