如何解决识别时间序列中的熊市期,股票数据
如何识别时间序列中价格下跌幅度大于某个阈值、在一定时间内且数据时间不是周期性的(熊)期?
例如,确定的(熊)期价格应在 2 小时内下降 3% 或更多。
import yfinance as yf
import pandas as pd
from datetime import datetime
import random
def random_times(stime,etime,n):
frmt = '%Y-%m-%d %H:%M:%S'
stime = datetime.strptime(stime,frmt)
etime = datetime.strptime(etime,frmt)
td = etime - stime
return [random.random() * td + stime for _ in range(n)]
# Getting historical,daily ohlc data from yfinance
msft = yf.Ticker("MSFT")
hist = msft.history(period="max")
# Generating random datetimes for rows in yfinance data
datetimes = random_times('2020-01-01 00:00:00','2021-01-30 00:00:00',len(hist.index))
datetimes = pd.to_datetime(datetimes)
datetimes = datetimes.sort_values()
# Dataframe with random datetimes and real MSTF close prices
df = pd.DataFrame({ 'time': datetimes,'close': hist['Close']})
df = df.set_index('time')
df.plot(figsize=(50,30))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。