我如何计算从开始期开始的累计百分比变化 [英] How can I calculate cumulative percentage change from beginning period

查看:224
本文介绍了我如何计算从开始期开始的累计百分比变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建具有滚动累积百分比更改的DataFrame.我想显示从初始购买日期(2014-09-05)起股票的百分比变化.

I am trying to create a DataFrame with a rolling cumulative percentage change. I would like to show the percentage change of the stock from the initial buy date (2014-09-05).

import pandas as pd
import pandas.io.data as web

cvs = web.get_data_yahoo('cvs', '2014-09-05')['Adj Close']

cvsChange = cvs[1:] / cvs.shift(1) - 1

推荐答案

谢谢@EdChum

我要找的是...

PriceChange = cvs.diff().cumsum()
PercentageChange = PriceChange / cvs.iloc[0]

这篇关于我如何计算从开始期开始的累计百分比变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆