需要有关使用Python查找自然对数返回和线性回归斜率的反馈

时间:2017-03-26 20:44:29

标签: python scipy linear-regression

我正在尝试获取时间序列价格的自然日志返回值,并将它们与Python SciPy库(stats.linregress)一起使用,以获得线性回归线的斜率。这是我第一次尝试这个,并且非常欣赏另一组眼睛和反馈。我认为自然日志返回部分代码存在问题。

symbols = ["'AAN'"]

# Getting x values (number of days in time series = 90)
xValues = []
x = 1
while x <= 90:
    xValues.append(x)
    x += 1

# print xValues

# The y values used in the stats.linregress method; 
# Currently I am getting them from a database, so I will 
# print out the returned values
yValues = []
for s in symbols:
    data90 = setup.last_90_closes(s)

for each in data90:
    # data90 returns a list of tuples, so I needed to 
    # extract the first element from each tuple
    i = each[0]
    yValues.append(i)

NewYValues = np.log(yValues)
# print NewYValues
# print yValues

slope, intercept, r_value, p_value, std_err = stats.linregress(xValues, NewYValues)


print slope

结果: 原来的yValues =

[31.93, 30.26, 29.86, 29.4, 29.37, 29.12, 29.51, 28.88, 29.01, 28.64, 28.63, 28.04, 27.97, 27.47, 26.75, 26.3, 25.71, 26.01, 25.26, 24.84, 24.81, 25.17,
24.71, 24.33, 22.63, 22.95, 23.1, 23.52, 23.23, 23.22, 23.56, 23.42, 22.82, 22.76, 22.77, 22.68, 22.81, 25.62, 25.13, 25.25, 25.17, 24.97, 24.95, 25.42,
24.69, 24.99, 25.14, 24.99, 25.66, 25.59, 25.09, 25.01, 25.01, 24.92, 25.01, 24.71, 24.99, 25.25, 24.73, 25.41, 24.92, 24.17, 24.78, 24.47, 24.36, 24.84,
 25.17, 24.71, 25.04, 25.27, 25.24, 25.23, 25.19, 25.18, 24.83, 24.9, 25.02, 24.76, 24.88, 24.53, 24.56, 24.55, 24.64, 23.94, 23.8, 23.68, 24.08, 23.93,
21.93, 22.88]

NewYValues =

[ 3.46354601  3.40982671  3.39651979  3.38099467  3.37997375  3.37142522
  3.38472919  3.36314931  3.3676406   3.35480434  3.35445512  3.33363206
  3.33113251  3.3130945   3.28653447  3.26956894  3.24688002  3.25848108
  3.22922212  3.21245526  3.2112468   3.22565281  3.20720802  3.19171016
  3.11927646  3.13331794  3.13983262  3.15785112  3.14544455  3.14501398
  3.15955036  3.15359036  3.12763734  3.12500461  3.12544388  3.12148348
  3.12719904  3.2433733   3.22406235  3.22882616  3.22565281  3.2176751
  3.21687382  3.23553627  3.2063983   3.21847574  3.2244602   3.21847574
  3.24493336  3.24220165  3.22246936  3.21927574  3.21927574  3.21567069
  3.21927574  3.20720802  3.21847574  3.22882616  3.20801708  3.2351428
  3.21567069  3.18511219  3.21003688  3.19744788  3.19294244  3.21245526
  3.22565281  3.20720802  3.22047455  3.22961792  3.22843004  3.22803376
  3.22644709  3.22605003  3.2120526   3.2148678   3.21967551  3.20922945
  3.21406427  3.19989686  3.2011191   3.20071185  3.20437114  3.1755507
  3.16968558  3.16463081  3.18138162  3.1751329   3.08785556  3.13026317]

斜率=

-0.00157242772248

我的问题是:结果似乎代表了代码的预期结果吗?

0 个答案:

没有答案