DataFrame.
shift
(periods=1, freq=None, axis=0)[source]¶
Shift index by desired number of periods with an optional time freq
Parameters: | periods : int
freq : DateOffset, timedelta, or time rule string, optional
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计算乘积