![](/img/trans.png)
[英]QThreadPool are running in sequence not in parallel, what is causing my code threads not run parallel?
[英]What is causing the empty sequence in my code?
我使用的是预创建的代码中调用trendy.py: https://github.com/dysonance/Trendy
代码的某些部分将计算Max1和Max2。 Min1和Min2
对于我选择的每个公司,我都会提供最近100天收盘价的代码。
该代码对某些公司而言按预期工作,但是对于一半以上的公司,它给我带来了ValueError。
min2 = min(x[(min1 + window):])
ValueError: min() arg is an empty sequence
所以对我来说,似乎min1是问题。 无法计算,因此留为空白。 然后将空序列输入给min2。
有人可以看看一下,让我知道您认为导致此问题的原因吗?
这是我用作输入的示例文件(它给了我所描述的错误)。
https://docs.google.com/spreadsheets/d/1xZdSGE05SfyoL9D4akSH0KlV8s2cR1CJLqLlVEzq_4k/edit?usp=sharing
这是代码的相关部分:
def gentrends(x, window=1/3.0, charts=True):
"""
Returns a Pandas dataframe with support and resistance lines.
:param x: One-dimensional data set
:param window: How long the trendlines should be. If window < 1, then it
will be taken as a percentage of the size of the data
:param charts: Boolean value saying whether to print chart to screen
"""
import numpy as np
import pandas as pd
from pandas_datareader import data, wb
x = np.array(x)
if window < 1:
window = int(window * len(x))
max1 = np.where(x == max(x))[0][0] # find the index of the abs max
min1 = np.where(x == min(x))[0][0] # find the index of the abs min
# First the max
if max1 + window > len(x):
max2 = max(x[0:(max1 - window)])
else:
max2 = max(x[(max1 + window):])
# Now the min
if min1 - window < 0:
min2 = min(x[(min1 + window):])
else:
min2 = min(x[0:(min1 - window)])
# Now find the indices of the secondary extrema
max2 = np.where(x == max2)[0][0] # find the index of the 2nd max
min2 = np.where(x == min2)[0][0] # find the index of the 2nd min
如果有人遇到此问题,我会发布此消息。
我所提供的数据是最近100天的收盘价。 但是,如果增加数据点的数量,则遇到的给定错误将少得多。
从Alphavantage API中,在每日时间序列上使用“完整”而不是“紧凑”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.