简单线性回归股票价格预测



这个简单的线性回归LR预测了close的价格,但它不会超过数据帧的末尾,我的意思是,我有最后的收盘价,除了预测之外,我想知道接下来的10个收盘价,当然我还没有,因为它们还在后头。在没有收盘价的情况下,我如何在LR栏中看到接下来的10个预测?

# get prices from the exchange
prices = SESSION_DATA.query_kline(
symbol = 'BTCUSDT',
interval = 60, # timeframe (1 hour)
limit = 200, # numbers of candles
from_time = (TIMESTAMP() - (200 * 60)*60)) # from now go back 200 candles, 1 hour each
# pull data to a dataframe
df = pd.DataFrame(prices['result'])
df = df[['open_time','open','high','low','close']].astype(float)
df['open_time'] = pd.to_datetime(df['open_time'], unit='s')
# df['open_time'] = pd.to_datetime(df['open_time':]).strftime("%Y%m%d %I:%M:%S")
df.rename(columns={'open_time': 'Date'}, inplace=True)
# using Ta-Lib
prediction = TAL.LINEARREG(df['close'], 10)
df['LR'] = prediction
print(df)

Date     open    high    low     close   LR
0   2022-10-06 14:00:00 20099.0 20116.5 19871.5 20099.0 NaN
1   2022-10-06 15:00:00 20099.0 20115.5 19987.0 20002.5 NaN
2   2022-10-06 16:00:00 20002.5 20092.0 19932.5 20050.0 NaN
3   2022-10-06 17:00:00 20050.0 20270.0 20002.5 20105.5 NaN
4   2022-10-06 18:00:00 20105.5 20106.0 19979.0 20010.5 NaN
5   2022-10-06 19:00:00 20010.5 20063.0 19985.0 20004.5 NaN
6   2022-10-06 20:00:00 20004.5 20064.5 19995.5 20042.5 NaN
7   2022-10-06 21:00:00 20042.5 20043.0 19878.5 19905.0 NaN
8   2022-10-06 22:00:00 19905.0 19944.0 19836.5 19894.0 NaN
9   2022-10-06 23:00:00 19894.0 19965.0 19851.0 19954.5 19925.527273
10  2022-10-07 00:00:00 19954.5 20039.5 19937.5 19984.5 19936.263636
11  2022-10-07 01:00:00 19984.5 20010.0 19957.0 19988.5 19935.327273

我希望df以这种方式结束

188 2022-10-14 10:00:00 19639.0 19733.5 19621.0 19680.0 19623.827273
189 2022-10-14 11:00:00 19680.0 19729.0 19576.5 NaN     19592.990909
190 2022-10-14 12:00:00 19586.5 19835.0 19535.5 NaN     19638.054545
191 2022-10-14 13:00:00 19785.5 19799.0 19612.0 NaN     19637.463636
192 2022-10-14 14:00:00 19656.5 19656.5 19334.5 NaN     19574.572727
193 2022-10-14 15:00:00 19455.0 19507.5 19303.5 NaN     19493.990909
194 2022-10-14 16:00:00 19351.0 19390.0 19220.0 NaN     19416.154545
195 2022-10-14 17:00:00 19296.5 19369.5 19284.5 NaN     19356.072727
196 2022-10-14 18:00:00 19358.0 19358.0 19127.5 NaN     19253.918182
197 2022-10-14 19:00:00 19208.5 19264.5 19100.0 NaN     19164.745455
198 2022-10-14 20:00:00 19164.0 19211.0 19114.0 NaN     19112.445455
199 2022-10-14 21:00:00 19172.0 19201.0 19125.0 NaN     19067.772727

由于线性回归是ax + b,10个进一步的预测将重复,因为除了收盘价之外,你没有更多的输入来改变预测,我认为,你正在尝试寻找蒙特卡罗模拟,它将尝试基于股市价格的随机游走假设进行预测。

最新更新