Преобразование линии Хафа Python - PullRequest
0 голосов
/ 30 мая 2020
ticker,PeakDataFrame,TroughDataFrame,Peakindex,Troughindex=IDXS(Period='6mo',Ticker='SPY')
# ticker returns dataframe of date,closing prices of ticker ; Peak/Trough index returns index position of the peak and trough closing prices in the ticker dataframe  



thetas=np.linspace(-(np.pi/2),np.pi/2,90*10*2)
cos_thetas,sin_thetas=np.cos(thetas),np.sin(thetas)
a,b=0,0
for i in range(len(ticker['Close'])):
    if a<i and b<ticker['Close'][i]:
        a,b=i,ticker['Close'][i] # Returns highest close and furthest from start date
diag_len=int(np.ceil(np.sqrt(a**2+b**2)))
rho=np.linspace(-diag_len,diag_len,diag_len*2)
accumulator=np.zeros((len(rho),len(thetas)),dtype=np.uint64) # Create accumulator with rows equivalent to no.of rhos and columns equivalent to no.of thetas

for i in Peakindex:
    y=ticker['Close'][i]
    x=i
    for THETA in range(len(thetas)):
        RHO=int(np.round(x * cos_thetas[THETA] + y * sin_thetas[THETA]))
        accumulator[ RHO , THETA ] += 1
print(accumulator.shape)

hspace,angles,dists=hough_line_peaks(hspace=accumulator,angles=thetas,dists=rho,threshold=3)

x,y = [],[]
for angle,distance in zip(angles,dists):
    x.append(distance * np.cos(angle))
    y.append(distance * np.sin(angle))

print(x,y)

Возвращенные значения x и y, похоже, не попадают в границы цен закрытия, может ли кто-нибудь сказать мне, что не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...