diff --git a/build.zig.zon b/build.zig.zon index 3c55c81..52d9932 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -14,8 +14,8 @@ .hash = "httpz-0.0.0-PNVzrBtMBwAPcQx3mNEgat3Xbsynw-eIC9SmOX5M9XtP", }, .zfin = .{ - .url = "git+https://git.lerch.org/lobo/zfin#913996072ee06c81121f50657e325ce8a56856e6", - .hash = "zfin-0.0.0-J-B21paODADTI5LGofs453BW06vDDK9UZl1LapWa-8eb", + .url = "git+https://git.lerch.org/lobo/zfin#5052492ffd49ebdc11b209da1b86bbaf7d365e5e", + .hash = "zfin-0.0.0-J-B21ryaDACsjkyET8s_NhF0W745-Qoc_fj9VM8Z-Ngx", }, }, } diff --git a/src/main.zig b/src/main.zig index 857ba4d..4a0eeb9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -174,8 +174,9 @@ fn handleReturns(app: *App, req: *httpz.Request, res: *httpz.Response) !void { const vol_best = v10y orelse v5y orelse v3y orelse v1y; const vol_term: ?u8 = if (v10y != null) 10 else if (v5y != null) 5 else if (v3y != null) 3 else if (v1y != null) 1 else null; - // Total returns with dividend reinvestment (non-fatal if dividends unavailable). - // trailing* fields use total return when available, falling back to price-only. + // Total returns: adj_close is the primary source (accounts for splits + dividends). + // Dividend-reinvestment is only used as fallback when adj_close returns null + // (e.g. candle history too short for stable-NAV funds like money markets). var t1y: ?f64 = p1y; var t3y: ?f64 = p3y; var t5y: ?f64 = p5y; @@ -184,18 +185,18 @@ fn handleReturns(app: *App, req: *httpz.Request, res: *httpz.Response) !void { if (app.svc.getDividends(symbol)) |div_result| { defer zfin.Dividend.freeSlice(app.allocator, div_result.data); const total = zfin.performance.trailingReturnsWithDividends(candles, div_result.data); - if (total.one_year) |r| { + if (t1y == null) if (total.one_year) |r| { t1y = r.annualized_return; - } - if (total.three_year) |r| { + }; + if (t3y == null) if (total.three_year) |r| { t3y = r.annualized_return; - } - if (total.five_year) |r| { + }; + if (t5y == null) if (total.five_year) |r| { t5y = r.annualized_return; - } - if (total.ten_year) |r| { + }; + if (t10y == null) if (total.ten_year) |r| { t10y = r.annualized_return; - } + }; } else |_| {} // Check if XML requested