예제 #1
0
def test_mc_analy_comparison():
    qgy_md = qgy.QgyModel()
    num_sim = 10000
    n_per_year = 50
    EtXT_analy = compute_expectation_analytic(qgy_md)
    EtXT_mc = compute_expectation_mc(qgy_md, num_sim, n_per_year)
    plt.plot(qgy_md.Tk, EtXT_analy, 'r--')
    plt.plot(qgy_md.Tk, EtXT_mc, 'b-o')
    plt.show()
예제 #2
0
def test_convergence():
    qgy_md = qgy.QgyModel()
    num_sim = 100
    n_per_year = 100
    EtXT_analy = compute_expectation_analytic(qgy_md)
    for i in range(1, 10):
        current_num = num_sim * i * 2
        EtXT_mc = compute_expectation_mc(qgy_md, current_num, n_per_year)
        RMSE = np.sqrt(np.sum((EtXT_analy - EtXT_mc)**2))
        print("sim_num = ", current_num, "err = ", RMSE, "N * err = ",
              current_num * RMSE, "sqrt(N) * err = ",
              np.sqrt(current_num) * RMSE)
예제 #3
0
from Model.QgyModel import *

qgy = QgyModel()
ytT = qgy.price_yoy_infln_fwd()
I0_Tk_corr = qgy.fit_yoy_convexity_correction(qgy.I0_Tk)

plt.subplot(1, 2, 1)
plt.plot(qgy.Tk[1:], -0.00012662 * np.log(qgy.Tk[1:]), '-')
plt.plot(qgy.Tk[1:], ytT[1:] - (qgy.I0_Tk[1:] / qgy.I0_Tk[:-1] - 1), 'or')

plt.subplot(1, 2, 2)
plt.plot(qgy.Tk[1:], ytT[1:] - (I0_Tk_corr[1:] / I0_Tk_corr[:-1] - 1), 'or')
print(qgy.I0_Tk)
print(I0_Tk_corr)
plt.show()
예제 #4
0
import Model.QgyModel as qgy
import matplotlib.pyplot as plt
import numpy as np


qgy = qgy.QgyModel()
qgy.n_per_year = 50
num_path = 10000
P_Tk = qgy.P_0T(qgy.Tk)

Sigma_Tk_y = 0.045
v_Tk_y = 0.8
rho_Tk_y = -0.5
rho_t_ny1 = -0.1
#R_Tk = np.array([0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) * 0.01
R_Tk = np.array([0, 1, 2, 4, 8, 16, 32, 64, 128, 256]) * 0.01
count = 0
for R in R_Tk:
    mc_res = np.zeros(len(qgy.Tk))
    qgy.fill_spherical_parameters(Sigma_Tk_y, v_Tk_y, rho_Tk_y, rho_t_ny1, R)
    for k in range(num_path):
        qgy.generate_terms_structure()
        disc = qgy.D_t
        yoy = qgy.Y_Tk
        disc_price = yoy * disc
        mc_res += disc_price
        #plt.plot(qgy.Tk, disc_price/P_Tk - 1, 'g-')
    avg_price = mc_res/num_path
    count += 1
    plt.plot(qgy.Tk, avg_price/P_Tk - 1, color=[0, count/len(R_Tk), 0])