-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update __init__.py * Update pandas-datareader requirement from ^0.9.0 to ^0.10.0 (#31) Updates the requirements on [pandas-datareader](https://github.com/pydata/pandas-datareader) to permit the latest version. - [Release notes](https://github.com/pydata/pandas-datareader/releases) - [Changelog](https://github.com/pydata/pandas-datareader/blob/main/release-procedure.md) - [Commits](pydata/pandas-datareader@v0.9.0...v0.10.0) --- updated-dependencies: - dependency-name: pandas-datareader dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update publish.yml (#32) * Create bump.yml (#33) * Update ci.yml (#34) * bump version (#37) Co-authored-by: GitHub Actions <action@github.com> * fix ci.yml * Update ci.yml * format (#38) Co-authored-by: GitHub Actions <action@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions <action@github.com>
- Loading branch information
1 parent
0132482
commit ae21c52
Showing
10 changed files
with
176 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Bump | ||
|
||
on: | ||
create: | ||
branches: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
bump: | ||
|
||
name: Bump | ||
|
||
runs-on: ubuntu-latest | ||
|
||
if: ${{ contains(github.ref, 'release/') }} | ||
|
||
steps: | ||
|
||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-python@v2 | ||
|
||
- run: pip install poetry | ||
|
||
- name: Bump version | ||
run: git branch --show-current | sed 's|release/||' | xargs poetry version | { printf '::set-output name=PR_TITLE::'; cat; } | ||
id: bump | ||
|
||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
author: GitHub Actions <action@github.com> | ||
commit-message: bump version | ||
delete-branch: true | ||
branch-suffix: short-commit-hash | ||
title: ${{ steps.bump.outputs.PR_TITLE }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
# flake8: noqa | ||
|
||
from .coint import CointAnalysis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pandas as pd | ||
import pandas_datareader | ||
import matplotlib.pyplot as plt | ||
from pandas.plotting import register_matplotlib_converters | ||
|
||
from cointanalysis import CointAnalysis | ||
|
||
from pandas.plotting import register_matplotlib_converters | ||
register_matplotlib_converters() | ||
|
||
|
||
def fetch_etf(ticker): | ||
return pandas_datareader.data.DataReader( | ||
ticker, 'yahoo', '2012-01-01', '2018-12-31' | ||
)['Adj Close'] | ||
ticker, "yahoo", "2012-01-01", "2018-12-31" | ||
)["Adj Close"] | ||
|
||
|
||
def plot_prices(hyg, bkln): | ||
plt.figure(figsize=(16, 4)) | ||
|
||
plt.title('HYG and BKLN') | ||
plt.title("HYG and BKLN") | ||
hyg_norm = 100 * hyg / hyg[0] | ||
bkln_norm = 100 * bkln / bkln[0] | ||
plt.plot(hyg_norm, label='HYG (2012-01-01 = 100)', linewidth=1) | ||
plt.plot(bkln_norm, label='BKLN (2012-01-01 = 100)', linewidth=1) | ||
plt.plot(hyg_norm, label="HYG (2012-01-01 = 100)", linewidth=1) | ||
plt.plot(bkln_norm, label="BKLN (2012-01-01 = 100)", linewidth=1) | ||
|
||
plt.legend() | ||
plt.savefig('hyg-bkln.png', bbox_inches="tight", pad_inches=0.1) | ||
plt.savefig("hyg-bkln.png", bbox_inches="tight", pad_inches=0.1) | ||
|
||
|
||
def plot_adjust(hyg, bkln, coint): | ||
plt.figure(figsize=(16, 4)) | ||
|
||
hyg_ = (-coint.coef_[0]) * hyg + coint.mean_ | ||
|
||
plt.title('HYG and BKLN') | ||
plt.plot(hyg_, | ||
label=f'{-coint.coef_[0]:.2f} * HYG + {coint.mean_:.2f}', | ||
linewidth=1) | ||
plt.plot(bkln, label='BKLN', linewidth=1) | ||
plt.title("HYG and BKLN") | ||
plt.plot( | ||
hyg_, label=f"{-coint.coef_[0]:.2f} * HYG + {coint.mean_:.2f}", linewidth=1 | ||
) | ||
plt.plot(bkln, label="BKLN", linewidth=1) | ||
|
||
plt.legend() | ||
plt.savefig('hyg-bkln-adjust.png', bbox_inches="tight", pad_inches=0.1) | ||
plt.savefig("hyg-bkln-adjust.png", bbox_inches="tight", pad_inches=0.1) | ||
|
||
|
||
def plot_spread(spread): | ||
plt.figure(figsize=(16, 4)) | ||
|
||
plt.title('Spread between HYG and BKLN') | ||
plt.title("Spread between HYG and BKLN") | ||
plt.plot(spread, linewidth=1) | ||
|
||
plt.savefig('hyg-bkln-spread.png', bbox_inches="tight", pad_inches=0.1) | ||
plt.savefig("hyg-bkln-spread.png", bbox_inches="tight", pad_inches=0.1) | ||
|
||
|
||
def main(): | ||
hyg = fetch_etf('HYG') | ||
bkln = fetch_etf('BKLN') | ||
hyg = fetch_etf("HYG") | ||
bkln = fetch_etf("BKLN") | ||
|
||
X = np.array([hyg, bkln]).T | ||
coint = CointAnalysis() | ||
|
||
# pvalue | ||
pvalue = coint.test(X).pvalue_ | ||
print(f'pvalue: {pvalue}') | ||
print(f"pvalue: {pvalue}") | ||
|
||
# fit, transform | ||
spread = pd.Series(coint.fit_transform(X), index=hyg.index) | ||
print(f'coef: {coint.coef_}') | ||
print(f'mean: {coint.mean_}') | ||
print(f'std: {coint.std_}') | ||
print(f"coef: {coint.coef_}") | ||
print(f"mean: {coint.mean_}") | ||
print(f"std: {coint.std_}") | ||
|
||
# plot | ||
plot_prices(hyg, bkln) | ||
plot_adjust(hyg, bkln, coint) | ||
plot_spread(spread) | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.