可以使用np.log和np.exp这两个:
x=5000 y=6000 ret=np.log(float(6000)/float(5000)) print ret new_y=6000/float(np.exp(ret)) print new_y
#举一个更加复杂的例子:
import pandas as pd import numpy as np #计算收益率 x=range(0,1000,1) y=range(1,1001,1) data=map(lambda (a,b):float(a)/float(b), zip(x,y)) ret=np.log(data) #还原价格序列 last_close=y[-1] new_x=[] for i in range(len(ret)): j=len(ret)-i-1 if i==0: new_close=last_close new_x.append(new_close) if i>0: new_close=np.exp(ret[-(i)])*y[-i] new_x.append(new_close) new_x.reverse()