To calculate factor returns using TOPIX as the universe, I attempted to retrieve the stock prices of the index constituents. However, the volume of data is too large and I am hitting the daily data retrieval limit. I would appreciate any suggestions on a better approach.
I am currently downloading the data using the following process, but I encounter the limit at step 2:
- Retrieve the RICs of TOPIX constituents as of a month-end date (for example, the end of August).
- Retrieve the stock prices for those RICs for the following month (for example, September 1–30) and save them in a DataFrame.
- Calculate returns directly from the stock prices stored in the DataFrame.
In addition, since there are approximately 1,600 constituents, I receive an error indicating that the request is too large when I attempt to retrieve all data at once. I therefore split the request into chunks of 50 RICs. However, some specific chunks return errors and no price data is retrieved.
I would be grateful for any advice on how to handle this more efficiently or reliably.
The actual code is as follows.
First, retrieve the universe:
df_tpx = ld.get_data(
universe=['0#.TOPX'],
fields=[f'TR.PriceClose(SDate={target_date},EDate={target_date})']
)
ric_col = df_tpx.columns[0]
rics = list(df_tpx[ric_col].dropna().unique())
Pattern 1:
df_history = ld.get_history(
universe=rics,
fields=['TRDPRC_1'],
start='2026-07-31',
end='2026-08-31',
interval='1D'
)
Pattern 2:
start_date = '2026-07-30'
end_date = '2026-08-31'
chunk_size = 50
long_dfs = []
for i in range(0, len(rics), chunk_size):
chunk_rics = rics[i:i + chunk_size]
try:
df_history = ld.get_history(
universe=chunk_rics,
fields=['TRDPRC_1'],
start=start_date,
end=end_date,
interval='1D'
)
if df_history is not None and not df_history.empty:
df_l = df_history.stack().reset_index()
df_l.columns = ['date', 'ric', 'close']
long_dfs.append(df_l)
except Exception as e:
print(
f"Error occurred for chunk {i} to {i + len(chunk_rics)} "
f"(skipped): {e}"
)