pandas dataframe 在金融计算中的应用

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计算乘积

发布了3 篇原创文章 · 获赞 0 · 访问量 596

猜你喜欢

转载自blog.csdn.net/flyinbirdf/article/details/82964650