snowball

자산배분 전략 백테스팅 패키지

https://github.com/hongjunhyoung/snowball

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (3.3%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

자산배분 전략 백테스팅 패키지

Basic Info
  • Host: GitHub
  • Owner: HongJunhyoung
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 5.19 MB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 5
  • Open Issues: 0
  • Releases: 0
Created over 5 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Snowball

Snowball은 자산 배분 전략을 손쉽게 백테스팅할 수 있는 파이썬 패키지입니다.

 

설치 방법

소스 코드는 GitHub에 올라와 있으며 최신버전은 pip로 설치할 수 있습니다. sh pip install snowball  

실행 예시

아래 예제를 실행하기 전에 FianceDataReader 패키지를 우선 설치해 주세요.
또 다른 예제들은 docs 디렉토리안의 sample 노트북을 참고하시기 바랍니다.  

한국 주식 채권 60/40

  • 2013년부터 매월말 리밸런싱: 한국 주식 ETF 60%, 한국 국채 ETF 40%
  • 거래 비용(수수료 및 슬리피지) 0.2% 가정 ```py import snowball as sb import FinanceDataReader as fdr

etfs = ['069500', '114820'] data = pd.concat([fdr.DataReader(etf)['Close'].rename(etf) for etf in etfs], axis=1)

bt = sb.run_backtest(prices=data, schedule='EOM', rule={'069500': 0.6, '114820': 0.4}, cost=0.002, start='2012-12-01') bt.report() ``` report_sample  

사용 방법

결과 리포트내 챠트가 plotly로 구현되어 있으므로 jupyter notebook에서 실행하는 것을 권장합니다.  

1. 자산 가격 데이터 준비

  • 투자할 자산(주식, ETF, Index, Commodity, etc.)의 일일 가격 데이터를 준비합니다.
  • 데이터 타입은 Pandas DataFrame이어야 합니다. py print(price_data) |date|ETFA|ETFB|ETF_C| |---|---|---|---| |2000-11-21|140.2723|203.29|2317.70| |2000-11-27|140.2707|204.39|2318.63| |2000-11-28|140.2121|204.87|2318.44| |...|...|...|...| |2020-12-01|137.8898|200.26|2316.95| |2020-12-02|139.8906|200.32|2316.53| |2020-12-03|138.7654|200.19|2315.77|   ### 2. 백테스팅
  • run_backtest() 함수를 이용하여 간단하게 포트폴리오의 성과를 시뮬레이션할 수 있습니다.
  • 리밸런싱 시점은 월말, 분기말, 년말, 사용자 정의 일자를 지원합니다.
  • 리밸런싱 방법은 동일 비중, 리스크 패리티, 정적 배분, 사용자 정의 규칙을 지원합니다. ```py import snowball as sb

동일 비중 / 월말 리밸런싱

bt = sb.runbacktest(prices=pricedata, schedule='EOM', rule='EqualWeight', start='2000-12-31') py

리스크 패리티 / 분기초(분기말 1영업일후) 리밸런싱

bt = sb.runbacktest(prices=pricedata, schedule='EOQ+1', rule='RiskParity', start='2000-12-31') py

정적 배분 / 매년말 5영업일전 리밸런싱

bt = sb.runbacktest(prices=pricedata, schedule='EOY-5', rule={'ETFA': 0.6, 'ETFB': 0.4}, start='2000-12-31') py

사용자 정의 규칙 / 지정일자

class MyRule(sb.Rule): def init(self): ...

def calculate(self, date, *args, **kwargs):
    if date < pd.to_datetime('2005-01-01'):
        weights = {'ETF_A': 0.7, 'ETF_B': 0.3}
    else:
        weights = {'ETF_A': 0.3, 'ETF_B': 0.7}
    return pd.Series(weights)

myrule = MyRule() myschedule = ['2001-06-30', '2005-06-30'] bt = sb.runbacktest(prices=pricedata, schedule=myschedule, rule=myrule, start='2000-12-31') ```  

3. 성과 분석

  • run_backtest()가 반환한 오브젝트의 report() 함수를 이용하여 결과를 확인합니다.
  • jupyter lab에서 챠트 표시가 정상적으로 되지 않는 경우 plotly extension을 설치하여 주십시오.
  • 챠트 때문에 노트북 렌더링이 느려지는 경우에는 charts='static' 또는 charts=None 옵션을 사용하시기 바랍니다. py bt.report()

  • 또는 결과 데이터를 직접 처리하여 직접 분석하실 수 있습니다. py print(bt.log, bt.stats, bt.returns, bt.weights, bt.trades)

GitHub Events

Total
  • Watch event: 1
  • Push event: 4
  • Create event: 2
Last Year
  • Watch event: 1
  • Push event: 4
  • Create event: 2

Committers

Last synced: over 3 years ago

All Time
  • Total Commits: 14
  • Total Committers: 1
  • Avg Commits per committer: 14.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Hong Junhyoung b****7@g****m 14

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: 20 days
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • j2doll (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 203 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
pypi.org: snowball

Investment strategy backtesting tool

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 203 Last month
Rankings
Dependent packages count: 10.0%
Forks count: 15.3%
Downloads: 17.5%
Average: 28.5%
Stargazers count: 31.9%
Dependent repos count: 67.6%
Maintainers (1)
Last synced: 11 months ago

Dependencies

setup.py pypi
  • Ipython *
  • PyPortfolioOpt *
  • kaleido >=0.2.1
  • numpy >=1.18.4
  • pandas >=1.0.3
  • plotly >=5.1.0
  • scipy >=1.4.1
  • sklearn *
  • tqdm >=4.45.0