为什么在循环上出现KeyError:0?

时间:2019-05-28 18:31:00

标签: python-3.x pandas loops for-loop finance

我正在尝试计算如下的股息折扣模型

P = sum from t to T of Kd_t x ROS_t x SPS_t/(1+Re_t)^t + SPS_t x P/SPS_t/(1+Re_T)^T

我有一个包含33年财务数据的数据框:Kd, SPS, ROS, Re, P/SPS

for i in range(len(stock1.SPS)):
    sum = 0
    k=0
    for j in range(i, len(stock1.SPS)):
        sum = sum + (stock1.Kd[j] * stock1.ROS[j] * stock1.SPS[j] / (1 + stock1.Re[j])**k + stock1.SPS[j] * stock1.P_SPS[j] / (1 + stock1.Re[j])**(len(stock1.SPS) - i))
        k = k + 1
        price_f = price_f.append(sum)

输出应为33个股票价格 我想问题出在循环中

0 个答案:

没有答案