# Path: alm/Balance_Sheets.py
# class Balance_Sheets(object):
#     """
#         DOCUMENTATION WILL BE COMPLETED LATER
#     """
#     def __init__(self):
#         self.assets = {}
#         self.liabilities = {}
#         self.cash_flows_in = {}
#         self.cash_flows_out = {}
# 
#     def update(self, key_lv1, key_lv2, value):
#         if key_lv1 == 'assets':
#             self.assets[key_lv2] = value
#         elif key_lv1 == 'liabilities':
#             self.liabilities[key_lv2] = value
#         elif key_lv1 == 'cash_flows_in':
#             self.cash_flows_in[key_lv2] = value
#         elif key_lv1 == 'cash_flows_out':
#             self.cash_flows_out[key_lv2] = value
#         else:
#             raise ValueError("Could not find ", key_lv1)
# 
#     def get_value(self, key_lv1, key_lv2):
#         if key_lv1 == 'assets':
#             resu = self.assets[key_lv2]
#         elif key_lv1 == 'liabilities':
#             resu = self.liabilities[key_lv2]
#         elif key_lv1 == 'cash_flows_in':
#             resu = self.cash_flows_in[key_lv2]
#         elif key_lv1 == 'cash_flows_out':
#             resu = self.cash_flows_out[key_lv2]
#         else:
#             raise ValueError("Could not find ", key_lv1)
#         return resu
# 
#     def get_cash_flow(self):
#         return sum(self.cash_flows_in[key] for key in self.cash_flows_in.keys()) - sum(self.cash_flows_out[key] for key in self.cash_flows_out.keys())


from ..liability.liability_data.Liabilities_data_m import Liabilities_data_m
from ..liability.liability_data.Liabilities_data import Liabilities_data
from ..esg.ESG_RN import ESG_RN
from .Balance_Sheets import Balance_Sheets
import numpy as np
        # ================================================================================================================================================
        for mdlp in liabilities.liabilities_data.model_points:
            mdlp.profit_sharing_rate[0] = mdlp.TMG[mdlp.seniority]
        # ==========================================
        # Initialize ALM
        # ==========================================
        alm = ALM(assets, liabilities, time_horizon)
        # ==========================================
        # Set up asset allocation
        # ==========================================
        alm.assets.add_allocation(allocation_EQ = 0.2, allocation_bond = 0.7)
        value = alm.liabilities.technical_provision.mathematical_provision[0]
        alm.assets.initialize_EQ_value(value = assets.allocations['EQ']*value)
        alm.assets.bonds.initialize_allocation(amount=assets.allocations['bonds']*value)
        # ===============================
        # Set up deflators
        # ===============================
        alm.assets.deflators = alm.assets.ESG_RN.scenarios[traj]['Deflators']
        
        print(alm.assets.bonds.init_rating_based_deflators[0])        
        
        bond_market_value = alm.assets.get_bond_market_value(0)
        bond_book_value = alm.assets.get_bond_book_value(0)
        # ==============================
        #          Cash
        # ==============================
        alm.assets.add_cash(amount = alm.assets.allocations['cash'] * value)
        # ================================
        # Initialize Balance Sheet
        # ================================

# Path: alm/Balance_Sheets.py
# class Balance_Sheets(object):
#     """
#         DOCUMENTATION WILL BE COMPLETED LATER
#     """
#     def __init__(self):
#         self.assets = {}
#         self.liabilities = {}
#         self.cash_flows_in = {}
#         self.cash_flows_out = {}
# 
#     def update(self, key_lv1, key_lv2, value):
#         if key_lv1 == 'assets':
#             self.assets[key_lv2] = value
#         elif key_lv1 == 'liabilities':
#             self.liabilities[key_lv2] = value
#         elif key_lv1 == 'cash_flows_in':
#             self.cash_flows_in[key_lv2] = value
#         elif key_lv1 == 'cash_flows_out':
#             self.cash_flows_out[key_lv2] = value
#         else:
#             raise ValueError("Could not find ", key_lv1)
# 
#     def get_value(self, key_lv1, key_lv2):
#         if key_lv1 == 'assets':
#             resu = self.assets[key_lv2]
#         elif key_lv1 == 'liabilities':
#             resu = self.liabilities[key_lv2]
#         elif key_lv1 == 'cash_flows_in':
#             resu = self.cash_flows_in[key_lv2]
#         elif key_lv1 == 'cash_flows_out':
#             resu = self.cash_flows_out[key_lv2]
#         else:
#             raise ValueError("Could not find ", key_lv1)
#         return resu
# 
#     def get_cash_flow(self):
#         return sum(self.cash_flows_in[key] for key in self.cash_flows_in.keys()) - sum(self.cash_flows_out[key] for key in self.cash_flows_out.keys())


# Path: alm/ALM.py
from ..liability.liability_data.Liabilities_data_m import Liabilities_data_m
from ..liability.liability_data.Liabilities_data import Liabilities_data
from ..esg.ESG_RN import ESG_RN
from .Balance_Sheets import Balance_Sheets
import numpy as np

        # ================================================================================================================================================
        for mdlp in liabilities.liabilities_data.model_points:
            mdlp.profit_sharing_rate[0] = mdlp.TMG[mdlp.seniority]
        # ==========================================
        # Initialize ALM
        # ==========================================
        alm = ALM(assets, liabilities, time_horizon)
        # ==========================================
        # Set up asset allocation
        # ==========================================
        alm.assets.add_allocation(allocation_EQ = 0.2, allocation_bond = 0.7)
        value = alm.liabilities.technical_provision.mathematical_provision[0]
        alm.assets.initialize_EQ_value(value = assets.allocations['EQ']*value)
        alm.assets.bonds.initialize_allocation(amount=assets.allocations['bonds']*value)
        # ===============================
        # Set up deflators
        # ===============================
        alm.assets.deflators = alm.assets.ESG_RN.scenarios[traj]['Deflators']
        
        print(alm.assets.bonds.init_rating_based_deflators[0])        
        
        bond_market_value = alm.assets.get_bond_market_value(0)
        bond_book_value = alm.assets.get_bond_book_value(0)
        # ==============================
        #          Cash
        # ==============================
        alm.assets.add_cash(amount = alm.assets.allocations['cash'] * value)
        # ================================
        # Initialize Balance Sheet
        # ================================

        BS = Balance_Sheets()