book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

Securities and Exchange Commission

US SEC Filings

Introduction

The US SEC Filings dataset provides the quarterly financial earning reports that the United States Securities and Exchange Commission (SEC) requires from publicly traded companies in the US. The data covers 15,000 US Equities, starts in January 1998, and is delivered on a daily frequency. The data is sourced from the SEC's Electronic Data Gathering, Analysis, and Retrieval (EDGAR) system. QuantConnect downloads and formats the Quarterly Financial Reports (10-Q) and Annual Financial Report (8-K) filings of companies into a format for easy consumption by LEAN.

For more information about the US SEC Filings dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

The mission of the U.S. Securities and Exchange Commission is to protect investors, maintain fair, orderly, and efficient markets, and facilitate capital formation. The SEC oversees the key participants in the securities world, including securities exchanges, securities brokers and dealers, investment advisors, and mutual funds. The SEC is concerned primarily with promoting the disclosure of important market-related information, maintaining fair dealing, and protecting against fraud.

Getting Started

The following snippet demonstrates how to request data from the US SEC Filings dataset:

from QuantConnect.DataSource import *

self.aapl = self.add_equity("AAPL", Resolution.MINUTE).symbol
self.report_8k_symbol = self.add_data(SECReport8K, self.aapl).symbol
self.report_10k_symbol = self.add_data(SECReport10K, self.aapl).symbol
self.report_10q_symbol = self.add_data(SECReport10Q, self.aapl).symbol
using QuantConnect.DataSource;

_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
_report8KSymbol = AddData<SECReport8K>(_symbol, Resolution.Daily).Symbol;
_report10KSymbol = AddData<SECReport10K>(_symbol, Resolution.Daily).Symbol;
_report10QSymbol = AddData<SECReport10Q>(_symbol, Resolution.Daily).Symbol;

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 1998
Asset Coverage15,000 US Equities
Data DensitySparse
ResolutionDaily
TimezoneUTC

Requesting Data

To add US SEC Filings data to your algorithm, call the AddDataadd_data method. Save a reference to the dataset Symbol so you can access the data later in your algorithm.

class SECReportAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2019, 8, 21)
        self.set_cash(100000)

        self.aapl = self.add_equity("AAPL", Resolution.MINUTE).symbol
        self.report_8k_symbol = self.add_data(SECReport8K, self.aapl).symbol
        self.report_10k_symbol = self.add_data(SECReport10K, self.aapl).symbol
        self.report_10q_symbol = self.add_data(SECReport10Q, self.aapl).symbol
namespace QuantConnect
{
    public class SECReportAlgorithm : QCAlgorithm
    {
        private Symbol _symbol, _report8KSymbol, _report10KSymbol, _report10QSymbol;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2019, 8, 21);
            SetCash(100000);

            _symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
            _report8KSymbol = AddData<SECReport8K>(_symbol, Resolution.Daily).Symbol;
            _report10KSymbol = AddData<SECReport10K>(_symbol, Resolution.Daily).Symbol;
            _report10QSymbol = AddData<SECReport10Q>(_symbol, Resolution.Daily).Symbol;
        }
    }
}

Accessing Data

To get the current US SEC Filings data, index the current Slice with the dataset Symbol. Slice objects deliver unique events to your algorithm as they happen, but the Slice may not contain data for your dataset at every time step. To avoid issues, check if the Slice contains the data you want before you index it.

def on_data(self, slice: Slice) -> None:
    if slice.contains_key(self.report_8k_symbol):
        data_point = slice[self.report_8k_symbol]
        self.log(f"{self.report_8k_symbol} report count at {slice.time}: {len(data_point.report.documents)}")

    if slice.contains_key(self.report_10k_symbol):
        data_point = slice[self.report_10k_symbol]
        self.log(f"{self.report_10k_symbol} report count at {slice.time}: {len(data_point.report.documents)}")

    if slice.ContainsKey(self.report_10q_symbol):
        data_point = slice[self.report_10q_symbol]
        self.log(f"{self.report_10q_symbol} report count at {slice.Time}: {len(data_point.report.documents)}")
public override void OnData(Slice slice)
{
    if (slice.ContainsKey(_report8KSymbol))
    {
        var dataPoint = slice[_report8KSymbol];
        Log($"{_report8KSymbol} report count at {slice.Time}: {data_point.Report.Documents.Count}");
    }

    if (slice.ContainsKey(_report10KSymbol))
    {
        var dataPoint = slice[_report10KSymbol];
        Log($"{_report10KSymbol} report count at {slice.Time}: {data_point.Report.Documents.Count}");
    }

    if (slice.ContainsKey(_report10QSymbol))
    {
        var dataPoint = slice[_report10QSymbol];
        Log($"{_report10QSymbol} report count at {slice.Time}: {data_point.Report.Documents.Count}");
    }
}

To iterate through all of the dataset objects in the current Slice, call the Getget method.

def on_data(self, slice: Slice) -> None:
    for dataset_symbol, data_point in slice.get(SECReport8K).items():
        self.log(f"{dataset_symbol} report count at {slice.time}: {len(data_point.report.documents)}")

    for dataset_symbol, data_point in slice.get(SECReport10K).items():
        self.log(f"{dataset_symbol} report count at {slice.time}: {len(data_point.report.documents)}")

    for dataset_symbol, data_point in slice.get(SECReport10Q).items():
        self.log(f"{dataset_symbol} report count at {slice.time}: {len(data_point.report.documents)}")
public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Get<SECReport8K>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} report count at {slice.Time}: {dataPoint.Report.Documents.Count}");
    }

    foreach (var kvp in slice.Get<SECReport10K>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} report count at {slice.Time}: {dataPoint.Report.Documents.Count}");
    }

    foreach (var kvp in slice.Get<SECReport10Q>())
    {
        var datasetSymbol = kvp.Key;
        var dataPoint = kvp.Value;
        Log($"{datasetSymbol} report count at {slice.Time}: {dataPoint.Report.Documents.Count}");
    }
}

Historical Data

To get historical US SEC Filings data, call the Historyhistory method with the dataset Symbol. If there is no data in the period you request, the history result is empty.

# DataFrames
report_8k_history_df = self.history(self.report_8k_symbol, 100, Resolution.DAILY)
report_10k_history_df = self.history(self.report_10k_symbol, 100, Resolution.DAILY)
report_10q_history_df = self.history(self.report_10q_symbol, 100, Resolution.DAILY)
history_df = self.history([self.report_8k_symbol, 
                           self.report_10k_symbol,
                           self.report_10q_symbol], 100, Resolution.DAILY)

# Dataset objects
report_8k_history_bars = self.history[SECReport8K](self.report_8k_symbol, 100, Resolution.DAILY)
report_10k_history_bars = self.history[SECReport10K](self.report_10k_symbol, 100, Resolution.DAILY)
report_10q_history_bars = self.history[SECReport10Q](self.report_10q_symbol, 100, Resolution.DAILY)
// Dataset objects
var report8KHistory = History<SECReport8K>(_report8KSymbol, 100, Resolution.Daily);
var report10KHistory = History<SECReport10K>(_report10KSymbol, 100, Resolution.Daily);
var report10QHistory = History<SECReport10Q>(_report10QSymbol, 100, Resolution.Daily);

// Slice objects
var history = History(new[] {_report8KSymbol, _report10KSymbol, _report10QSymbol}, 100, Resolution.Daily);

For more information about historical data, see History Requests.

Remove Subscriptions

To remove a subscription, call the RemoveSecurityremove_security method.

self.remove_security(self.report_8k_symbol)
self.remove_security(self.report_10k_symbol)
self.remove_security(self.report_10q_symbol)
RemoveSecurity(_report8KSymbol);
RemoveSecurity(_report10KSymbol);
RemoveSecurity(_report10QSymbol);

If you subscribe to US SEC Filings data for assets in a dynamic universe, remove the dataset subscription when the asset leaves your universe. To view a common design pattern, see Track Security Changes.

Example Applications

The US SEC Filings dataset enables you to create strategies using information from SEC reports. Examples include the following strategies:

  • Extracting information about corporate earnings from the documents for further analysis
  • Applying sentiment analysis to the text content of the documents (for example, keyword scoring and ranking)

Classic Algorithm Example

The following example algorithm creates a dynamic universe of the 10 most liquid US Equities. It then buys the securities that have an 8K report with more than 20,000 characters and forms an equal-weighted portfolio. Instead of trading based on how long the report is, you could use sentiment analysis by scoring keywords.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class SECReport8KAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2019, 12, 31)
        self.set_cash(100000)

        self.universe_settings.resolution = Resolution.DAILY
        self.add_universe(self.coarse_selector)
        self.dataset_symbol_by_symbol = {}
        self.long_symbols = []
        self.rebalance = False

        # Request underlying equity data.
        ibm = self.add_equity("IBM", Resolution.DAILY).symbol
        # Add news data for the underlying IBM asset for trade signal generation
        earnings_filing = self.add_data(SECReport10Q, ibm, Resolution.DAILY).symbol
        # Request 120 days of history with the SECReport10Q IBM custom data Symbol
        history = self.history(SECReport10Q, earnings_filing, 120, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from our history request")

    def coarse_selector(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
        # Select the top 10 traded companies with fundamental data, since the market activities can better reflect the fundamental factor efficiently
        coarse = sorted([cf for cf in coarse if cf.has_fundamental_data],
            key=lambda cf: cf.dollar_volume, reverse=True)[:10]
        return [cf.symbol for cf in coarse]

    def on_data(self, slice: Slice) -> None:
        # Trade from SEC data 
        for report in slice.Get(SECReport8K).Values:
            underlying_symbol = report.symbol.underlying
            # Skip the Symbol if it's no longer in the universe (insuffucient popularity to reach market efficiency of fundamental factor)
            if underlying_symbol not in self.dataset_symbol_by_symbol:
                if underlying_symbol in self.long_symbols:
                    self.rebalance = True
                    self.long_symbols.remove(underlying_symbol)
                continue

            # Long the stocks with SEC report over 20000 text length, suggesting excessive insights or future projections are highlighted
            report_text_length = sum([len(i.text) for i in report.report.documents])
            if report_text_length > 20000:
                if underlying_symbol not in self.long_symbols:
                    self.rebalance = True
                    self.long_symbols.append(underlying_symbol)
            elif underlying_symbol in self.long_symbols:
                self.rebalance = True
                self.long_symbols.remove(underlying_symbol)

        if not self.rebalance:
            return
        self.rebalance = False

        # Invest equally to evenly dissipate the capital concentration risk
        portfolio_targets = []
        equal_weighting = 1 / len(self.long_symbols) if len(self.long_symbols) > 0 else 0
        for symbol, security_holding in self.portfolio.items():
            weight = 0
            if symbol in self.long_symbols:
                weight = equal_weighting
            elif not security_holding.invested:
                continue
            portfolio_targets.append(PortfolioTarget(symbol, weight))
        self.set_holdings(portfolio_targets)


    def on_securities_changed(self, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            # If added to universe, adds SECReport8K for trade signal generation
            self.dataset_symbol_by_symbol[security.symbol] = self.add_data(SECReport8K, security.symbol).symbol

        for security in changes.removed_securities:
            # Remove SEC data subscription to release computation resources
            dataset_symbol = self.dataset_symbol_by_symbol.pop(security.symbol, None)
            if dataset_symbol:
                self.remove_security(dataset_symbol)
using QuantConnect.DataSource;

namespace QuantConnect
{
    public class SECReport8KAlgorithm : QCAlgorithm
    {
        private Dictionary<Symbol, Symbol> _datasetSymbolBySymbol = new Dictionary<Symbol, Symbol>();
        private List<Symbol> _longSymbols = new List<Symbol>();
        private bool _rebalance = False;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2019, 12, 31);
            SetCash(100000);

            UniverseSettings.Resolution = Resolution.Daily;
            AddUniverse(CoarseSelector);

            // Request underlying equity data.
            var ibm = AddEquity("IBM", Resolution.Daily).Symbol;
            // Add SEC report 10-Q data for the underlying IBM asset for trade signal generation
            var earningsFiling = AddData<SECReport10Q>(ibm, Resolution.Daily).Symbol;
            // Request 120 days of history with the SECReport10Q IBM custom data Symbol.
            var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
            Debug($"We got {history.Count()} items from our history request");
        }

        public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
        {
            // Select the top 10 traded companies with fundamental data, since the market activities can better reflect the fundamental factor efficiently
            return coarse.Where(x => x.HasFundamentalData)
                .OrderByDescending(x => x.DollarVolume)
                .Take(10).Select(x => x.Symbol);
        }

        public override void OnData(Slice slice)
        {
            // Trade from SEC data 
            foreach (var report in slice.Get<SECReport8K>().Values)
            {
                var underlyingSymbol = report.Symbol.Underlying;
                // Skip the Symbol if it's no longer in the universe (insuffucient popularity to reach market efficiency of fundamental factor)
                if (!_datasetSymbolBySymbol.ContainsKey(underlyingSymbol))
                {
                    if (_longSymbols.Contains(underlyingSymbol))
                    {
                        _rebalance = True;
                        _longSymbols.Remove(underlyingSymbol);
                    }
                    continue;
                }

                // Long the stocks with SEC report over 20000 text length, suggesting excessive insights or future projections are highlighted
                var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
                if (reportTextLength > 20000)
                {
                    if (!_longSymbols.Contains(underlyingSymbol))
                    {
                        _rebalance = True;
                        _longSymbols.Add(underlyingSymbol);
                    }
                }
                else if (_longSymbols.Contains(underlyingSymbol))
                {
                    _rebalance = True;
                    _longSymbols.Remove(underlyingSymbol);
                }
            }

            if (!_rebalance)
            {
                return;
            }
            _rebalance = False;

            // Invest equally to evenly dissipate the capital concentration risk
            var portfolioTargets = new List<PortfolioTarget>();
            var equalWeighting = _longSymbols.Count > 0 ? 1.0m / _longSymbols.Count : 0m;
            foreach (var kvp in Portfolio)
            {
                var symbol = kvp.Key;
                var securityHolding = kvp.Value;
                var weight = 0m;
                if (_longSymbols.Contains(symbol))
                {
                    weight = equalWeighting;
                }
                else if (!securityHolding.Invested)
                {
                    continue;
                }
                portfolioTargets.Add(new PortfolioTarget(symbol, weight));
            }
            SetHoldings(portfolioTargets);
        }

        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            foreach (var security in changes.AddedSecurities)
            {
                // If added to universe, adds SECReport8K for trade signal generation
                _datasetSymbolBySymbol[security.Symbol] = AddData<SECReport8K>(security.Symbol).Symbol;
            }

            foreach (var security in changes.RemovedSecurities)
            {                
                Symbol reportSymbol;
                if (_datasetSymbolBySymbol.TryGetValue(security.Symbol, out reportSymbol))
                {
                    // Remove SEC data subscription to release computation resources
                    RemoveSecurity(reportSymbol);
                    _datasetSymbolBySymbol.Remove(security.Symbol);
                }
            }
        }
    }
}

Framework Algorithm Example

The following example algorithm creates a dynamic universe of the 10 most liquid US Equities. It then buys the securities that have an 8K report with more than 20,000 characters and forms an equal-weighted portfolio. Instead of trading based on how long the report is, you could use sentiment analysis by scoring keywords.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class SECReport8KAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2019, 12, 31)
        self.set_cash(100000)

        self.universe_settings.resolution = Resolution.DAILY
        # Filter for the most liquid stocks for trading due to high market activities for effecient pricing from fundamental factor
        self.add_universe_selection(MostLiquidFundamentalUniverseSelectionModel(self.universe_settings))
        # Custom alpha model that generates insights from SEC data
        self.add_alpha(SECReport8KAlphaModel())
        # Invest equally to evenly dissipate the capital concentration risk
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel(lambda time: None))


class MostLiquidFundamentalUniverseSelectionModel(CoarseFundamentalUniverseSelectionModel):
    def __init__(self, universe_settings: UniverseSettings) -> None:
        super().__init__(self.select_coarse, universe_settings)

    def select_coarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
        # Select the top 10 traded companies with fundamental data, since the market activities can better reflect the fundamental factor efficiently
        selected = [c for c in coarse if c.has_fundamental_data]
        sorted_by_dollar_volume = sorted(selected, key=lambda c: c.dollar_volume, reverse=True)
        return [c.symbol for c in sorted_by_dollar_volume[:10]]


class SECReport8KAlphaModel(AlphaModel):
    dataset_symbol_by_symbol = {}
    
    def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
        insights = []

        # Trade only based on SEC data 
        for report in slice.Get(SECReport8K).Values:
            underlying_symbol = report.symbol.underlying
            if underlying_symbol not in self.dataset_symbol_by_symbol:
                continue

            # Long the stocks with SEC report over 20000 text length, suggesting excessive insights or future projections are highlighted
            report_text_length = sum([len(i.text) for i in report.report.documents])

            if report_text_length > 20000:
                direction = InsightDirection.UP
            elif algorithm.portfolio[underlying_symbol].invested:
                direction = InsightDirection.FLAT
            else:
                continue
            insights.append(Insight.price(underlying_symbol, timedelta(days=30), direction))

        return insights

    def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            # If added to universe, adds SECReport8K for trade signal generation
            self.dataset_symbol_by_symbol[security.symbol] = algorithm.add_data(SECReport8K, security.symbol).symbol

        for security in changes.removed_securities:
            # Remove SEC data subscription to release computation resources
            symbol_data = self.dataset_symbol_by_symbol.pop(security.symbol, None)
            if symbol_data:
                algorithm.remove_security(symbol_data)
using QuantConnect.DataSource;

namespace QuantConnect
{
    public class SECReport8KAlgorithm : QCAlgorithm
    {
        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2019, 12, 31);
            SetCash(100000);

            UniverseSettings.Resolution = Resolution.Daily;
            // Filter for the most liquid stocks for trading due to high market activities for effecient pricing from fundamental factor
            AddUniverseSelection(new MostLiquidFundamentalUniverseSelectionModel(UniverseSettings));
            // Custom alpha model that generates insights from SEC data
            AddAlpha(new SECReport8KAlphaModel());
            // Invest equally to evenly dissipate the capital concentration risk
            SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(time => None));
        }
    }

    class MostLiquidFundamentalUniverseSelectionModel : CoarseFundamentalUniverseSelectionModel
    {
        public MostLiquidFundamentalUniverseSelectionModel(UniverseSettings universeSettings)
            : base(default(Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>>), universeSettings)
        {
        }

        public override IEnumerable<Symbol> SelectCoarse(QCAlgorithm algorithm, IEnumerable<CoarseFundamental> coarse)
        {
            // Select the top 10 traded companies with fundamental data, since the market activities can better reflect the fundamental factor efficiently
            return coarse.Where(x => x.HasFundamentalData)
                .OrderByDescending(x => x.DollarVolume)
                .Take(10).Select(x => x.Symbol);
        }
    }

    public class SECReport8KAlphaModel : AlphaModel
    {
        private Dictionary<Symbol, Symbol> _datasetSymbolBySymbol = new Dictionary<Symbol, Symbol>();

        public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
        {
            var insights = new List<Insight>();

            // Trade only based on SEC data 
            foreach (var report in slice.Get<SECReport8K>().Values)
            {
                var underlyingSymbol = report.Symbol.Underlying;
                if (!_datasetSymbolBySymbol.ContainsKey(underlyingSymbol))
                {
                    continue;
                }

                // Long the stocks with SEC report over 20000 text length, suggesting excessive insights or future projections are highlighted
                var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
                InsightDirection direction;
                if (reportTextLength > 20000)
                {
                    direction = InsightDirection.Up;
                }
                else if (algorithm.Portfolio[underlyingSymbol].Invested)
                {
                    direction = InsightDirection.Flat;
                }
                else
                {
                    continue;
                }
                insights.Add(Insight.Price(underlyingSymbol, TimeSpan.FromDays(30), direction));
            }

            return insights;
        }

        public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
        {
            foreach (var symbol in changes.AddedSecurities.Select(x => x.Symbol))
            {
                // If added to universe, adds SECReport8K for trade signal generation
                _datasetSymbolBySymbol[symbol] = algorithm.AddData<SECReport8K>(symbol).Symbol;
            }
        	
            foreach (var symbol in changes.RemovedSecurities.Select(x => x.Symbol))
            {
                // Remove SEC data subscription to release computation resources
                Symbol reportSymbol;
                if (_datasetSymbolBySymbol.TryGetValue(symbol, out reportSymbol))
                {
                        algorithm.RemoveSecurity(reportSymbol);
                        _datasetSymbolBySymbol.Remove(symbol);
                }
            }
        }
    }
}

Data Point Attributes

The US SEC Filings dataset provides SECReport8K, SECReport10K, and SECReport10Q objects.

Report 8K Attributes

SECReport8K objects have the following attributes:

Report 10K Attributes

SECReport10K objects have the following attributes:

Report 10Q Attributes

SECReport10Q objects have the following attributes:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: