Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from ranaroussi/fix/events-merge
Fix merging of dividends/splits with prices
- Loading branch information
Showing
5 changed files
with
203 additions
and
11 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 @@ | ||
#!/usr/bin/env python |
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,9 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import os | ||
_parent_dp = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
_src_dp = _parent_dp | ||
sys.path.insert(0, _src_dp) | ||
|
||
import yfinance |
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,44 @@ | ||
from .context import yfinance as yf | ||
|
||
import unittest | ||
|
||
class TestPriceHistory(unittest.TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_weeklyWithEvents(self): | ||
# Reproduce issue #521 | ||
tkr1 = "QQQ" | ||
tkr2 = "GDX" | ||
start_d = "2014-12-29" | ||
end_d = "2020-11-29" | ||
df1 = yf.Ticker(tkr1).history(start=start_d, end=end_d, interval="1wk", actions=True) | ||
df2 = yf.Ticker(tkr2).history(start=start_d, end=end_d, interval="1wk", actions=True) | ||
try: | ||
self.assertTrue(df1.index.equals(df2.index)) | ||
except: | ||
missing_from_df1 = df2.index.difference(df1.index) | ||
missing_from_df2 = df1.index.difference(df2.index) | ||
print("{} missing these dates: {}".format(tkr1, missing_from_df1)) | ||
print("{} missing these dates: {}".format(tkr2, missing_from_df2)) | ||
raise | ||
|
||
# Test that index same with and without events: | ||
tkrs = [tkr1, tkr2] | ||
for tkr in tkrs: | ||
df1 = yf.Ticker(tkr).history(start=start_d, end=end_d, interval="1wk", actions=True) | ||
df2 = yf.Ticker(tkr).history(start=start_d, end=end_d, interval="1wk", actions=False) | ||
try: | ||
self.assertTrue(df1.index.equals(df2.index)) | ||
except: | ||
missing_from_df1 = df2.index.difference(df1.index) | ||
missing_from_df2 = df1.index.difference(df2.index) | ||
print("{}-with-events missing these dates: {}".format(tkr, missing_from_df1)) | ||
print("{}-without-events missing these dates: {}".format(tkr, missing_from_df2)) | ||
raise | ||
|
||
if __name__ == '__main__': | ||
unittest.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
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