Router Queue Simulation in C++ in MMNN and MM1 conditions
PYTHON_CDS_SPREAD_CALCULATIOn
1. '''
Created on Jan 25, 2016
@author: HTQ
'''
from math import sqrt
from random import gauss
from numpy import ones, random,exp,average,maximum, zeros, array, log, minimum
import time
StartTime=time.clock()
interest_rate=0.05
hazard_rate=0.007
recovery_rate=0.10
time_to_maturity = 10
Traj = 1000000
notional = 1000000
DefaultTime=-log(random.random_sample((Traj,)))/hazard_rate
IFdefault=DefaultTime<time_to_maturity
Payoff=notional*(1-recovery_rate)*exp(-interest_rate*DefaultTime)*IFdefault
Premiumpaytime=minimum(time_to_maturity,DefaultTime)
payment=notional*0.0001* (1-exp(-interest_rate*Premiumpaytime))/interest_rate
CDS_Spread=average(Payoff)/average(payment)
CDS_Premium=CDS_Spread*notional*0.0001
print(CDS_Spread)
print(CDS_Premium)
EndTime=time.clock()
print('It took following seconds to run the program')
print(EndTime-StartTime )