Hi,
Is there any way to count the number (or %) of NA for a factor on a specific universe from API?
Without factset licence.
Maybe with a screener on a specific date with an Eval (factor, 1,0) ?
A % on a specific period would be nice.
Hi,
Is there any way to count the number (or %) of NA for a factor on a specific universe from API?
Without factset licence.
Maybe with a screener on a specific date with an Eval (factor, 1,0) ?
A % on a specific period would be nice.
If you want to retrieve the NA count as reported by a ranking system, you can do this directly through the API.
Use the endpoint:
POST /rank/ranks
In the request body, include the parameter that enables NA reporting (set includeNaCnt to true). If you're testing via the Swagger page, you can paste this request body there and execute it to see the output.
https://api.portfolio123.com/docs/index.html
{
"pitMethod": "Complete",
"precision": 2,
"rankingSystem": 403577,
"universe": "easy to trade us",
"rankingMethod": 2,
"asOfDt": "2026-04-21",
"includeNames": false,
"includeNaCnt": true,
"includeFinalStmt": false,
"nodeDetails": "composite",
"currency": "USD",
"figi": "Share Class"
}
The response will be returned in JSON format, structured in columns. The NA count is included in that output, but it may not be immediately obvious—you’ll likely need to inspect the fields and parse the structure to extract the exact value.
The API allows Z Score in data_universe without a data license, so you could do this example which gets the count of NAs for 2 factors in the prussell 1000 on a single date.
import p123api
import pandas as pd
try:
client = p123api.Client(api_id='your id', api_key='your key',
endpoint="https://api.portfolio123.com")
data = client.data_universe(
{
"universe": 'prussell1000',
"pitMethod": 'Complete',
"asOfDt": '2026-04-21',
'names': ['zPr2CashFlQ','zCostGQ'],
'formulas': [
# 'FCount("ZScore(`Pr2CashFlQ`, #All, 7.5, 999)=999")', #failed - requires data license
# 'FCount("Pr2CashFlQ=NA")', #failed - requires data license
'ZScore("Pr2CashFlQ",#All, 0, 999)',
'ZScore("CostGQ",#All, 0, 999)'
]
}, True) #True to output to dataframe
zscore_999_count = (data['zPr2CashFlQ'] == 999).sum()
print(f"Count of Pr2CashFlQ = NA: {zscore_999_count}")
PercentNA = 100*(zscore_999_count/len(data))
print(f"Percent of Pr2CashFlQ = NA: {PercentNA}")
zscore_999_count = (data['zCostGQ'] == 999).sum()
print(f"Count of CostGQ = NA: {zscore_999_count}")
PercentNA = 100*(zscore_999_count/len(data))
print(f"Percent of CostGQ = NA: {PercentNA}")
except p123api.ClientException as e:
print(e)
Much better answer since the request was for NAs of a factor!
You can also use the lightly documented preproc request parameter.
import p123api
import pandas as pd
try:
client = p123api.Client(api_id='yourID', api_key='yourkey',
endpoint="https://api.portfolio123.com")
data = client.data_universe(
{
"universe": 'prussell1000',
"pitMethod": 'Complete',
"asOfDt": '2026-04-21',
'names': ['Pr2CashFlQ','CostGQ'],
'formulas': [
"Pr2CashFlQ",
"CostGQ"
],
"preproc": {
"scaling": "rank",
"scope" : "date",
"naFill": "false"
}
}, True) #True to output to dataframe
null_count = data['Pr2CashFlQ'].isna().sum()
print(f"Count of Pr2CashFlQ = NA: {null_count}")
PercentNA = 100*(null_count/len(data))
print(f"Percent of Pr2CashFlQ = NA: {PercentNA}")
null_count = data['CostGQ'].isna().sum()
print(f"Count of CostGQ = NA: {null_count}")
PercentNA = 100*(null_count/len(data))
print(f"Percent of CostGQ = NA: {PercentNA}")
except p123api.ClientException as e:
print(e)
Amazing, I didn’t see it.
It works!
Thanks.