API functions: Data Retrieval

API functions for data retrieval operations

Marco Salerno
Written by Marco SalernoLast update 9 days ago

Data Functions

data

This operation allows you to retrieve large sets of data from our point in time engine.

data_universe

This operation allows you to retrieve point in time data for a selected universe.

data()

Wrapper for POST /data

This operation allows you to retrieve large sets of data from our point in time engine. You will need to obtain your own license from the data vendor (Factset or Compustat) to fully access. You can try it without a license with the following stocks: IBM, MSFT & INTC and for 5 years of history. Alternatively see the data_universe() operation below to download normalized data.

p123api.Client().data({
    # Specify either: tickers, FIGI, p123Uids, CIKs, 
    # or gvkeys (Compustat only)
    'tickers': ['ticker1', 'ticker2'' ...],
    'formulas': ['form1', 'form2', ... ],
    'startDt': 'yyyy-mm-dd',
    'endDt': 'yyyy-mm-dd',
    # optional parameters
    'currency': 'USD' | 'CAD' | 'CHF' | 'EUR' | 'GBP' | 'NOK' | 'PLN' | 'SEK' | 'TRY',
    'precision': 2 | 3 | 4,
    'frequency': 'Every Week' | 'Every N Weeks' (2,3,4,6,8,13,26,52),
    'pitMethod': 'Prelim' | 'Complete',
    'includeNames': True | False,
    'region': 'United States' | 'Canada' | 'North America' | 'Europe' | 'North Atlantic',
    'ignoreErrors': True | False #True will ignore invalid tickers, FIGI, etc
},True) # True - output to Pandas DataFrame | [False] to JSON.

data_universe()

Wrapper for POSTโ€‹ /dataโ€‹/universe

Example Google Colab

This operation allows you to retrieve point in time data for a selected universe. If a preprocessor that normalizes the data is not used, a data license with our vendor might be required. For the universe parameter, specify the name of your custom universe or one of the Portfolio123 universes.


p123api.Client().data_universe({
    # Specify the universe name (ex 'SP500'). To use the 
    # API universe that can be updated with other
    # API functions use 'APIUniverse' 
        "universe": "DJIA" # universe symbol or name
        , "asOfDts": ["2024-03-16","2024-03-09"]  # use weekend dates
        , "formulas": [ "Close(0)/close(5)", "PEExclXorTTM", "SalesGr%TTM" ]
        # names optional. Must match the number of columns in formulas
        , "names":["1wk%","PE","SalesGr"] 
        , "pitMethod": 'Prelim' | 'Complete'
        # use None for max precision 
        , "precision": None | 2 | 3 | 4
        , "type": "stock" | "etf"
        # add company name column
        , "includeNames": False 
        , "figi": "Country Composite" | "Share Class"
        , 'currency': 'USD' | 'CAD' | 'CHF' | 'EUR' | 'GBP' | 'NOK' | 'PLN' | 'SEK' | 'TRY'

        # normalization
        ,"preproc": {
            "scaling": "minmax" | "rank" | "normal"
            , "scope" : "dataset" | "date"
            , "trimPct": 5.0
            , "outliers": True # when True outliers are clipped
            , "naFill": False # when True NAs are set to the middle values
            , "outlierLimit": 5 # used for normal scaling
            # data license required for non technical factors
            , "excludedFormulas": ["Close(0)/close(5)"] 
            # end date for the scaling when scope = dataset
            , "mlTrainingEnd": "2020-01-01" 
          }
        }
    , to_pandas=True
    )

Go to:

Did this answer your question?