use adj_close returns under most circumstances
All checks were successful
Generic zig build / build (push) Successful in 1m6s
Generic zig build / deploy (push) Successful in 13s

This commit is contained in:
Emil Lerch 2026-03-24 05:32:59 -07:00
parent be48c4a8e3
commit 6a46606f83
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 13 additions and 12 deletions

View file

@ -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",
},
},
}

View file

@ -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