Documentation>Application Documentation>XMIM Documentation>XMIM Examples>TOP/BOTTOM Example

TOP/BOTTOM Example
 

TOP

The TOP statement allows you to have XMIM report the top 1, 2, 10, 100, or whatever number of answers that meet your criteria. Typically the Attribute criteria used is selected from the Profit-Loss Statistics button from the Attribute Window.

Example 1:

LET

ATTR MovgAvg = 5 TO 100 BY 5

TOP 5 equity

 

When used with an ORDER query (Profit and Loss function) the above LET expression will only return the top 5 results that return the top 5 final equity figures.

The “TOP n” constraint may be used by selecting the Options button within a LET window. After you have defined your Variable within a LET Statement select the Options button before exiting the LET window. “TOP n” requires input of a value into the text field and selection of an Attribute. For the example above we chose Profit-Loss Statistics, Final Statistics and Equity for the Attribute menu selection.

Example 2:

Here is a way to demonstrate TOP functionality in XMIM. This query will return the top 50 results based on the calculation you give it. Note: the query finds what individual stocks in the S&P 500 moved the most compared to the S&P 500 index. It finds the TOP 50 percent movers.

LET

theSym=FILE "/home/lim/dates/user/COMPONENTS/GII.SPX"
TOP 50 percent_move from 1 year ago to today of theSym - percent_move from 1 year ago to today of SPX

LET
ATTR stockVsMarket=percent_move from 1 year ago to today of theSym - percent_move from 1 year ago to today of SPX

SHOW

1: percent_move from 1 year ago to today of theSym
2: percent_move from 1 year ago to today of SPX
stockVsMarket: stockVsMarket

WHEN

Date is 2/13/2004

 


B
OTTOM

Like the TOP statement, BOTTOM allows you to filter the results so that the system only reports answers for the parameter sets that don't exceed some maximum utility.

Example:

LET
     ATTR num00 = 10 TO 20 BY 1
     BOTTOM 2 Biggest_Loss

LET
  theSec = CSCO

   1: ORDER
     1.1: Buy 1 contract of theSec

   WHEN
       Date is after 1998

     AND
       num00 day % move of theSec  crosses above 5

EXIT
       num00 day % move of theSec crosses below  1

 

Example using TOP and BOTTOM:  You want to see which S&P 500 groups are the biggest movers from Thanksgiving to Christmas. You write a query that ranks the top 5 and bottom 5 S&P 500 groups based on an average of their percentage moves.

TOP 5 total / counter
BOTTOM 5 total / counter

LET
ATTR PercMV = percent_move from Thanksgiving to Christmas of Group

SHOW
PercMV: PercMV
WHEN
Date is Thanksgiving
AND
total = toal + PercMV
AND
counter = counter + 1