python性能,循环速度提高

时间:2017-01-05 10:28:22

标签: python hadoop multiprocessing python-multithreading

以下函数应针对每38天的股票价格与时间进行内核回归。

def kernelregressions(assetprices, windowperiod): #regresses prices on time
timeindex = np.linspace(1, assetprices.shape[0], assetprices.shape[0]) #time to start from 1 upto the length of the dataset
smoothprices = pd.DataFrame(index=timeindex, columns=assetprices.columns, dtype="float") # empty frame to store the smoothed prices
for symbol in assetprices.columns:
    for i in range(0,assetprices.shape[0]-windowperiod-1, windowperiod+1): #regressions are done for each 38 day period
        smoothprice = KernelReg(assetprices[symbol].iloc[i:i+windowperiod], 
                                timeindex[i:i+windowperiod], var_type="c", bw="cv_ls").fit()[0]
        smoothprices[symbol].iloc[i:i+windowperiod]= smoothprice
return smoothprices #returns smooth prices

" assetprices"输入是一个包含股票价格列的熊猫数据框,在我的情况下窗口期是38。

当数据框有100个价格序列为500天的股票时,上述功能需要永远才能运行。

是否有任何python模块,包等...(或更好的循环方式)我可以利用它来加速这个功能? 这里适用Multiprocessingmultithreading吗?

0 个答案:

没有答案
相关问题