# Path: internal_model/PCA.py
# def pca_swap_rate(file_name):
#     swap_matrix, maturity_range = read_swap_rate(file_name)
#     cov_mat = np.cov(np.array(swap_matrix).T)
#     w, v = la.eig(cov_mat)
#     eigenvalues = w.real
#     eigenvectors = (v.T).real
#     norm_a1 = np.linalg.norm(eigenvectors[0])
#     norm_a2 = np.linalg.norm(eigenvectors[1])
#     norm_a3 = np.linalg.norm(eigenvectors[2])
#     a1 = np.divide(eigenvectors[0], norm_a1)
#     a2 = np.divide(-eigenvectors[1], norm_a2)
#     a3 = np.divide(eigenvectors[2], norm_a3)
#     alpha_range = []
#     beta_range = []
#     gamma_range = []
#     for l in swap_matrix:
#         alpha_range.append(np.dot(l, a1))
#         beta_range.append(np.dot(l, a2))
#         gamma_range.append(np.dot(l, a3))
# 
#     alpha_min = min(alpha_range)
#     alpha_max = max(alpha_range)
#     beta_min = min(beta_range)
#     beta_max = max(beta_range)
#     gamma_min = min(gamma_range)
#     gamma_max = max(gamma_range)
#     return eigenvalues, eigenvectors, a1, a2, a3, alpha_min, alpha_max, beta_min, beta_max, gamma_min, gamma_max, maturity_range


from .PCA import pca_swap_rate
from ..core_math import excel_toolbox as et
import matplotlib.pyplot as plt
import pickle
import xlwings as xw
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 25 22:57:32 2016

@author: Quang Dien DUONG
"""

### Progam packages
### Python packages



Working_URL = r'Feuille_de_calcul_ALM(Working).xlsm'

@xw.func
def PCA_swap():
    # ====================================================================================
    # VL1, VL2, VL3 correspond respectively to the first, second and third vector loadings
    # ====================================================================================

# Path: internal_model/PCA.py
# def pca_swap_rate(file_name):
#     swap_matrix, maturity_range = read_swap_rate(file_name)
#     cov_mat = np.cov(np.array(swap_matrix).T)
#     w, v = la.eig(cov_mat)
#     eigenvalues = w.real
#     eigenvectors = (v.T).real
#     norm_a1 = np.linalg.norm(eigenvectors[0])
#     norm_a2 = np.linalg.norm(eigenvectors[1])
#     norm_a3 = np.linalg.norm(eigenvectors[2])
#     a1 = np.divide(eigenvectors[0], norm_a1)
#     a2 = np.divide(-eigenvectors[1], norm_a2)
#     a3 = np.divide(eigenvectors[2], norm_a3)
#     alpha_range = []
#     beta_range = []
#     gamma_range = []
#     for l in swap_matrix:
#         alpha_range.append(np.dot(l, a1))
#         beta_range.append(np.dot(l, a2))
#         gamma_range.append(np.dot(l, a3))
# 
#     alpha_min = min(alpha_range)
#     alpha_max = max(alpha_range)
#     beta_min = min(beta_range)
#     beta_max = max(beta_range)
#     gamma_min = min(gamma_range)
#     gamma_max = max(gamma_range)
#     return eigenvalues, eigenvectors, a1, a2, a3, alpha_min, alpha_max, beta_min, beta_max, gamma_min, gamma_max, maturity_range


# Path: internal_model/PCA_main.py
from .PCA import pca_swap_rate
from ..core_math import excel_toolbox as et
import matplotlib.pyplot as plt
import pickle
import xlwings as xw

# -*- coding: utf-8 -*-
"""
Created on Mon Jul 25 22:57:32 2016

@author: Quang Dien DUONG
"""

### Progam packages
### Python packages



Working_URL = r'Feuille_de_calcul_ALM(Working).xlsm'

@xw.func
def PCA_swap():
    # ====================================================================================
    # VL1, VL2, VL3 correspond respectively to the first, second and third vector loadings
    # ====================================================================================

    eigenvalues, eigenvectors, VL1, VL2, VL3, alpha_min, alpha_max, beta_min, beta_max, gamma_min, gamma_max, maturities = pca_swap_rate(Working_URL)