this ode was using for making backtest predictions, I liked how it predicts, can you adapt so it predicts to next 365 days?# Define backtest period: last 365 days
backtest_days = 365
backtest_start_idx = len(zayavki)

# Storage for predictions
preds_linear = []
preds_weekday = []
preds_weekday_month = []
actuals = []

print("Running rolling backtest...")

for idx in range(backtest_start_idx, len(zayavki)):
    # Define training window: 365 days before the prediction day
    train_end = idx
    train_start = max(0, train_end - 365)
    train = zayavki.iloc[train_start:train_end].copy()
    
    # Skip if not enough data
    if len(train) < 365:
        preds_linear.append(np.nan)
        preds_weekday.append(np.nan)
        preds_weekday_month.append(np.nan)
        actuals.append(np.nan)
        continue
    
    # Prepare training features
    train['Days'] = (train['date_period'] - train['date_period'].min()).dt.days
    train['weekday'] = train['date_period'].dt.dayofweek
    train['month'] = train['date_period'].dt.month
    
    # 1. Fit linear trend
    X_train = train[['Days']]
    y_train = train['Кол-во заявок']
    model = LinearRegression()
    model.fit(X_train, y_train)
    
    # 2. Calculate weekday seasonality factors
    weekday_means = train.groupby('weekday')['Кол-во заявок'].mean()
    overall_mean = train['Кол-во заявок'].mean()
    weekday_factors = weekday_means / overall_mean
    
    # 3. Calculate monthly additive seasonality
    train['trend'] = model.predict(X_train)
    train['weekday_factor'] = train['weekday'].map(weekday_factors)
    train['residual'] = train['Кол-во заявок'] - (train['trend'] * train['weekday_factor'])
    monthly_additive = train.groupby('month')['residual'].mean()
    
    # Prepare test day
    test_row = zayavki.iloc[idx]
    test_day = (test_row['date_period'] - train['date_period'].min()).days
    test_weekday = test_row['date_period'].dayofweek
    test_month = test_row['date_period'].month
    
    # Make predictions
    # 1. Linear prediction
    pred_linear = model.predict(np.array([[test_day]]))[0]
    
    # 2. Weekday seasonal prediction
    weekday_factor = weekday_factors.get(test_weekday, 1.0)
    pred_weekday = pred_linear * weekday_factor
    
    # 3. Weekday + Monthly prediction
    monthly_adj = monthly_additive.get(test_month, 0.0)
    pred_weekday_month = pred_weekday + monthly_adj
    
    # Store predictions and actual
    preds_linear.append(pred_linear)
    preds_weekday.append(pred_weekday)
    preds_weekday_month.append(pred_weekday_month)
    actuals.append(test_row['Кол-во заявок'])
    
    # Progress indicator
    if (idx - backtest_start_idx + 1) % 50 == 0:
        print(f"Processed {idx - backtest_start_idx + 1}/{backtest_days} days")

print("Backtest completed!")


import matplotlib.pyplot as plt

# Get corresponding dates for plotting
backtest_dates = zayavki['date_period'].iloc[backtest_start_idx:backtest_start_idx + len(actuals_clean)]

plt.figure(figsize=(16, 8))
plt.plot(backtest_dates, actuals_clean, label='Actual zayavki', color='blue', linewidth=2)
plt.plot(backtest_dates, preds_linear_clean, label=f'Linear (SMAPE: {smape_linear:.2f}%)', color='orange', linestyle='--')
plt.plot(backtest_dates, preds_weekday_month_clean, label=f'Weekday+Monthly (SMAPE: {smape_weekday_month:.2f}%)', color='red', linestyle='--')
plt.plot(backtest_dates, preds_weekday_clean, label=f'Weekday Seasonal (SMAPE: {smape_weekday:.2f}%)', color='green', linestyle='-.')

plt.title('Rolling Backtest: Last 365 Days (Using Previous 365 Days for Training)')
plt.xlabel('Date')
plt.ylabel('zayavki')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()