Пример #1
0
import numpy as np
from Tools import RNG, AnalyticTools
from FractionalBrownian import fBM

no_paths = 100000
no_time_steps = 2**6
t0 = 0.0
t1 = 1.0
z0 = 0.0
hurst_parameter = 0.5
seed = 123456789

rng = RNG.RndGenerator(seed)
paths = fBM.cholesky_method(t0, t1, z0, rng, hurst_parameter, no_paths,
                            int(no_time_steps * t1))

# Time steps to compute
t = np.linspace(t0, t1, int(no_time_steps * t1))

# Compute mean
empirical_mean = np.mean(paths, axis=0)

# Compute variance
empirical_variance = np.var(paths, axis=0)
exact_variance = [fBM.covariance(t_i, t_i, hurst_parameter) for t_i in t]

# Compute covariance
no_full_time_steps = len(t)
empirical_covariance = np.zeros(shape=(no_time_steps, no_full_time_steps))
exact_covariance = np.zeros(shape=(no_time_steps, no_full_time_steps))
Пример #2
0
dt = np.linspace(0.00001, 0.001, 15)
no_dt_s = len(dt)

# simulation info
alpha = 0.4
nu = 0.5
rho = -0.4
parameters = [alpha, nu, rho]
no_time_steps = 3

seed = 123456789
no_paths = 10000000
delta_time = 1.0 / 365.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0
options = []
options_shift_right = []
options_shift_left = []
shift_spot = 0.0001
for d_i in dt:
    options.append(
        EuropeanOption(f0, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0,
                       d_i))
    options_shift_right.append(
        EuropeanOption(f0 * (1.0 + shift_spot), 1.0, TypeSellBuy.BUY,
                       TypeEuropeanOption.CALL, f0, d_i))
    options_shift_left.append(
Пример #3
0
                               q) * notional
option_t_i[0] = black_scholes_merton('c', spot, k, delta_time, r, sigma,
                                     q) * notional
beta_t = option_t_i[0] - alpha_t_i_1 * spot

portfolio_t_i[0] = (alpha_t_i_1 * spot + beta_t)

s_t_i_1 = spot
s_t_i = 0.0
alpha_t_i = 0.0

rebalanced_index = list(
    map(lambda x: int(x), list(np.arange(0.0, no_time_steps, 30))))
# rebalanced_index = np.arange(1, no_time_steps)

rng = RNG.RndGenerator(123)
z_s = rng.normal(0.0, 1.0, no_time_steps - 1)

for i in range(1, no_time_steps):
    s_t_i = s_t_i_1 * np.exp((r - q) * diff_t_i_s[i - 1] -
                             0.5 * sigma * sigma * diff_t_i_s[i - 1] +
                             np.sqrt(diff_t_i_s[i - 1]) * sigma * z_s[i - 1])

    delta_time = T - t_i_s[i]
    option_t_i[i] = notional * black_scholes_merton('c', s_t_i, k, delta_time,
                                                    r, sigma, q)

    if i in rebalanced_index:
        alpha_t_i = analytical.delta('c', s_t_i, k, delta_time, r, sigma,
                                     q) * notional
        beta_t = beta_t * (1 + r * diff_t_i_s[i - 1]) + alpha_t_i_1 * s_t_i_1 * q * diff_t_i_s[i - 1] + \