diff --git a/quantstats_lumi/.DS_Store b/quantstats_lumi/.DS_Store new file mode 100644 index 0000000..e83d81a Binary files /dev/null and b/quantstats_lumi/.DS_Store differ diff --git a/quantstats_lumi/_plotting/wrappers.py b/quantstats_lumi/_plotting/wrappers.py index 1866ed6..dd1e28c 100644 --- a/quantstats_lumi/_plotting/wrappers.py +++ b/quantstats_lumi/_plotting/wrappers.py @@ -82,7 +82,11 @@ def snapshot( returns.columns = strategy_colname colors = _GRAYSCALE_COLORS if grayscale else _FLATUI_COLORS - returns = _utils.make_portfolio(returns.dropna(), 1, mode).pct_change().fillna(0) + returns = ( + _utils.make_portfolio(returns.dropna(), 1, mode) + .pct_change(fill_method=None) + .fillna(0) + ) if figsize is None: size = list(_plt.gcf().get_size_inches()) diff --git a/quantstats_lumi/utils.py b/quantstats_lumi/utils.py index d2d4c9d..22fd986 100644 --- a/quantstats_lumi/utils.py +++ b/quantstats_lumi/utils.py @@ -17,13 +17,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io as _io import datetime as _dt -import pandas as _pd +import inspect +import io as _io + import numpy as _np +import pandas as _pd import yfinance as _yf + from . import stats as _stats -import inspect def _mtd(df): @@ -208,9 +210,9 @@ def _prepare_returns(data, rf=0.0, nperiods=None): if isinstance(data, _pd.DataFrame): for col in data.columns: if data[col].dropna().min() >= 0 and data[col].dropna().max() > 1: - data[col] = data[col].pct_change() + data[col] = data[col].pct_change(fill_method=None) elif data.min() >= 0 and data.max() > 1: - data = data.pct_change() + data = data.pct_change(fill_method=None) # cleanup data data = data.replace([_np.inf, -_np.inf], float("NaN")) @@ -239,7 +241,7 @@ def download_returns(ticker, period="max", proxy=None): params["start"] = period[0] else: params["period"] = period - return _yf.download(**params)["Close"].pct_change() + return _yf.download(**params)["Close"].pct_change(fill_method=None) def _prepare_benchmark(benchmark=None, period="max", rf=0.0, prepare_returns=True): @@ -259,14 +261,13 @@ def _prepare_benchmark(benchmark=None, period="max", rf=0.0, prepare_returns=Tru benchmark = benchmark[benchmark.columns[0]].copy() if isinstance(period, _pd.DatetimeIndex) and set(period) != set(benchmark.index): - # Adjust Benchmark to Strategy frequency benchmark_prices = to_prices(benchmark, base=1) new_index = _pd.date_range(start=period[0], end=period[-1], freq="D") benchmark = ( benchmark_prices.reindex(new_index, method="bfill") .reindex(period) - .pct_change() + .pct_change(fill_method=None) .fillna(0) ) benchmark = benchmark[benchmark.index.isin(period)]