gpt4 book ai didi

python - 每日赫斯特指数

转载 作者:行者123 更新时间:2023-11-28 18:33:38 25 4
gpt4 key购买 nike

我正在尝试估算股票 yield 的每日 Hurst 指数值(例如,每天也有 Hurst 指数 - 类似于:https://www.quandl.com/data/PE/CKEC_HURST-Hurst-Exponent-of-Carmike-Cinemas-Inc-Common-Stock-CKEC-NASDAQ)。

我正在使用这段 Python 代码(取自 https://www.quantstart.com/articles/Basics-of-Statistical-Mean-Reversion-Testing ),但我不知道如何将它用于每日 Hurst 值而不是仅一个值:

from datetime import datetime
from pandas.io.data import DataReader
from numpy import cumsum, log, polyfit, sqrt, std, subtract
from numpy.random import randn

def hurst(ts):

"""Returns the Hurst Exponent of the time series vector ts"""
# Create the range of lag values
lags = range(2, 100)

# Calculate the array of the variances of the lagged differences
tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]

# Use a linear fit to estimate the Hurst Exponent
poly = polyfit(log(lags), log(tau), 1)

# Return the Hurst exponent from the polyfit output
return poly[0]*2.0


# Download the stock prices series from Yahoo
aapl = DataReader("AAPL", "yahoo", datetime(2012,1,1), datetime(2015,9,18))

# Call the function
hurst(aapl['Adj Close'])

最佳答案

我猜你的意思是:

from datetime import timedelta
current_date = datetime(2012,1,3)
end_date = datetime(2015,9,18)
aapl = DataReader("AAPL", "yahoo", current_date, end_date)
index = 0
while index < len(aapl['Adj Close']):
print current_date.strftime("%Y-%m-%d")
print hurst(aapl['Adj Close'][index:index + 1])
index += 1
current_date += timedelta(days=1)

关于python - 每日赫斯特指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com