|
SystemTrade
2012-03-09 02:46:59
|
|
Whenever the list of index constituents of a specific index changes, you can easily get the new index members by one of the downloaders provided.
But you would need to delete the index membership of the symbols that were removed from the index manually e.g. by using the bulk updater.
This might not be easy if a symbol is assigned to several indizes, for instance to the DJIA, S&P 100, S&P 500 and is only removed from the DJIA.
The little script below lets you delete the membership of all symbols to a specific index and when you download the new constituents after that deletion, you will have proper index data.
You should put the script in the script editor and add it to the bookmark panel.
Just open the output window, start the script and after the beep enter the name of the index in the output window - don't enter return after the name.
//---------- C# - remove Symbols from Index ----------
App.Main.SetOutput("");
System.Console.Beep();
App.Main.AddToOutput("Please enter Index from which symbols will be removed in Output window within 10 seconds after the next beep.");
App.Main.Sleep(10000);
App.Main.SetOutput("");
System.Console.Beep();
App.Main.Sleep(10000);
string delIndexRef = App.Main.GetOutput();
if (delIndexRef == "") App.Main.AddToOutput("\r\n" + "Please run again and enter index.\r\n");
else
{
App.Main.AddToOutput("\r\n[" + delIndexRef + "] chosen.\r\n");
Symbol[] allSymbols = Symbols.GetSymbols();
int symbols = 0;
int duplicates = 0;
int previous = -1;
for(int i = 0; i < allSymbols.Length; i++)
{
while(Array.IndexOf(allSymbols[i].GetIndexesFromList(), delIndexRef) >= 0)
{
allSymbols[i].RemoveIndex(delIndexRef);
App.Main.AddToOutput(allSymbols[i].Name + " removed.\r\n");
if (previous != i)
{
symbols = symbols + 1;
previous = i;
}
else
duplicates = duplicates + 1;
}
}
App.Main.AddToOutput(symbols + " symbols and " + duplicates + " duplicates removed from index " + delIndexRef + ".");
}
System.Console.Beep();
|
|