Normalize the index component weights

This commit is contained in:
moshferatu 2024-03-13 14:21:40 -07:00
parent 2c2e4d8358
commit 65c9072155

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Windows.Media;
@ -125,6 +126,13 @@ namespace NinjaTrader.NinjaScript.Indicators
Components.Add(symbol);
ComponentWeightings.Add(symbol, double.Parse(percentage));
}
// Normalize the component weightings to add up to 1.
double totalWeighting = ComponentWeightings.Values.Sum();
foreach (var component in Components)
{
ComponentWeightings[component] /= totalWeighting;
}
}
public override string DisplayName