#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

## Combination Element from Lexicographical Index

by QuantShare, 3708 days ago

The current algorithm calculates the mathematical combination element given the lexicographical index. The function gets several string values separated by a semi-colon, a value to test, the number of values per combination and the combination index (or what is called lexicographical index).

To understand the usefulness of this function, here is an example that lets you test several stock combinations. The function returns 1 or TRUE if a specific stock or ETF symbol is found in a combination element, otherwise it returns 0 or FALSE.
- The values to be passed to the function are A;AA;B;C;GOOG;MSFT;AAPL (Stock symbols separated by a comma)
- The value to be test is the current stock symbol (The stock that is currently tested in the analyzer, simulator or screener). To get the current stock symbol, we use the function: Name()
- The number of values per combinations (K) is set to 3

Given a K value of 3 and an N value of 7 (7 stock symbols passed in the first argument of our function), the total number of combinations is: 35

Combination 0: A;AA;B
Combination 1: A;AA;C
Combination 2: A;AA;GOOG
....
Combination 34: GOOG;MSFT;AAPL

By passing a lexicographical index of 34, the function calculates the combination string (GOOG;MSFT;AAPL) and tests whether the stock symbol provided in the second argument of our function is included in this string. In case we are analyzing Citigroup Inc. (C), the response is no and the trading function returns 0.

If we vary the lexicographical index from 0 to 34, we can test all stock names combinations. In a trading system, the formula may look like this:

Optimize("lexindex", 0, 34, 1);
buy = CombinationIndex("A;AA;B;C;GOOG;MSFT;AAPL", Name(), 3, lexindex) == 1;

An example of using this function is to test a strategy that combines different ETF or Stock symbols to check which combination of assets perform best.

Note: You can get the total number of combinations by setting the lexicographical index to -1.

nb1 = CombinationIndex("A;AA;B;C;GOOG;MSFT;AAPL", Name(), 3, -1);
Optimize("lexindex", 0, nb1, 1);

What is this?

 Type: Trading Indicator Object ID: 977 Country: All Market: All Style: Technical Analysis

Related objects
Show All
Set Global Variable (by QuantShare, uploaded several months ago)
No notes
 24
Time-series location relative to its high and low (by The trader, uploaded several months ago)
No notes
 40
Transform any order into a limit order selectively based on a trading rule (by Tom Huggens, uploaded several months ago)
No notes
 33
Historical Intraday Data for U.S. Stocks (by QuantShare, uploaded several months ago)
No notes
 131
Market Yield on U.S. Treasury Securities (by QuantShare, uploaded several months ago)
No notes
 31
No notes
 42
Exit Position based on Profitability (by QuantShare, uploaded several months ago)
No notes
 60
Number of reviews
Average rate
Click to rate this item
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object

Number of reviews
Average rate
Click to rate this item
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object