[英]An infinite while loop in python with pandas calculating the standard deviation
[英]Infinite while loop pandas?
我在運行一個無限循環嗎? 如果是這樣,我該如何解決這個問題?
代碼如下:
new_exit_date, new_exit_price = [] , []
high_price_series = df_prices.High['GTT']
entry_date = df_entry.loc['GTT','entry_date']
window_price_series = high_price_series[high_price_series.index >= entry_date]
while len(window_price_series) >= 63:
window_high_series = window_price_series[-63:]
last_date_of_window = window_high_series.index[0]
entire_hist = high_price_series[high_price_series.index <= last_date_of_window]
if window_high_series.max() != entire_hist.max():
new_exit_date.append(window_price_series.index[-64])
new_exit_price.append(window_price_series[-64])
break
else:
window_price_series = window_price_series[window_price_series.index >= window_high_series.idxmax()]
if len(window_price_series) < 63:
new_exit_date.append(window_price_series.index[0])
new_exit_price.append(window_price_series[0])
high_price_series
是股票 GTT 的 Pandas 系列價格。 entry_date
給出了我們為股票 GTT 輸入買單的日期。 假設我們在 2018-03-02 進入。 所以entry_date
取值'2018-03-02'
。 假設在 63 個交易日的 window 內,GTT 在 2018 年 3 月 26 日創下歷史新高,即window_high_series.max() == entire_hist.max()
,那么我要做的就是更新window_price_series
以從2018-03-26,再次檢查GTT是否在2018-03-26的63個交易日內創歷史新高。
high_prices_series
看起來像
Date
2021-04-01 1.89
2021-03-31 1.90
...
2018-03-26 62.32
2018-03-25 62.35
...
2018-03-02 49.00
那就是索引是按降序排列的。
我不確定代碼在哪里運行到無限循環。 它會在整個entire_hist = high_price_series[high_price_series.index <= last_date_of_window
嗎?
如果您需要更多信息,請發表評論。
請改用window_price_series = window_price_series[window_price_series.index > window_high_series.idxmax()]
。 一個>
符號而不是>=
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.