Clarify history() period default
This commit is contained in:
@@ -4,6 +4,8 @@ _ROOT_URL_ = 'https://finance.yahoo.com'
|
||||
|
||||
_SENTINEL_ = object()
|
||||
|
||||
period_default = '1mo if start & end None'
|
||||
|
||||
fundamentals_keys = {
|
||||
'financials': ["TaxEffectOfUnusualItems", "TaxRateForCalcs", "NormalizedEBITDA", "NormalizedDilutedEPS",
|
||||
"NormalizedBasicEPS", "TotalUnusualItems", "TotalUnusualItemsExcludingGoodwill",
|
||||
|
||||
+3
-2
@@ -34,11 +34,12 @@ from . import Ticker, utils
|
||||
from .data import YfData
|
||||
from . import shared
|
||||
from .config import YfConfig
|
||||
from .const import period_default
|
||||
|
||||
@utils.log_indent_decorator
|
||||
def download(tickers, start=None, end=None, actions=False, threads=True,
|
||||
ignore_tz=None, group_by='column', auto_adjust=True, back_adjust=False,
|
||||
repair=False, keepna=False, progress=True, period=None, interval="1d",
|
||||
repair=False, keepna=False, progress=True, period=period_default, interval="1d",
|
||||
prepost=False, rounding=False, timeout=10, session=None,
|
||||
multi_level_index=True) -> Union[_pd.DataFrame, None]:
|
||||
"""
|
||||
@@ -48,7 +49,7 @@ def download(tickers, start=None, end=None, actions=False, threads=True,
|
||||
List of tickers to download
|
||||
period : str
|
||||
Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max
|
||||
Default: 1mo
|
||||
Default: '1mo' if start & end None
|
||||
Either Use period parameter or use start and end
|
||||
interval : str
|
||||
Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo
|
||||
|
||||
@@ -11,7 +11,7 @@ import warnings
|
||||
|
||||
from yfinance import shared, utils
|
||||
from yfinance.config import YfConfig
|
||||
from yfinance.const import _BASE_URL_, _PRICE_COLNAMES_
|
||||
from yfinance.const import _BASE_URL_, _PRICE_COLNAMES_, period_default
|
||||
from yfinance.exceptions import YFDataException, YFInvalidPeriodError, YFPricesMissingError, YFRateLimitError, YFTzMissingError
|
||||
|
||||
class PriceHistory:
|
||||
@@ -29,7 +29,7 @@ class PriceHistory:
|
||||
self._reconstruct_start_interval = None
|
||||
|
||||
@utils.log_indent_decorator
|
||||
def history(self, period=None, interval="1d",
|
||||
def history(self, period=period_default, interval="1d",
|
||||
start=None, end=None, prepost=False, actions=True,
|
||||
auto_adjust=True, back_adjust=False, repair=False, keepna=False,
|
||||
rounding=False, timeout=10,
|
||||
@@ -38,7 +38,7 @@ class PriceHistory:
|
||||
:Parameters:
|
||||
period : str
|
||||
| Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max
|
||||
| Default: 1mo
|
||||
| Default: '1mo' if start & end None
|
||||
| Can combine with start/end e.g. end = start + period
|
||||
interval : str
|
||||
| Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo
|
||||
@@ -81,13 +81,21 @@ class PriceHistory:
|
||||
warnings.warn("'raise_errors' deprecated, do: yf.config.debug.hide_exceptions = False", DeprecationWarning, stacklevel=5)
|
||||
|
||||
interval_user = interval
|
||||
period_user = period
|
||||
if period == period_default:
|
||||
period_user = None
|
||||
if start or end:
|
||||
period = None
|
||||
else:
|
||||
period = '1mo'
|
||||
else:
|
||||
period_user = period
|
||||
if repair and interval in ["5d", "1wk", "1mo", "3mo"]:
|
||||
# Yahoo's way of adjusting mutiday intervals is fundamentally broken.
|
||||
# Have to fetch 1d, adjust, then resample.
|
||||
if interval == '5d':
|
||||
raise ValueError("Yahoo's interval '5d' is nonsense, not supported with repair")
|
||||
if start is None and end is None and period is not None:
|
||||
# Convert period to start -> end
|
||||
tz = self.tz
|
||||
if tz is None:
|
||||
# Every valid ticker has a timezone. A missing timezone is a problem.
|
||||
|
||||
+3
-2
@@ -24,6 +24,7 @@ from __future__ import print_function
|
||||
from . import Ticker, multi
|
||||
from .live import WebSocket
|
||||
from .data import YfData
|
||||
from .const import period_default
|
||||
|
||||
|
||||
class Tickers:
|
||||
@@ -46,7 +47,7 @@ class Tickers:
|
||||
# "Tickers", ticker_objects.keys(), rename=True
|
||||
# )(*ticker_objects.values())
|
||||
|
||||
def history(self, period=None, interval="1d",
|
||||
def history(self, period=period_default, interval="1d",
|
||||
start=None, end=None, prepost=False,
|
||||
actions=True, auto_adjust=True, repair=False,
|
||||
threads=True, group_by='column', progress=True,
|
||||
@@ -59,7 +60,7 @@ class Tickers:
|
||||
threads, group_by, progress,
|
||||
timeout, **kwargs)
|
||||
|
||||
def download(self, period=None, interval="1d",
|
||||
def download(self, period='1mo if start & end None', interval="1d",
|
||||
start=None, end=None, prepost=False,
|
||||
actions=True, auto_adjust=True, repair=False,
|
||||
threads=True, group_by='column', progress=True,
|
||||
|
||||
Reference in New Issue
Block a user