Click here to Login





                                                   Script to remove Symbols from an Index

  1

0
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();



QuantShare
2012-03-09 04:04:12

  1

Nice. Thank you for sharing this.

We may add the ability to upload scripts to the sharing server. What do you think?



SystemTrade
2012-03-12 04:14:48

  0

I think that would be a good idea. Please let me know when this will be implemented and I will upload the script again.


No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Combination Element from Lexicographical Index
Yale - Valuation Confidence Index
Identify Spilts Screener Script
Ticker Symbol Index
RTS Index

How-to Lessons
How to run a screen or a watchlist from a script
How to get stocks for a particular index using the global script
How to remove non-active securities
How to get trading orders from a portfolio programmatically
How to import trading data from CSV files

Related Forum Threads
Adding symbols and changing properties from script
Speed of script execution for symbols with many bars
Creat a Composite Index from few stock symbol
MM script: getting Daily prices of index from Intraday Interval
Remove invalid symbols

Blog Posts
Short Index - Part 1
Short Index - Part 2
QS Trading Software: Global Script
Export Trading Orders from a Portfolio to a File
Create a Pivot Table that displays the Relative Strength Index - ...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.