请问各位大神,Python3.8中这段代码运行正常,但是print()后没有输出结果,是什么情况?


在这里插入代码片

from scipy import stats
from scipy.optimize import fsolve
import numpy as np
def KMVOptSearch(E, D, r, T, EquityTheta):
EtoD = float(E) / float(D)
# print(EtoD)
# print()
# global i
# i = 1
def KMVfun(x, EtoD, r, T, EquityTheta):
EtoD, r, T, EquityTheta = float(EtoD), float®, float(T), float(EquityTheta)
d1 = (np.log(x[0] * EtoD) + (r + 0.5 * x[1] ** 2) * T) / (x[1] * np.sqrt(T))
d2 = d1 - x[1] * np.sqrt(T)
# global i
# print(“第{}次计算:”.format(i))
# i += 1
# print(x[0],x[1])
# print(x[0] * stats.norm.cdf(d1, 0.0, 1.0) - np.exp(-r * T) * stats.norm.cdf(d2, 0.0, 1.0) / EtoD - 1,
# stats.norm.cdf(d1, 0.0, 1.0) * x[0] * x[1] - EquityTheta
# )
# print()
return [
x[0] * stats.norm.cdf(d1, 0.0, 1.0) - np.exp(-r * T) * stats.norm.cdf(d2, 0.0, 1.0) / EtoD - 1,
stats.norm.cdf(d1, 0.0, 1.0) * x[0] * x[1] - EquityTheta
]
# print()
VaThetaX = fsolve(KMVfun, [1, 0.1], args=(EtoD, r, T, EquityTheta))
Va = VaThetaX[0] * E
AssetTheta = VaThetaX[1]
return Va, AssetTheta
# 无风险列表
r_list = [0.0251, 0.0173, 0.0150, 0.0150, 0.0150, 0.0150]
# 违约触发点列表
DP_list = [2140334854, 2406595530, 1680334683, 2363501441, 2470386057, 2947048737]
# 债券面值列表
D_list = [30983551225, 29893388116, 23062745183, 22235856439]
# 股权收益率波动率列表
PriceTheta_list = [0.4155, 0.6321, 0.3676, 0.2174, 0.1781, 0.1448]
# 股权市场价值列表
E_list = [7684982705, 6719038694, 5102104575, 5327292242, 4788084118, 3801898642]
for i in range(6):
# 利用KMV模型计算
r = r_list[i] # 无风险利率
T = 1 # 期权到期时间,以年为单位
SD = 1e8 # LD为长期负债 (单位:元)
LD = 50000000 # TD短期负债 (单位:元)
DP = DP_list[i] # 违约触发点DPT # DP=(TD-LD) +0.5LD (7) 其中:TD为总负债;LD为长期负债。 (单位:元)
D = DP # D=TD-LD+0.5∗LD 债券的面值是D (单位:元)
PriceTheta = PriceTheta_list[i] # 交易波动率,可以是日月年的数据 (单位:%)
EquityTheta = PriceTheta # 股权收益率的波动率σE
E = E_list[i] # 公司股票的市场价值 (单位:元)
Va, AssetTheta = KMVOptSearch(E, D, r, T, EquityTheta) # 资产价值VA(单位:元)资产收益率波动率σA
AssetTheta = AssetTheta # 资产收益率波动率σA (单位:%)
DD = (Va - DP) / (Va * AssetTheta) # 违约距离DD
EDF = stats.norm.cdf(-DD) # 预期违约概率EDF(单位:%)

  print("第{}季度的情况:".format(i + 1))    
  print('Va=', Va)
  print('AssetTheta=', AssetTheta)
  print('DD=', DD)
  print('EDF={}%'.format(EDF * 100))
  print()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值