From 29d028fee2d109cef3ee43b5bbbb450cc9e30ec0 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 18 Feb 2026 02:39:26 -0500 Subject: [PATCH] refactor: Replace find_first_index with FindIndex --- src/client/spark/Risk/VolSurfaceSlideCalculator.cs | 8 ++++---- src/cs/Bts.Collections/CollectionHelper.cs | 11 ----------- src/cs/Bts.Collections/EnumerableExtensions.cs | 5 +++++ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/client/spark/Risk/VolSurfaceSlideCalculator.cs b/src/client/spark/Risk/VolSurfaceSlideCalculator.cs index d6e55f60d..06b92f42c 100644 --- a/src/client/spark/Risk/VolSurfaceSlideCalculator.cs +++ b/src/client/spark/Risk/VolSurfaceSlideCalculator.cs @@ -414,8 +414,8 @@ namespace mbts.analytics { out IDictionary slide_expiration_map) { slide_expiration_map = new Dictionary(); int n_greeks = ordered_greeks.Count(), - zero_handle_index = perc_handles.find_first_index(0.0), - pnl_index = ordered_greeks.find_first_index(VolSurfaceGreeks.Pnl); + zero_handle_index = perc_handles.FindIndex(0.0), + pnl_index = ordered_greeks.FindIndex(VolSurfaceGreeks.Pnl); double delta_terms_cpp = cpp_map.TryGetValue(delta_terms_symbol, out delta_terms_cpp) ? delta_terms_cpp : Double.NaN; foreach (var kv_exp in pos_map) { VolSurfaceExpiration exp = kv_exp.Key; @@ -457,8 +457,8 @@ namespace mbts.analytics { double delta_terms_cpp = cpp_map.TryGetValue(delta_terms_symbol, out delta_terms_cpp) ? delta_terms_cpp : Double.NaN, oev_terms_cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, oev_terms_option_symbol, Venue.Unset), out oev_terms_cpp) ? oev_terms_cpp : Double.NaN; int n_greeks = ordered_greeks.Count(), - zero_handle_index = perc_handles.find_first_index(0.0), - pnl_index = ordered_greeks.find_first_index(VolSurfaceGreeks.Pnl); + zero_handle_index = perc_handles.FindIndex(0.0), + pnl_index = ordered_greeks.FindIndex(VolSurfaceGreeks.Pnl); IDictionary> exp_k_theo_map = VolSurfaceSlideCalculator._convert_exp_theos_to_strike_theos(theo_map); /* expiration */ foreach (var kv_exp in pos_map) { diff --git a/src/cs/Bts.Collections/CollectionHelper.cs b/src/cs/Bts.Collections/CollectionHelper.cs index b367cf379..e5c67e8d1 100644 --- a/src/cs/Bts.Collections/CollectionHelper.cs +++ b/src/cs/Bts.Collections/CollectionHelper.cs @@ -464,17 +464,6 @@ namespace bts.utils { return rv; } - public static int find_first_index(this IEnumerable list, T elem_to_find, Func equals = null) { - if (equals == null) equals = (t1, t2) => t1.Equals(t2); - int rv = 0; - foreach (T t in list) { - if (elem_to_find.Equals(t)) - return rv; - rv++; - } - return -1; - } - /// /// Gets coordinates for an index in the imaginary sorted list that results from merging /// and . The "X" coordinate is either 0 diff --git a/src/cs/Bts.Collections/EnumerableExtensions.cs b/src/cs/Bts.Collections/EnumerableExtensions.cs index 72cb95d23..e27e09fd0 100644 --- a/src/cs/Bts.Collections/EnumerableExtensions.cs +++ b/src/cs/Bts.Collections/EnumerableExtensions.cs @@ -488,6 +488,11 @@ namespace System.Collections.Generic { return false; } + public static int FindIndex(this IEnumerable source, T value) { + TryFindIndex(source, value, EqualityComparer.Default, out int index); + return index; + } + public static bool TryFindIndex(this IEnumerable source, T value, out int index) => TryFindIndex(source, value, EqualityComparer.Default, out index);