단순히 anaconda prompt에서 pip install backtrader로 설치하고
cerebro.run()을 실행했을 때 위과 같은 에러가 계속 발생했다.
이를 해결하고자 구글링해봤을 때 backtrader 패키지 내부의 yahoo.py의 코드를 수정해줘야 한다는 솔루션이 대부분이었다.
하지만 코드를 수정함과 동시에 패키지 재설치 및 파이썬 버전까지 바꿔가며 실행해봤으나 같은 에러가 계속 발생했다. 아마도 버전이 바뀌면서 해당 솔루션도 현재 시점에서 해결이 안되는 경우가 생긴듯 했다.
그러던 찰나에 최근 솔루션을 발견하게 되었고
https://github.com/mementum/backtrader/pull/453
Yahoo 404 - Changed the request User-Agent to accepted value by frruit · Pull Request #453 · mementum/backtrader
Without this change the simple basic tutorials are not executable because yahoo blocks the default user agent from the requests lib
github.com
Don‘t install backtrader via pip.git clone this repo and then copy backtrader folder to your site-packages
backtrader github의 conversation에서 위와 같은 솔루션을 발견했다
https://github.com/mementum/backtrader
GitHub - mementum/backtrader: Python Backtesting library for trading strategies
Python Backtesting library for trading strategies. Contribute to mementum/backtrader development by creating an account on GitHub.
github.com
위의 링크를 따라 backtrader github의 파일을 clone하거나 .zip으로 다운로드한 뒤
해당 파일내의 backtrader 파일을 현재 활용하고 있는 환경의 site-packages에 복사해주니 원활하게 작동했다.
ex) C:\Users\Owner\anaconda3\envs\backtrader\Lib\site-packages
현재 나는 backtrader라는 가상환경을 활용 중이다
계속 오류가 나서 고생했는데 이렇게 수동적으로 패키지를 수정하거나 다운로드 받는 방법에 대해 하나 더 알게되어 기뻤다.
'datascience > Finanace' 카테고리의 다른 글
문자열 앞에 0채우기(주식 ticker) (0) | 2022.03.20 |
---|---|
금융 투자 기본 개념(샤프비율, 효율적 투자선) (0) | 2021.05.08 |
금융 투자 기본 개념(Return, Risk) (0) | 2021.05.02 |
yfinance를 활용한 코스피와 S&P500지수 비교 (0) | 2021.04.16 |
yfinance를 활용한 주식 데이터 불러오기 (0) | 2021.04.11 |