垂直仓y值平均值

2024-06-28 15:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有股票市场数据(从0开始的日期和收盘价),我用这个numpy.fft格式计算快速傅里叶变换和相应的频率,然后以压缩列表的形式显示这些频率,“FFT,Frequency”。我使用以下公式将频率值分隔为垂直对数容器:

logbins = np.logspace(Min(logX),max(logX),numbins=10, base=10.0

然后我将频率值数字化到这些箱子中,并使用:

for k in range(1,len(freqlogbins)):
    mean_freq.append(np.mean(Tfreq2[freqdig==k]))

这很好,但是我还需要计算出每个bin中y值的平均值。你知道吗

我想在某种程度上可能会引用ZippedList[0,i]中的x值,y值作为ZippedList[1,i]

但不知道怎么做。你知道吗

以下是可复制代码的示例:

import numpy as np

T_date0=np.arange(0,400)
T_price=np.random.uniform(100,400, size=400)

T_fft=np.fft.fft(T_price)
Tfreq=np.fft.fftfreq(T_date0.shape[-1])

然后,使用以下方法消除任何负频率值和相应的fft值:

Tfreq2=[]
T_fft2=[]
for i in range(len(Tfreq)):                             
    if Tfreq[i]>0:
        Tfreq2.append(Tfreq[i])
        T_fft2.append(T_fft[i])       
T_fft_absSq=(np.absolute(T_fft2))**2
logTFAS=np.log10(T_fft_absSq)
logTfreq=np.log10(Tfreq2)

numbins=10
logbins=np.logspace((min(logTfreq)-0.00000001),(max(logTfreq)+0.00000001),num=numbins, base=10.0) #The +/-0.00000001 are so that the endpoints lie in the bin intervals.

Tfreq2=np.array(Tfreq2)
TFAS=np.array(T_fft_absSq)

freqdig=np.digitize(Tfreq2,logbins)
mean_freq=[]
mean_fft=[]
for k in range(1,len(logbins)):
mean_freq.append(np.mean(Tfreq2[freqdig==k]))

Fourier=zip(logTfreq,logTFAS)
##This is where I need to work out the mean of the y values, in the vertical bins

下面是数据的样子,其中黑色虚线表示箱子,黄色虚线表示每个箱子中x值的平均值。蓝线是2阶多项式拟合。你知道吗

显然,随机数据看起来会有点不同的链接,我张贴在下面,但它给出了一个想法。你知道吗

Diagrammatic representation


Tags: the数据infftfornpmean频率
2条回答

不太清楚你想要什么,但也许数字化将有助于:

import numpy as np
d = np.random.random(1000)
bins = np.linspace(0, 1, 10)
dig = np.digitize(d, bins)
binmean = [d[dig == i].mean() for i in range(1, len(bins))]

print binmean

我想得太多了。。。。你知道吗

我能够以一种非常相似的方式计算y值平均值,使用频率组合如下:

for k in range(1,len(logbins)):
    mean_freq.append(np.mean(np.array(logTfreq)[freqdig==k]))
    mean_fft.append(np.mean(np.array(logTFAS)[freqdig==k]))

相关问题 更多 >