from lib import stats wd = os.getcwd() yahoo_root = os.path.join(wd, 'data', 'yahoo') pyplot.style.use(config.glyfish_style) # %% Δt = 1.0 npts = 1000 time = numpy.linspace(0.0, float(npts)*Δt, npts + 1) dB = bm.brownian_noise(npts+1) title = f"Brownian Noise" bm.plot(dB, time, title, "brwonian_noise_cholesky") # %% H = 0.5 samples = bm.fbn_cholesky(H, Δt, npts, dB=dB) title = f"Cholesky Fractional Brownian Noise: Δt={Δt}, H={H}" bm.plot(samples, time,title, "fbn_cholesky_H_0.5") # %% H = 0.9 samples = bm.fbn_cholesky(H, Δt, npts, dB=dB) title = f"Cholesky Fractional Brownian Noise: Δt={Δt}, H={H}" bm.plot(samples, time,title, "fbn_cholesky_H_0.9")
from lib import stats wd = os.getcwd() yahoo_root = os.path.join(wd, 'data', 'yahoo') pyplot.style.use(config.glyfish_style) # %% Δt = 1.0 npts = 1024 time = numpy.linspace(0.0, float(npts)*Δt, npts) dB = bm.brownian_noise(2*npts) title = f"Brownian Noise" bm.plot(dB[:npts], time, title, "brwonian_noise_fft") # %% H = 0.5 samples = bm.fbn_fft(H, Δt, npts, dB=dB) title = f"FFT Fractional Brownian Noise: Δt={Δt}, H={H}" bm.plot(samples, time,title, "fbn_fft_H_0.5") # %% H = 0.89 samples = bm.fbn_fft(H, Δt, npts, dB=dB) title = f"FFT Fractional Brownian Noise: Δt={Δt}, H={H}" bm.plot(samples, time,title, "fbn_fft_H_0.89")
wd = os.getcwd() yahoo_root = os.path.join(wd, 'data', 'yahoo') pyplot.style.use(config.glyfish_style) # %% f = FBM(n=1024, hurst=0.85, length=1024, method='daviesharte') fbm = f.fbm() fbn = f.fgn() times = f.times() # %% bm.plot(fbn, times[:1024], "FBM Library FBN H=0.85", "fbm_library_fbn_H_0.85") # %% bm.plot(fbm, times, "FBM Library FBM H=0.85", "fbm_library_fbm_H_0.85") # %% ac = stats.autocorrelate(fbn).real bm.plot(ac[:200], times[:200], "FBM Library FBN γ H=0.85", "fbm_library_γ_H_0.85") # %% f = FBM(n=1024, hurst=0.9, length=1024, method='daviesharte') row_component = [f._autocovariance(i) for i in range(1, f.n)] reverse_component = list(reversed(row_component))
Z[i] = Z[i]*Δt**(H - 0.5)/numpy.sqrt(C) return Z # %% Δt = 1.0 npts = 1000 b = int(numpy.ceil(npts**(1.5))) time = numpy.linspace(0.0, float(npts)*Δt, npts + 1) B1 = brownian_motion.brownian_noise(b) B2 = brownian_motion.brownian_noise(npts+1) # %% samples = brownian_motion.brownian_motion_from_noise(B2) brownian_motion.plot(samples, time, "Brownian Motion From Noise", "brownian_motion_from_noise") # %% H = 0.5 samples = fb_motion_riemann_sum(H, Δt, npts, B1=B1, B2=B2) time = numpy.linspace(0.0, float(npts)*Δt, npts+1) title = f"Fractional Brownian Motion: Δt={Δt}, H={H}" brownian_motion.plot(samples, time, title, "fbm_riemann_sum_comparision_H_0.5") # %% H = 0.9 samples = fb_motion_riemann_sum(H, Δt, npts, B1=B1, B2=B2) time = numpy.linspace(0.0, float(npts)*Δt, npts+1) title = f"Fractional Brownian Motion: Δt={Δt}, H={H}"
if i == 0: samples = numpy.array([brownian_motion.brownian_motion(Δt, npts)]) else: samples = numpy.append(samples, numpy.array([brownian_motion.brownian_motion(Δt, npts)]), axis=0) time = numpy.linspace(0.0, float(npts-1)*Δt, npts) title = f"Brownian Motion: Δt={Δt}" brownian_motion.multiplot(samples, time, [5.0, 25.0], title, "brownian_motion_2") # %% Δt = 0.01 npts = 10000 samples = brownian_motion.brownian_motion(Δt, npts) time = numpy.linspace(0.0, float(npts-1)*Δt, npts) title = f"Brownian Motion: Δt={Δt}" brownian_motion.plot(samples, time, title, "brownian_motion_3") # %% max_lag = 5000 title = f"Brownian Motion Autocorrelation: Δt={Δt}, npts={npts}" brownian_motion.autocor(title, samples, Δt, max_lag, "brownian_motion_autocorrelation_1") # %% Δt = 0.01 npts = 10000 nsim = 8 μ = 0.1 σ = 0.1