using System; using System.Globalization; using System.Net.Http; using System.Text.Json; // Print numbers with a dot, whatever the language of the machine CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; // Read both funds' files (one GET each, no key), naming your own project using var http = new HttpClient(); http.DefaultRequestHeaders.UserAgent.ParseAdd( "MyProject/1.0 (+https://example.com)"); const string api = "https://tickerinside.com/api/v1/fund/"; using var vooDoc = JsonDocument.Parse( await http.GetStringAsync(api + "voo.json")); using var qqqDoc = JsonDocument.Parse( await http.GetStringAsync(api + "qqq.json")); var voo = vooDoc.RootElement; var qqq = qqqDoc.RootElement; // Each fund has the date of its own issuer's file Console.WriteLine( $"VOO holdings_as_of {voo.GetProperty("holdings_as_of").GetString()}"); Console.WriteLine( $"QQQ holdings_as_of {qqq.GetProperty("holdings_as_of").GetString()}"); // Overlap by weight, as the site computes it: for every ticker both funds // hold, add the smaller of its two weights var inQqq = qqq.GetProperty("holdings"); double overlap = 0; int shared = 0; foreach (var h in voo.GetProperty("holdings").EnumerateObject()) { if (inQqq.TryGetProperty(h.Name, out var w)) { overlap += Math.Min(h.Value.GetDouble(), w.GetDouble()); shared++; } } Console.WriteLine( $"overlap by weight {overlap:F1}%, {shared} companies in both"); // The lines to print under the figure, one per fund file Console.WriteLine(voo.GetProperty("cite_as").GetString()); Console.WriteLine(qqq.GetProperty("cite_as").GetString());