API functions: Screen

API functions for screening operations

Marco Salerno
Written by Marco SalernoLast update 10 days ago

Screen Functions

screen_run

This operation allows you to run a screen.

screen_backtest

This operation allows you to run a performance backtest of a Screen.

screen_rolling_backtest

This operation allows you to run and collect the output of rolling screens.

screen_run()

Wrapper for POST​ /screen​/run

This operation allows you to run a screen. You can specify the screen settings directly as well as use one of your existing screens.

# Specify the screen settings inline:
p123api.Client().screen_run({
    'screen': {
        'type': 'stock' | 'etf',
        'universe': 'Universe name',
        'maxNumHoldings': 10, # 0 for all
        'method': 'long' | 'short' | 'long/short' | 'hedged',
        'benchmark': 'SPY',
        'currency': 'USD' | 'CAD' | 'CHF' | 'EUR' | 'GBP' | 'NOK' | 'PLN' | 'SEK' | 'TRY',

        #Several options for specifying the ranking. Choose one of these 5:
        'ranking': 'Ranking Name',
        'ranking': id,
        'ranking': {
            'method': 0, # 0-Use Ranking System Default, 2-Percentile NAs Negative, 
                         # 4-Percentile NAs Neutral, 1-Normal Distribution
            'id': id},
        'ranking': {
            'method': 0,
            'name': 'Ranking Name'},
        'ranking': {
            'formula': 'formula1',
            'lowerIsBetter': True | False },

        'rules': [
            {'formula': 'formula1',
                'type': 'common' | 'long' | 'short' | 'hedge'
            },
            {'formula': 'formula2',
                'type': 'common' | 'long' | 'short' | 'hedge'
            }
            ... etc ...]
    #
    # Optional parameters
    'asOfDt': 'yyyy-mm-dd', # Defaults to today's date
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    },True) # True - output to Pandas DataFrame | [False] to JSON.
# Run an existing screen using the integer id of the screen:
p123api.Client().client.screen_run({
    'screen': id,
    #
    # Optional parameters
    'asOfDt': 'yyyy-mm-dd', # Defaults to today's date
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    },True) # True - output to Pandas DataFrame | [False] to JSON.
# Run an existing screen using the integer id of the screen and maxNumHoldings:
p123api.Client().client.screen_run({
    'screen': {
        'id': id,
        'maxNumHoldings': 10  # 0 for all. Optional.
        },
    #
    # Optional parameters
    'asOfDt': 'yyyy-mm-dd', # Defaults to today's date
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4
    },True) # True - output to Pandas DataFrame | [False] to JSON.

screen_backtest()

Wrapper for POST​ /screen​/backtest

This operation allows you to run a performance backtest of a Screen.

# Backtest a screen which is defined inline:
p123api.Client().screen_backtest({
    'screen': {
        'type': 'stock' | 'etf',
        'universe': 'Universe name',
        'maxNumHoldings': 10,  #0 for all
        'method': 'long' | 'short' | 'long/short' | 'hedged',
        'currency': 'USD' | 'CAD' | 'CHF' | 'EUR' | 'GBP' | 'NOK' | 'PLN' | 'SEK' | 'TRY',
        'benchmark': 'SPY',

        #Several options for specifying the ranking. Choose one of these 5:
        'ranking': 'Ranking Name',
        'ranking': id,
        'ranking': {
            'method': 0, # 0-Use Ranking System Default, 2-Percentile NAs Negative, 
                         # 4-Percentile NAs Neutral, 1-Normal Distribution
            'id': id},
        'ranking': {
            'method': 0,
            'name': 'Ranking Name'},
        'ranking': {
            'formula': 'formula1',
            'lowerIsBetter': True | False },

        'rules': [
            {'formula': 'formula1',
                'type': 'common' | 'long' | 'short' | 'hedge'
            },
            {'formula': 'formula2',
                'type': 'common' | 'long' | 'short' | 'hedge'
            }
            ... etc ...]
        },
    'startDt': '2020-01-01',
    #
    # Optional parameters
    'endDt': 'yyyy-mm-yy',
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    'transPrice': 1, # 1 - Open | 3 - Avg of Hi and Low | 4 - Close
    'maxPosPct': 0,
    'slippage': 0.25,
    'longWeight': 100,
    'shortWeight': 100,
    'rankTolerance': 0,
    'carryCost': 0,
    'rebalFreq': 'Every 4 Weeks' | 'Every Week' | 
                 'Every N Weeks' (2,3,4,6,8,13,26,52),
    'riskStatsPeriod': ['Monthly'] | 'Weekly' | 'Daily'
    },True) # True - output to Pandas DataFrame | [False] to JSON.
# Backtest and existing screen using the integer id of the screen:
p123api.Client().screen_backtest({
    'screen': id,
    'startDt': '2020-01-01',
    #
    # Optional parameters
    'endDt': 'yyyy-mm-yy',
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    'transPrice': 1, # 1 - Open | 3 - Avg of Hi and Low | 4 - Close
    'maxPosPct': 0,
    'slippage': 0.25,
    'longWeight': 100,
    'shortWeight': 100,
    'rankTolerance': 0,
    'carryCost': 0,
    'rebalFreq': 'Every 4 Weeks' | 'Every Week' | 
                 'Every N Weeks' (2,3,4,6,8,13,26,52),
    'riskStatsPeriod': 'Monthly' | 'Weekly' | 'Daily'
    },True) # True - output to Pandas DataFrame | [False] to JSON.
# Backtest an existing screen using the integer id of the screen and maxNumHoldings:
p123api.Client().screen_backtest({
    'screen': {
        'id': id,
        'maxNumHoldings': 10  # 0 for all. Optional.
        },
    'startDt': '2020-01-01',
    #
    # Optional parameters
    'endDt': 'yyyy-mm-dd',
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    'transPrice': 1, # 1 - Open | 3 - Avg of Hi and Low | 4 - Close
    'maxPosPct': 0,
    'slippage': 0.25,
    'longWeight': 100,
    'shortWeight': 100,
    'rankTolerance': 0,
    'carryCost': 0,
    'rebalFreq': 'Every 4 Weeks' | 'Every Week' | 
                 'Every N Weeks' (2,3,4,6,8,13,26,52),
    'riskStatsPeriod': ['Monthly'] | 'Weekly' | 'Daily'
    },True) # True - output to Pandas DataFrame | [False] to JSON.

screen_rolling_backtest()

Wrapper for POST​ /screen​/rolling-backtest

This operation allows you to run and collect the output of rolling screens. Rolling screens are subsequent, fixed holding period backtests of a screen, moving forward the starting date for each test. Rolling screens are excellent robustness tests.

p123api.Client().screen_rolling_backtest({
    'screen': id,
    'startDt': 'yyyy-mm-dd',
    #
    # Optional parameters
    'endDt': 'yyyy-mm-dd',
    'pitMethod': 'Prelim' | 'Complete',
    'precision': 2 | 3 | 4,
    'transPrice': 1, # 1 - Open | 3 - Avg of Hi and Low | 4 - Close
    'maxPosPct': 0,
    'slippage': 0.25,
    'longWeight': 100,
    'shortWeight': 100,
    'frequency': 'Every 4 Weeks' | 'Every Week',
    'holdingPeriod': 182
})

Go to:

Did this answer your question?