From 66eafa045157fa3cc499bdc09268acf59331ce8a Mon Sep 17 00:00:00 2001 From: Red S Date: Mon, 25 Nov 2024 20:20:38 -0800 Subject: [PATCH] fix: scaled_navs now only considers last 10 most recent ratios VINIX vs VOO is an example of how related MF/ETFs diverge in NAV across time, because of the difference in how each pays out dividends and capital gains. Thus, recent prices are the most relevant ones --- fava_investor/util/experimental/scaled_navs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fava_investor/util/experimental/scaled_navs.py b/fava_investor/util/experimental/scaled_navs.py index 83073c9..69a805e 100755 --- a/fava_investor/util/experimental/scaled_navs.py +++ b/fava_investor/util/experimental/scaled_navs.py @@ -114,9 +114,15 @@ def estimate_mf_navs(self): etf_price = etf_prices[0].amount.number ratio = mf_price / etf_price # print(" ", p.date, mf_price, etf_price, ratio) - ratios.append(ratio) + ratios.append((p.date, ratio)) if ratios: if etf in self.latest_prices: + # consider only the most recent 10 values, because some ETFs and MFs that are + # not share classes of each other can diverge due to how they pay dividends and + # capgain distributions (eg: VINIX vs VOO) + ratios.sort(key=lambda x: x[0]) + ratios = ratios[-10:] + ratios = [i[1] for i in ratios] median_ratio = statistics.median(ratios) scaled_number = round(self.latest_prices[etf].number * median_ratio, 2) scaled_mf[mf] = (etf, median_ratio, Amount(scaled_number, self.latest_prices[etf].currency))