netflypsb commited on
Commit
cf382bd
·
verified ·
1 Parent(s): 5b30d11

Create algo/tbats.py

Browse files
Files changed (1) hide show
  1. algo/tbats.py +28 -0
algo/tbats.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tbats import TBATS
2
+ import pandas as pd
3
+
4
+ def tbats_forecast(data, forecast_horizon):
5
+ """
6
+ Forecast future values using the TBATS model, with a dynamic forecast horizon.
7
+
8
+ Parameters:
9
+ - data: Pandas Series of historical closing prices.
10
+ - forecast_horizon: Integer specifying the number of days to forecast.
11
+
12
+ Returns:
13
+ - Pandas Series containing the forecasted values with a datetime index.
14
+ """
15
+ # Instantiate the TBATS estimator with seasonal periods. Adjust these as necessary.
16
+ estimator = TBATS(seasonal_periods=(7, 365.25), use_trend=True, use_box_cox=False)
17
+
18
+ # Fit the model to the historical data
19
+ model = estimator.fit(data)
20
+
21
+ # Forecast for the specified horizon
22
+ forecast = model.forecast(steps=forecast_horizon)
23
+
24
+ # Creating a pandas Series for the forecast, indexed by future dates
25
+ future_dates = pd.date_range(start=data.index[-1] + pd.Timedelta(days=1), periods=forecast_horizon)
26
+ forecast_series = pd.Series(forecast, index=future_dates)
27
+
28
+ return forecast_series