55from lennart_epp .analysis .forecast_ar import forecast_ar_multi_step
66from lennart_epp .config import BLD
77
8- # Konstanten für Fehlermeldungen
9- missing_close_price_msg = "Spalte 'close_price' fehlt!"
10- too_few_train_msg = "Zu wenige Trainingsdaten."
11- type_forecast_msg = "Forecast muss 'pd.Series' sein."
12- multi_forecast_msg = "Forecast enthält mehrdimensionale Werte."
8+ missing_close_price_msg = "Column 'close_price' missing!"
9+ too_few_train_msg = "Not enough training data."
10+ type_forecast_msg = "Forecast has to be 'pd.Series'."
11+ multi_forecast_msg = "Forecast contains multi-dimensional values."
1312
1413
1514def task_forecast_ar (
1615 data = BLD / "data" / "cleaned_apple_data.pkl" ,
17- produces = BLD / "forecasts" / "apple_2023_forecast .pkl" ,
18- lags = 30 ,
16+ produces = BLD / "forecasts" / "multistep_forecast .pkl" ,
17+ lags = 50 ,
1918):
19+ """Generate multi-step forecasts using an AR model.
20+
21+ Args:
22+ data (Path): Path to the cleaned Apple stock data.
23+ produces (Path): Path to store the multi-step forecast as a pickle file.
24+ lags (int, optional): Number of lags to use for the AR model.
25+
26+ Raises:
27+ KeyError: If the required "close_price" column is missing.
28+ ValueError: If there are insufficient training data.
29+ TypeError: If the forecast is not a Pandas Series.
30+ ValueError: If the forecast contains multi-dimensional values.
31+
32+ Returns:
33+ None: Saves the forecast to specified output files.
34+ """
2035 df = pd .read_pickle (data )
2136 if "close_price" not in df .columns :
2237 raise KeyError (missing_close_price_msg )
@@ -26,18 +41,15 @@ def task_forecast_ar(
2641 if len (train_data ) < lags :
2742 raise ValueError (too_few_train_msg )
2843
29- # AR-Modell fitten, um die integrierten Koeffizienten zu erhalten
3044 ar_result = fit_ar_model (train_data .to_frame (), column = "close_price" , p = lags )
3145 integrated_coefficients = ar_result ["integrated_coefficients" ]
3246
33- # Forecast mit den integrierten Koeffizienten berechnen
3447 forecast = forecast_ar_multi_step (
3548 df ,
3649 integrated_coefficients = integrated_coefficients ,
3750 forecast_steps = lags ,
3851 )
3952
40- # Validierung before dem Speichern
4153 if not isinstance (forecast , pd .Series ):
4254 raise TypeError (type_forecast_msg )
4355 if forecast .apply (lambda x : isinstance (x , list | np .ndarray )).any ():
0 commit comments