본문 바로가기

Python

ARIMA

 

1.환율

 

10년 주기설은 잘 맞는 거 같다.

 

원인이 무엇이든 숫자로 표현되는 결과는 같다.

 

금 상승, 미 국채수익률 하락, 유가 폭락, 환율 급등.




 2. timeseries

워낙 환율이 이슈라 말할 무언가가 필요하다.
 
아주 기본적인 timeseries 부터 다시 시작해보자.
 
EVIEWS 등의 간단한 통계 package에서 손쉽게 가능하지만 python을 통한 code분석은 모델의 기본적인 구조를
 
어떻게 구현했는지 살펴볼 수 있는 장점이 있다.
 
 


3. ARIMA

 

ARIMA 모형 설명은 넘치고 넘치지만 아래 사이트를 베이스로 진행.

 

https://dataplatform.cloud.ibm.com/exchange/public/entry/view/815137c868b916821dec777bdc23013c

 

IBM Watson Studio

{"locales":"en-US","messages":{"CommonHeader.client.trial.days":"Your trial ends in {number} days","CommonHeader.client.trial.tomorrow":"Your trial ends tomorrow","CommonHeader.client.trial.subtitle":"When your trial ends, your data will not be erased but

dataplatform.cloud.ibm.com

한국어로는 아래 사이트 참조

https://byeongkijeong.github.io/ARIMA-with-Python/

 

ARIMA, Python으로 하는 시계열분석 (feat. 비트코인 가격예측)

서론 시계열 분석(Time series analysis)이란, 독립변수(Independent variable)를 이용하여 종속변수(Dependent variable)를 예측하는 일반적인 기계학습 방법론에 대하여 시간을 독립변수로 사용한다는 특징이 있다. 독립변수로 시간을 사용하는 특성때문에 분석에 있어서 일반적인 방법론들과는 다른 몇가지 고려가 필요하다. 본 포스트에서는 시계열 분석(혹은 예측)에 있어서 가장 널리 사용되는 모델중 하나인 ARIMA에 대해

byeongkijeong.github.io

 

 

 

 

4. 몇 가지 오류와 해결방법

 

인터넷에서 공개된 code를 따라하다 보면 마주치는 수 많은 에러.

 

1. exog contains inf or nans

 

https://stackoverflow.com/questions/55100413/arima-model-missingdataerror-exog-contains-inf-or-nans

 

ARIMA Model - MissingDataError: exog contains inf or nans

I am trying to forecast few values using ARIMA Model. I get the following error. I have tried to remove the stationarity and other necessary conditions for the forecasting. Can someone point me out...

stackoverflow.com

 

나 같은 경우 일별 환율을  주간 환율로 resample 한 이후 staionarity 검증할 때 위와 같은 에러가 발생. 

 

검색 결과 몇 시간을 고민한 끝에 알아낸 점은 데이터 결측치가 존재했던 것.

 

주간 평균 데이터 엑셀로 받아서 보니 한주 값이 비어 있었다..

 

그래서 다음과 같은 코드 추가

 

1
2
# any missing values?

결측치가 존재하는지 확인하고

 

1
fx_krw_week = fx_krw_week.dropna(axis = 0)

지워버리기.

모든 분석의 핵심은 데이터 전처리 

 

 

1. ValueError: You must specify a freq or x must be a pandas object with a timeseries index with a freq not set to None 

 

다음 단계인 decomposion에서 역시 에러 발생.

 

https://stackoverflow.com/questions/39272806/valueerror-you-must-specify-a-freq-or-x-must-be-a-pandas-object-with-a-timeseri?noredirect=1&lq=1

 

Time Series Analysis - unevenly spaced measures - pandas + statsmodels

I have two numpy arrays light_points and time_points and would like to use some time series analysis methods on those data. I then tried this : import statsmodels.api as sm import pandas as pd td...

stackoverflow.com

그래서 코드를 아래와 같이 수정. 

1
decomposition = seasonal_decompose(fx_krw_week, freq = 52)