如何将Quantopian平台的公开数据集导入本地Python脚本?
First off, let's get the hard truth out there: Quantopian shut down its core services back in 2020, so all official APIs—including the dataset import tools you’re hoping to use—are completely non-functional now. The quantopian PyPI package never existed, and quantopian-tools was deprecated long ago with no remaining access to the original databases. Those paths are dead ends.
That said, you have solid alternatives to get similar data for your local Python scripts:
Leverage public or third-party data sources
Most of Quantopian’s datasets came from public or commercial providers that you can access directly. For example:- Free options: Yahoo Finance, Alpha Vantage, or Federal Reserve Economic Data (FRED). Use libraries like
pandas-datareaderto pull this data into your local environment easily:import pandas_datareader.data as web from datetime import datetime start_date = datetime(2021, 1, 1) end_date = datetime(2024, 1, 1) # Pull Apple stock data from Yahoo Finance stock_data = web.DataReader("AAPL", "yahoo", start_date, end_date) - Paid options: If you need professional-grade data (like the CRSP/Compustat datasets Quantopian used), providers like Nasdaq Data Link (formerly Quandl), Polygon.io, or FactSet offer APIs that integrate seamlessly with Python.
- Free options: Yahoo Finance, Alpha Vantage, or Federal Reserve Economic Data (FRED). Use libraries like
Check community-backed backups
Some developers backed up subsets of Quantopian’s datasets before the platform shut down, which you might find on GitHub or other code hosting platforms. Critical note: Always verify the data’s license before using it—many of Quantopian’s datasets had restricted usage rights, so you can’t use backups for commercial purposes without explicit permission.Recreate custom datasets locally
If the dataset you want was a derived factor (like custom moving averages or volatility metrics), you can rebuild it yourself using raw market data and Python libraries likepandasorNumPy. For example, calculate a 50-day moving average once you have daily price data for your target assets.
Just to recap: There’s no direct way to pull Quantopian’s original datasets into a local script anymore, but these alternatives should get you close to matching your original needs.
内容的提问来源于stack exchange,提问作者KOB

