refactor: Replace find_first_index with FindIndex
This commit is contained in:
1 parent
dc5da87a65
commit
29d028fee2
3 files changed
+9
-15
No files matched your search
@@ -414,8 +414,8 @@ namespace mbts.analytics {
|
||||
out IDictionary<SecurityExpiration, SlideContractUnit> slide_expiration_map) {
|
||||
slide_expiration_map = new Dictionary<SecurityExpiration, SlideContractUnit>();
|
||||
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<mbts.SecurityStrike, List<Theos>> exp_k_theo_map = VolSurfaceSlideCalculator._convert_exp_theos_to_strike_theos(theo_map);
|
||||
/* expiration */
|
||||
foreach (var kv_exp in pos_map) {
|
||||
|
||||
@@ -464,17 +464,6 @@ namespace bts.utils {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static int find_first_index<T>(this IEnumerable<T> list, T elem_to_find, Func<T, T, bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets coordinates for an index in the imaginary sorted list that results from merging
|
||||
/// <paramref name="list1"/> and <paramref name="list2"/>. The "X" coordinate is either 0
|
||||
|
||||
@@ -488,6 +488,11 @@ namespace System.Collections.Generic {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int FindIndex<T>(this IEnumerable<T> source, T value) {
|
||||
TryFindIndex(source, value, EqualityComparer<T>.Default, out int index);
|
||||
return index;
|
||||
}
|
||||
|
||||
public static bool TryFindIndex<T>(this IEnumerable<T> source, T value, out int index) =>
|
||||
TryFindIndex(source, value, EqualityComparer<T>.Default, out index);
|
||||
|
||||
|
||||
Reference in new issue
Block a user