Ranked order values are created by the execution of system.RankInstruments.  Each time an instrument's ranking values are updated the system.RankInstruments function should be executed so the new order of instruments will be ranked using the updated ranking values.

 

Instrument Properties:

instrument.longRank
instrument.shortRank
instrument.longRankingValue
instrument.shortRankingValue

instrument.customSortValue

 

Instrument Functions:

instrument.SetLongRankingValue( )
instrument.SetShortRankingValue( )
instrument.SetCustomSortValue( )

 

Sorts the physical instrument list that is used for the simulation loop using the method indicated:

Method Value:

Sorting Method Description:

1

Long Ranked value sorts the instrument list by the current Long Rank number order.

2

Long Ranking script assigned value will be sorted in ascending order.

3

Dictionary assigned Original Order Sort value.

4

Custom Sort Value order.

5

Alphabetical by Symbol

6

Alphabetical by Group.

 

Note:

All markets are sorted regardless of whether they are primed.

 

The ranking process that creates the Long Rank from the Long Ranking Value is the system.RankInstruments function and/or the Portfolio Manager internal process.

 

The Ranking process only ranks trading instruments (those that are primed and ready to be used in scripting). So as you said, you need to be aware of this if you set the Long Ranking Value, and then Rank the list, and then Sort the list by the Long Rank.

 

A more direct approach if you need the instrument list sorted, is to set the Long Ranking Value and then sort by the Long Ranking Value directly using the system.SortInstrumentList(2). Note that the Long Rank by definition is created by ranking the Long Ranking Value from highest to lowest, so the Long Rank is sorted "opposite" of Long Ranking Value.

 

As for markets that are not primed, you can check this when you use the Rank or Ranking Value, by checking the instrument.isPrimed property or the instrument.tradesOnTradeBar property if necessary. Note that the Entry and Exit scripts do not run if the instrument is not primed or does not trade on the trade date. So you only need these properties if looping over the instrument list manually. Likewise if you loop over the instruments manually to set the Long Ranking Value, you can set this to some out of bounds value as necessary to move to the back of the list. The only time you can't set the value is in the Portfolio Manager where the non primed instruments are not looped over.

 

In addition, the custom sort value is available for use by the system.SortInstrumentList( method# ) function.

Property: instrument.customSortValue

Function: instrument.SetCustomSortValue( value )

 

The Custom Sort Value can also be set in other scripts, just like the ranking Values.

-- Loop over each instrument setting the custom sort value

-- call system.sortInstrumentList(4)

-- Loop over each instrument and note how the instrument list has been sorted

 

Once the instrument list is sorted using the SortInstrumentList function, the Entry Orders script and other instrument scripts will execute in a new order.

 

Example:

'  Create a BPV Instrument Variable Name

Click to Enlarge, Click to Reduce

BPV Instrument Variable Type Example

'  Get Total Number of Instruments in Portfolio
iTotalSymbols = system.totalInstruments
'  Sort Portfolio in Alphabetical Order
system.SortInstrumentList ( 5 )
'  Create Column Header Titles
PRINT "Mkt#", "Mkt-Symbol"
'  Generate a List of Portfolio Symbols
For x = 1 TO iTotalSymbols STEP 1
  '  Bring each instrument into Script Context
  iLoadOK = Mkt.LoadSymbol( x )
  '  When Instrument Loads OK,...
  If iLoadOK THEN
    '  Increment Loaded Instrument Counter
     iCount = iCount + 1
    '  Send Mkt Record to 'PRINT OUTPUT.csv' file
    PRINT iCount, Mkt.symbol
  ENDIF
Next '  x

 

Returns:

Mkt#        Mkt-Symbol

1                EFA

2                GLD

3                IWM

4                LQD

5                MDY

 

Links:

system.RankInstruments, instrument.tradesOnTradeBar

See Also:

 

 


Edit Time: 9/25/2017 09:09:58 AM


Topic ID#: 570

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software