months = dict() for year in range(2007,2026): months[year]=[str(year*100+month) for month in range(1,13)] count, sum, sumSq, mean, stdev = dict(), dict(), dict(), dict(), dict() for firm in firms: for year in range(2007, 2026): t = (firm, year) #元組(公司,年) count[t] = 0 sum[t] = 0.0 sumSq[t] = 0.0 for row in rows: #字典value增加append元素 for firm in firms: if row[0] == firm: for year in range(2007, 2026): t = (firm, year) for month in months[year]: if row[1] == month: count[t] +=1 temp = float(row[8]) sum[t] += temp sumSq[t] += temp*temp for firm in firms: #以下計算各年度月報酬率的平均數與標準差 for year in range(2007, 2026): t = (firm, year) temp1 = count[t] temp2 = sum[t] mean[t] = temp2 / temp1 temp2 = sumSq[t] - temp2 * temp2 / temp1 ...
請用其他有意義的名稱取代媒體1,https://ktglgfk.blogspot.com/2025/06/pythoncsvtkintermarkowitz.html
回覆刪除