프로그래밍/파이썬

환율 예측 chatgpt

do121 2023. 2. 24. 04:50

import pandas_datareader as pdr
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.arima.model import ARIMA

# Set the start and end dates for the exchange rate data
start_date = '2000-01-01'
end_date = '2022-02-22'

# Get exchange rate data from FRED using pandas_datareader
df = pdr.get_data_fred('DEXKOUS', start_date, end_date)

# Split the data into training and testing sets
train_data = df.loc['2000-01-01':'2019-12-31']
test_data = df.loc['2020-01-01':]

# Fit an ARIMA model to the training data
model = ARIMA(train_data, order=(1,1,1))
result = model.fit()

# Use the model to make predictions on the testing data
forecast = result.forecast(steps=len(test_data))

# Plot the predicted values against the actual values
plt.plot(test_data, label='Actual')
plt.plot(forecast, label='Forecast')
plt.legend()
plt.show()

# Print the forecasted values for the next 30 days
last_date = df.index[-1]
next_date = pd.date_range(start=last_date, periods=30, freq='D')
next_date_str = next_date.strftime('%Y-%m-%d')
next_values = pdr.get_data_fred('DEXKOUS', start_date=last_date, end_date=next_date_str)
print("Forecasted values for the next 30 days:")
print(next_values)

'프로그래밍 > 파이썬' 카테고리의 다른 글

flask 에서 인수를 받는 방법 chatgpt  (0) 2023.03.28
pdf 근접단어 찾기(pdfminer) chatgpt  (0) 2023.03.21
pdf 근접단어 찾기 chatgpt  (0) 2023.03.21
에러 메세지  (0) 2022.12.06
파이썬 팁  (0) 2022.12.06