Reputation: 11
This simple linear regression LR
predicts the close
price but it doesn't go further than the end of the dataframe, I mean, I have the last closing price and aside is the prediction, but I want to know the next 10 closing prices which of course I don't have yet because are still coming. How do I see in the LR
column the next 10 predictions without having the closing price yet?
# 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
. . . I want the df ends this way
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
Upvotes: 0
Views: 305
Reputation: 11
Since Linear regression is ax + b
the 10 further predictions would repeat itself, because you don't have any more input to alter the predictions beside the close price, i think, you are trying to look for a Monte Carlo simulation, that would try to predict based on random walk hypothesis for stock market prices.
Upvotes: 1