我有一个df与每日" Adj Close" (来自雅虎)对于我想要与SPY进行比较的许多股票。
AAPL ABC ... SPY
Date
2016-03-10 100.56 85.79 198.52
2016-03-11 101.64 89.14 201.72
...
2016-06-09 99.65 76.17 212.08
2016-06-10 98.83 76.46 210.07
我想描绘除SPY(基准)之外的每个股票的最近3个月。 每张图表都应该将股票价格与SPY价格进行比较。
这意味着,例如,对于绘制AAPL图表,基准SPY_AAPL应计算为:
SPY_AAPL = df['SPY'] / 198.52 * 100.56
...所以AAPL的第一点悬停在" SPY_AAPL"的那一点上。 绘制其他股票的图表需要类似的计算......
SPY_ABC = df['SPY'] / 198.52 * 85.79
我不确定必须将辅助列(SPY_AAPL,SPT_ABC ...)添加到df中。 Perpaps可以随时计算和#34;。
"图表系列"也许可以在" for循环"
for x in df.columns: # how to remove the SPY here?
df[x].tail(66).plot() # 66 is approx 3 months
# SPY_XXX.tail(66).plot() # here the benchmark
plt.show()
非常感谢任何帮助。
答案 0 :(得分:2)