pandas dataframe 在金融计算中的应用

本文详细解析了Pandas库中DataFrame.shift()函数的使用方法,包括参数解释、示例展示以及数学公式如复利计算和对数收益率的介绍。通过实例说明了如何在数据处理中实现时间序列数据的前移或后移。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DataFrame.shift(periods=1freq=Noneaxis=0)[source]

Shift index by desired number of periods with an optional time freq

Parameters:

periods : int

Number of periods to move, can be positive or negative

freq : DateOffset, timedelta, or time rule string, optional

Increment to use from the tseries module or time rule (e.g. ‘EOM’). See Notes.

axis : {0 or ‘index’, 1 or ‘columns’}

Returns:

shifted : DataFrame

 

假设obj为DataFrame结构体,

例如:

obj = [

[2012-12-12  12  13  14  15],

[2012-12-13  21  22  23  24]

]

obj.shift(1)后(该偏移为行偏移),为

obj = [

[2012-12-12  Nan  Nan  Nan  Nan],

[2012-12-13  12  13  14  15]

]

如果指定按列偏移,则为obj.shift(1, axis=1)

R=ln(r+1)     r=(Pt - Pt-1) / Pt-1  r为盈利百分比 。 当|r|<<1的时候,ln(r+1)约等于r

compounding:复利,每年的盈利作为下一年的本金计算盈利。复利的计算公式为:

Pt=Pt-1*(1+r/n)**n

当n趋向无穷时,(1+r/n)**n =e**r

numpy.prod计算乘积

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值