Factors
QuantConnect.DataSource.Factors
Factors()
Bases: DynamicData
Factor values and positions. Subscribe with a security's Symbol to get each factor's value for it and its position in it: how much of the security the factor holds, from the first open after the data point's time. Subscribe with UNLINKED to get the unlinked factors' market-wide series. Each data point behaves like a dictionary of factor name to value, and position gives a factor's position. A data point holds the numbers that are new at its time.
Creates an empty instance, required by LEAN to construct the type
UNLINKED
UNLINKED: str = '$UNLINKED'
Ticker for the unlinked factors subscription
PAIR
PAIR: str = '$PAIR'
Start of the identifier cell of a pair row in the universe files, as in $PAIR(KO R735QTJ8XC9X;PEP R735QTJ8XC9X)
HEDGE_RATIO_SUFFIX
HEDGE_RATIO_SUFFIX: str = '_hedge_ratio'
End of the name of a pairs factor's hedge ratio column, as in closest_price_pairs_hedge_ratio
POSITION_SUFFIX
POSITION_SUFFIX: str = '_position'
End of the name of a factor's position column, as in roc_1d_position
ROC_1_DAY
ROC_1_DAY: str = 'roc_1d'
1-day rate of change of the close, close
VOLATILITY_21_DAY
VOLATILITY_21_DAY: str = 'volatility_21d'
21-day realized volatility, the standard deviation of the 1-day close-to-close returns over the trailing 21 days, ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
VOLUME_Z_21_DAY
VOLUME_Z_21_DAY: str = 'volume_z_21d'
21-day volume z-score, the number of standard deviations the session's volume sits above or below its trailing 21-day mean, ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
FINRA_SHORT_SALE_VOLUME_SHORT_VOLUME_RATIO_SMA_21_DAY
FINRA_SHORT_SALE_VOLUME_SHORT_VOLUME_RATIO_SMA_21_DAY: (
str
) = "finra_short_sale_volume_short_volume_ratio_sma_21d"
21-point mean of the FINRA Reg SHO daily short volume ratio, the share of a stock's off-exchange reported volume executed as short sales, ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
SPECTRAL_TICK_FLOW_SIGNAL_EXECUTION_SCORE
SPECTRAL_TICK_FLOW_SIGNAL_EXECUTION_SCORE: str = (
"spectral_tick_flow_signal_execution_score"
)
Algorithmic execution-flow intensity, QuantConnect's Spectral Tick Flow Signal execution score: the normalized strength of the strongest recurring intraday execution rhythm in the stock's tick data, ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
UST_YIELD_1_MONTH
UST_YIELD_1_MONTH: str = 'ust_yield_1m'
1-month US Treasury yield curve rate, as published daily at 16:30 New York time. The positions rank each of SPY's constituents on its sensitivity to the yield: the slope on the yield's daily change when the stock's daily returns over the past 21 sessions are regressed on SPY's return and that change. The factor holds the bottom tenth long and the top tenth short, equally weighted.
EARNING_YIELD
EARNING_YIELD: str = 'earning_yield'
Trailing earnings yield, Morningstar's ValuationRatios.EarningYield: diluted EPS over price, ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
MFI_21_DAY
MFI_21_DAY: str = 'mfi_21d'
21-day Money Flow Index, the share of the typical price's money flow over 21 sessions that came on sessions the typical price rose, from 0 to 100, ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
MOM_12_MONTH
MOM_12_MONTH: str = 'mom_12m'
Twelve-month momentum skipping the most recent month, the stock's return over months t-11 through t-1 with 21 sessions to a month, from Jegadeesh and Titman (1993, JF), ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
INT_MOM
INT_MOM: str = 'int_mom'
Intermediate momentum, the stock's return over months t-12 through t-7 with 21 sessions to a month, from Novy-Marx (2012, JFE), ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
MOM_12_MONTH_OFF_SEASON
MOM_12_MONTH_OFF_SEASON: str = 'mom_12m_off_season'
Momentum without the seasonal month, the mean of the monthly returns of months t-1 through t-10 with 21 sessions to a month, from Heston and Sadka (2008, JFE), ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
VIX
VIX: str = 'vix'
CBOE Volatility Index (VIX), the market's expectation of 30-day S&P 500 volatility. The series is VIX's daily close. The positions rank each of SPY's constituents on its sensitivity to VIX: the slope on VIX's daily change when the stock's daily returns over the past 21 sessions are regressed on SPY's return and that change. The factor holds the top tenth long and the bottom tenth short, equally weighted.
WTI_CRUDE_OIL
WTI_CRUDE_OIL: str = 'wti_crude_oil'
WTI crude oil price, the daily mid close of Oanda's West Texas Oil CFD in US dollars per barrel. The positions rank each of SPY's constituents on its sensitivity to the price: the slope on the price's daily change when the stock's daily returns over the past 21 sessions are regressed on SPY's return and that change. The factor holds the bottom tenth long and the top tenth short, equally weighted.
MONETARY_CYCLE
MONETARY_CYCLE: str = 'monetary_cycle'
Monetary cycle, the monetary environment of Jensen, Mercer and Johnson (1996): +1 while the most recent change in the Federal Reserve's primary credit rate was a decrease and -1 while it was an increase, read from LEAN's risk-free interest rate model at midnight New York on every calendar day. The factor times SPY: it holds SPY short while the cycle is +1 and long while it's -1.
VOLUME_TREND
VOLUME_TREND: str = 'volume_trend'
Volume trend, the slope of a regression of monthly volume on a linear time trend over the trailing 60 months over the mean monthly volume, with 21 sessions to a month and at least 30 months, from Haugen and Baker (1996, JFE), ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
MOM_SEASON_SHORT
MOM_SEASON_SHORT: str = 'mom_season_short'
Return seasonality last year, the stock's return over the 21 sessions from 252 to 231 sessions ago, from Heston and Sadka (2008, JFE), ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
ILLIQUIDITY
ILLIQUIDITY: str = 'illiquidity'
Amihud illiquidity, the mean over the past 12 months of the daily ratio of the absolute return to the dollar volume traded, from Amihud (2002, JFM), ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
M_2_GROWTH_1_MONTH
M_2_GROWTH_1_MONTH: str = 'm2_growth_1m'
M2 money supply growth from one monthly release to the next: the Federal Reserve's seasonally adjusted monthly M2 over its value for the month before, minus one, from FRED's series M2SL as currently revised, stamped at the midnight after the day the Federal Reserve's H.6 release first published it. The positions rank each of SPY's constituents on its sensitivity to the growth: the slope on the growth's change when the stock's returns between releases over the last 60 releases are regressed on SPY's return and that change. The factor holds the top tenth long and the bottom tenth short, equally weighted.
GROSS_PROFITS_TO_ASSETS
GROSS_PROFITS_TO_ASSETS: str = 'gross_profits_to_assets'
Gross profits to assets from Novy-Marx (2013, JFE). It's annual revenue minus cost of revenue over total assets from Morningstar's annual accounts, and financial firms are left out. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
RD_TO_MARKET_VALUE
RD_TO_MARKET_VALUE: str = 'rd_to_market_value'
R&D to market value from Chan, Lakonishok and Sougiannis (2001, JF). It's annual research and development expense from Morningstar's annual accounts over the month's market value, and a stock without R&D has no value. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
OPERATING_PROFITABILITY_RD_ADJUSTED
OPERATING_PROFITABILITY_RD_ADJUSTED: str = (
"operating_profitability_rd_adjusted"
)
R&D-adjusted operating profitability from Ball et al. (2016, JFE). It's annual revenue minus cost of revenue and SG&A over total assets, from Morningstar's annual accounts. Morningstar's SG&A leaves out R&D, so R&D isn't counted as an expense. A filing without book equity has no value, and financial firms are left out. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
FABER_10_MONTH_SMA_SECTOR_ETFS
FABER_10_MONTH_SMA_SECTOR_ETFS: str = (
"faber_10_month_sma_sector_etfs"
)
The 10-month moving average timing rule from Faber (2007, Journal of Wealth Management), on the eleven Select Sector SPDR ETFs. An ETF's value is its month-end close over the mean of its last ten month-end closes, minus one. The factor holds an ETF long while its value is positive and nothing otherwise.
SALES_TO_PRICE
SALES_TO_PRICE: str = 'sales_to_price'
Sales to price from Barbee, Mukherji and Raines (1996, Financial Analysts Journal). It's annual revenue from Morningstar's annual accounts over the month's market value. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
CASH_BASED_OPERATING_PROFITABILITY
CASH_BASED_OPERATING_PROFITABILITY: str = (
"cash_based_operating_profitability"
)
Cash-based operating profitability from Ball et al. (2016, JFE). Operating profitability is revenue minus cost of revenue and SG&A from Morningstar's annual accounts. The cash-based measure takes out the year's increase in receivables, inventory and prepaid assets and adds back the year's increase in deferred revenue, accounts payable and accrued expenses. It's then taken over total assets. A missing figure counts as zero. A stock without positive book equity or market value has no value, and financial firms are left out. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
INVESTMENT_TO_REVENUE_VS_OWN_MEAN
INVESTMENT_TO_REVENUE_VS_OWN_MEAN: str = (
"investment_to_revenue_vs_own_mean"
)
Abnormal investment from Titman, Wei and Xie (2004, JFQA). It's annual capital expenditure over revenue from Morningstar's annual accounts, over the stock's own mean of that ratio across the past 36 months, which needs at least 24. A stock with revenue under $10 million has no value. A fiscal year is used from six months after it ends, for twelve months. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
COMPOSITE_EQUITY_ISSUANCE_5_YEAR
COMPOSITE_EQUITY_ISSUANCE_5_YEAR: str = (
"composite_equity_issuance_5y"
)
Composite equity issuance from Daniel and Titman (2006, JF). It's the log growth of market value over the past 60 months minus the stock's return over them, so it measures the equity issued net of buybacks. Market value is Morningstar's at each month's end, and the return comes from adjusted closes. A stock priced at $5 or less has no value. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
BID_ASK_SPREAD_CS
BID_ASK_SPREAD_CS: str = 'bid_ask_spread_cs'
Bid-ask spread from Amihud and Mendelson (1986, JFE) with the high-low estimator from Corwin and Schultz (2012, JF). Each session's estimate compares the ranges of that session and the one before with the range over both, on adjusted daily bars. A range with the high equal to the low, a price that isn't positive or no volume is replaced from the last good range and the close. A range with the high over 8 times the low is dropped, and a range is shifted to take in the prior close when that close lies outside it. Negative estimates count as 0. A month's value is the mean of its daily estimates and needs at least 12 of them. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
VOLUME_SD_36_MONTH
VOLUME_SD_36_MONTH: str = 'volume_sd_36m'
The standard deviation of a stock's monthly share volume over the past 36 months from Chordia, Subrahmanyam and Anshuman (2001, JFE). A stock needs at least 24 of those months, and a month's volume is the sum of its unadjusted daily volumes. Only stocks that Morningstar lists on the NYSE at the formation are ranked. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
SHORT_INTEREST
SHORT_INTEREST: str = 'short_interest'
Short interest, from Dechow et al. (2001, JFE): the shares held short in FINRA's report over Morningstar's shares outstanding of the share class. Each month uses the report FINRA published in the month before on the 16th or later. Formed at the first update of SPY's constituents in each month and ranked then among them. The factor holds the fifth with the least short interest long and the fifth with the most short, equally weighted.
INTANGIBLE_RETURN_BM
INTANGIBLE_RETURN_BM: str = 'intangible_return_bm'
The intangible return on book-to-market, from Daniel and Titman (2006, JF). Each month the 60-month returns of SPY's constituents are regressed on their log book-to-market from 60 months before and on its change over the 60 months plus the return. The residual is the factor's value. Book equity is common stock equity from Morningstar's annual accounts, used from six months after the fiscal year ends for twelve months. Market value is Morningstar's at formation, and the ratio must be positive. Returns come from month-end closes adjusted for splits and dividends. Returns below the 1st percentile of the month's constituents or above the 99th are left out of the regression, and stocks at $5 or less are left out after it. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the top tenth long and the bottom tenth short, equally weighted.
INTANGIBLE_RETURN_CFP
INTANGIBLE_RETURN_CFP: str = 'intangible_return_cfp'
The intangible return on cash flow to price, from Daniel and Titman (2006, JF). Each month the 60-month returns of SPY's constituents are regressed on their log cash flow to price from 60 months before and on its change over the 60 months plus the return. The residual is the factor's value. Cash flow is net income less discontinued operations plus depreciation and amortization, from Morningstar's annual accounts. Discontinued operations count as 0 when missing, and so does depreciation that's missing or from another period's cash flow statement. A fiscal year is used from six months after it ends for twelve months. Market value is Morningstar's at formation, and the ratio must be positive. Returns come from month-end closes adjusted for splits and dividends. Returns below the 1st percentile of the month's constituents or above the 99th are left out of the regression, and stocks at $5 or less are left out after it. Formed at each month's last close and ranked each session among SPY's constituents. The factor holds the bottom tenth long and the top tenth short, equally weighted.
INVESTMENT_PPE_INVENTORY
INVESTMENT_PPE_INVENTORY: str = 'investment_ppe_inventory'
Investment from Lyandres, Sun and Zhang (2008, RFS): the negative of the yearly change in gross PPE plus inventory over the total assets a year before. The figures are Morningstar's annual accounts from a 10-K, 20-F or 40-F filing. A fiscal year is used from 6 to 17 months after the month it ends and the latest one wins. Formed at each month's last close and carried to each session for SPY's constituents. Each constituent's position is the z-score of its value against all of its daily values so far. It needs 126 of them and is capped at 2 either way.
MOM_SEASON_6_TO_10_YEAR
MOM_SEASON_6_TO_10_YEAR: str = 'mom_season_6_10y'
Return seasonality from Heston and Sadka (2008, JFE): the mean of a stock's returns in the same calendar month as the coming one over the years 6 to 10 before. A month's return runs from the last adjusted close of the month before to its own last close, and the mean takes the years that have one. Formed at each month's last close and ranked then among SPY's constituents listed on the NYSE or AMEX. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the top tenth long and the bottom tenth short, equally weighted.
SPECULATIVE_PRESSURE_COMMODITY_ETFS
SPECULATIVE_PRESSURE_COMMODITY_ETFS: str = (
"speculative_pressure_commodity_etfs"
)
Speculative pressure from Fan et al. (2020, Journal of Futures Markets) on twelve commodity ETFs that stand in for the futures. A commodity's pressure is the mean over the past year of its speculators' long minus short positions over their sum, from the CFTC's legacy Commitments of Traders reports. A report counts from its release and the mean needs 26 of them. At each month's last close the pressures of the commodities whose ETF traded that month are standardized across them. Each value is a commodity's z-score over the sum of the z-scores' sizes, times the number of commodities. The values are the positions, held for the month.
STAT_ARB_SECTOR_ETF_RESIDUALS
STAT_ARB_SECTOR_ETF_RESIDUALS: str = (
"stat_arb_sector_etf_residuals"
)
Statistical arbitrage from Avellaneda and Lee (2010, Quantitative Finance) on pairs of a stock and its Select Sector SPDR ETF, the one where the stock's weight is largest. Each day the stock's returns over the past 60 sessions are regressed on the ETF's, and the cumulative residuals are fit to a mean-reverting process. The s-score is the process's distance from its equilibrium level in equilibrium standard deviations, with the levels centered on their average across the stocks. The value is the negative s-score and the hedge ratio is the regression's beta. Each value uses the session's close and is stamped at the midnight after it. The factor holds a pair long from a value above 1.25 until it falls below 0.5, and short from a value below -1.25 until it rises above -0.75. It holds nothing while the residual takes more than 30 sessions to revert, and a pair starts flat after a day it isn't listed.
TREASURY_FORWARD_SPREAD_ETFS
TREASURY_FORWARD_SPREAD_ETFS: str = (
"treasury_forward_spread_etfs"
)
The forward-spot spread from Fama and Bliss (1987, American Economic Review) on four Treasury ETFs. The spread is the one-year forward rate from year n-1 to n minus the one-year yield, on the Treasury's par yield curve. Each ETF takes the n of the maturity it holds: 2 years for SHY and 5 for IEI, with 10 for IEF and 20 for TLT. A yield the curve lacks is interpolated linearly in maturity. The spread is taken on each month's last curve date and stamped at the midnight after it. Each ETF's position is the z-score of its spread against all of its monthly spreads so far. It needs 36 of them and is capped at 2 either way.
LUNAR_PHASE_COUNTRY_ETFS
LUNAR_PHASE_COUNTRY_ETFS: str = 'lunar_phase_country_etfs'
The lunar cycle from Yuan, Zheng and Zhu (2006, Journal of Empirical Finance). The series is the lunar phase at midnight New York on every calendar day: -1 within 7 days of a full moon's date and +1 otherwise. Full moons are dated in UTC with Meeus's Astronomical Algorithms (1998). The factor gives each iShares MSCI single-country ETF and SPY the phase of each session from the session after its first close. It holds them long in new moon periods and short in full moon periods.
COMMODITY_MOMENTUM_ETFS
COMMODITY_MOMENTUM_ETFS: str = 'commodity_momentum_etfs'
Commodity momentum from Miffre and Rallis (2007, Journal of Banking and Finance) on twelve commodity ETFs that stand in for the futures. At each month's last close the ETFs are ranked on their log return over the past 12 months, from each one's last close in the month a year before. The factor holds the top fifth long and the bottom fifth short for the month in equal weights. A fifth is a fifth of the ranked ETFs rounded, and at least one. Each value is the position times the number of ranked ETFs over the number in a fifth.
TREASURY_AUCTION_CYCLE_ETFS
TREASURY_AUCTION_CYCLE_ETFS: str = (
"treasury_auction_cycle_etfs"
)
The Treasury auction cycle from Lou, Yan and Zhang (2013, Review of Financial Studies) on four Treasury ETFs. Each ETF follows the auctions of the maturity it holds: SHY the 2-year note's and IEI the 5-year note's, with IEF the 10-year note's and TLT the 30-year bond's. The auction dates come from EODHD's economic events calendar from 2019. An auction counts once the calendar lists it. Each value is -1 in the 5 sessions before an auction and +1 in the 5 sessions after it, leaving out the auction's session, and 0 otherwise. The values are the positions.
ASSETS_TO_MARKET
ASSETS_TO_MARKET: str = 'assets_to_market'
Assets to market from Fama and French (1992, JF). It's total assets from Morningstar's annual accounts over the market value at the June's last close. A fiscal year is used from six months after it ends for twelve months if it reports total assets and net income. Formed at the last close of each June and ranked then among SPY's constituents. A stock keeps its rank until the next June while it stays in SPY. The factor holds the bottom tenth long and the top tenth short, equally weighted.
BOOK_EQUITY_GROWTH
BOOK_EQUITY_GROWTH: str = 'book_equity_growth'
Book equity growth from Lockwood and Prombutr (2010, Journal of Financial Research). It's common stock equity from Morningstar's annual accounts over the equity in use twelve months before, when both are positive. A fiscal year is used from six months after it ends for twelve months if it reports total assets and net income. Formed at the last close of each June and ranked then among SPY's constituents. A stock keeps its rank until the next June while it stays in SPY. The factor holds the bottom tenth long and the top tenth short, equally weighted.
NET_DEBT_TO_PRICE
NET_DEBT_TO_PRICE: str = 'net_debt_to_price'
Net debt to price from Penman, Richardson and Tuna (2007, Journal of Accounting Research). Net debt is long-term debt plus current debt and preferred stock less cash and marketable securities, from Morningstar's annual accounts. Missing cash counts as 0. It's taken over the market value at the June's last close. Financial firms and stocks without book equity are left out. Only the constituents in the top three fifths of book equity over market value are ranked. A fiscal year is used from six months after it ends for twelve months if it reports total assets and net income. Formed at the last close of each June and ranked then among SPY's constituents. A stock keeps its rank until the next June while it stays in SPY. The factor holds the bottom tenth long and the top tenth short, equally weighted.
INTANGIBLE_RETURN_SALES
INTANGIBLE_RETURN_SALES: str = 'intangible_return_sales'
The intangible return on sales to price, from Daniel and Titman (2006, JF). Each June the 60-month returns of SPY's constituents are regressed on their log sales to price from 60 months before and on its change over the 60 months plus the return. The residual is the factor's number. Sales is total revenue from Morningstar's annual accounts, and market value is Morningstar's at the month's last close. The ratio must be positive. Returns come from month-end closes adjusted for splits and dividends. Returns below the 1st percentile of the June's constituents or above the 99th are left out of the regression. A fiscal year is used from six months after it ends for twelve months if it reports total assets and net income. Formed at the last close of each June and ranked then among SPY's constituents. A stock keeps its rank until the next June while it stays in SPY. The factor holds the bottom tenth long and the top tenth short, equally weighted.
EQUITY_DURATION
EQUITY_DURATION: str = 'equity_duration'
Equity duration from Dechow, Sloan and Soliman (2004, Review of Accounting Studies). It's the duration of the stock's equity in years over the market value at the fiscal year's end. Each of the next ten years pays out its forecast earnings less its growth in book equity, weighted by the year and discounted at 12%. A terminal value follows them. Return on equity starts from the fiscal year's and moves toward 12% with a persistence of 0.57. Sales growth starts from the fiscal year's and moves toward 6% with a persistence of 0.24. The figures are book equity, net income before discontinued operations and revenue from Morningstar's annual accounts. The year before is the one in use twelve months earlier. A fiscal year is used from six months after it ends for twelve months if it reports total assets and net income. Formed at the last close of each June and ranked then among SPY's constituents. A stock keeps its rank until the next June while it stays in SPY. The factor holds the top tenth long and the bottom tenth short, equally weighted.
TREND_FACTOR
TREND_FACTOR: str = 'trend_factor'
The trend factor from Han, Zhou and Zhu (2016, JFE): a stock's moving averages over 3 to 1,000 sessions weighted by how each predicted the next month's return. The averages are of daily closes adjusted for splits, and each is over the stock's last close. Each month a regression across SPY's constituents priced at $5 or more gives each average's slope on the next month's return. A stock's trend sums its averages times their mean slopes over the 12 months before. Formed at each month's last close and ranked then among SPY's constituents priced at $5 or more. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the top tenth long and the bottom tenth short, equally weighted.
MOMENTUM_OFF_SEASON_6_TO_10_YEAR
MOMENTUM_OFF_SEASON_6_TO_10_YEAR: str = (
"momentum_off_season_6y_10y"
)
Off-season momentum from Heston and Sadka (2008, JFE): the mean of a stock's monthly returns over the years 6 to 10 before, leaving out the months in the same calendar month as the coming one. A month's return runs from the last adjusted close of the month before to its own last close. It's 0 when the stock didn't trade the month before, and the mean takes the months the stock traded. Formed at each month's last close and ranked then among SPY's constituents that Morningstar lists on the NYSE or AMEX. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the tenth with the lowest mean long and the tenth with the highest short, equally weighted.
IDIOSYNCRATIC_SKEWNESS_FF_3
IDIOSYNCRATIC_SKEWNESS_FF_3: str = (
"idiosyncratic_skewness_ff3_1m"
)
Idiosyncratic skewness from Bali, Engle and Murray (2015): the skewness of a stock's daily residuals over a month. The residuals are from a regression of its daily excess returns on the Fama-French market, size and value factors. A month needs 15 sessions with a return and the factors. A daily return needs the stock's adjusted closes on the session and the one before, and the factors are QuantConnect's daily Fama-French factors. Formed at each month's last close and ranked then among SPY's constituents. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the tenth with the highest skewness long and the tenth with the lowest short, equally weighted.
BETA_VIX_CHANGE
BETA_VIX_CHANGE: str = 'beta_vix_change'
The beta on changes in the VIX from Ang et al. (2006, JF): the slope of a stock's daily excess returns on the daily change in the VIX close. The slope is from a regression on the change and the market's excess return over the stock's last 20 sessions with all three. It needs 15 of them, and a month takes its last slope. A daily return needs the stock's adjusted closes on the session and the one before, and the market is QuantConnect's daily Fama-French market factor. Formed at each month's last close and ranked then among SPY's constituents. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the tenth with the lowest beta long and the tenth with the highest short, equally weighted.
LONG_RUN_REVERSAL_13_TO_36_MONTH
LONG_RUN_REVERSAL_13_TO_36_MONTH: str = (
"long_run_reversal_13m_36m"
)
Long-run reversal from De Bondt and Thaler (1985, JF): a stock's compounded return over the 13th to 36th months before. A month's return runs from the last adjusted close of the month before to its own last close. It's 0 when the stock didn't trade the month before, and a stock needs to have traded in all 24 months. Formed at each month's last close and ranked then among SPY's constituents. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the tenth with the lowest return long and the tenth with the highest short, equally weighted.
MOMENTUM_OFF_SEASON_11_TO_15_YEAR
MOMENTUM_OFF_SEASON_11_TO_15_YEAR: str = (
"momentum_off_season_11y_15y"
)
Off-season momentum from Heston and Sadka (2008, JFE): the mean of a stock's monthly returns over the years 11 to 15 before, leaving out the months in the same calendar month as the coming one. A month's return runs from the last adjusted close of the month before to its own last close. It's 0 when the stock didn't trade the month before, and the mean takes the months the stock traded. Formed at each month's last close and ranked then among SPY's constituents that Morningstar lists on the NYSE or AMEX. A stock keeps its rank until the next formation while it stays in SPY. The factor holds the tenth with the lowest mean long and the tenth with the highest short, equally weighted.
MOMENTUM_SEASON_11_TO_15_YEAR
MOMENTUM_SEASON_11_TO_15_YEAR: str = (
"momentum_season_11y_15y"
)
Return seasonality from Heston and Sadka (2008, JFE): the mean of a stock's returns in the same calendar month as the coming one over the years 11 to 15 before. A month's return runs from the adjusted close of the last session of the month before to that of its own, and the mean takes the years that have one. Formed at each month's last close for SPY's constituents that Morningstar lists on the NYSE or AMEX and held from the start of the next month. A stock keeps its value until the next formation while it stays in SPY. The factor holds the stocks with a positive mean long and those with a negative one short, equally weighted.
keys
keys: Iterable[str]
Names of the factors this data point carries a value for. A position or a pairs factor's hedge ratio isn't a factor of its own, so it isn't listed.
is_unlinked
is_unlinked: bool
True when this data point carries the unlinked factors rather than a tradable security's factors
is_pair
is_pair: bool
True when this data point is a universe file's row for a pair of securities
b
b: Symbol
The pair's second security on a pair row. A positive position holds it short, at the hedge ratio's dollars for each dollar of a.
end_time
end_time: datetime
Time the numbers became known, in New York time. A position is held from the first open after it. An unlinked value keeps its source series' own time.
data_type
data_type: MarketDataType
Market Data Type of this data - does it come in individual price packets or is it grouped into OHLC.
time
time: datetime
Current time marker of this data packet.
value
value: float
Value representation of this data packet. All data requires a representative value for this moment in time. For streams of data this is the price now, for OHLC packets this is the closing price.
price
price: float
As this is a backtesting platform we'll provide an alias of value as price.
ALL_RESOLUTIONS
ALL_RESOLUTIONS: List[Resolution] = ...
A list of all Resolution
This Field is protected.
DAILY_RESOLUTION
DAILY_RESOLUTION: List[Resolution] = ...
A list of Resolution.DAILY
This Field is protected.
MINUTE_RESOLUTION
MINUTE_RESOLUTION: List[Resolution] = ...
A list of Resolution.MINUTE
This Field is protected.
HIGH_RESOLUTION
HIGH_RESOLUTION: List[Resolution] = ...
A list of high Resolution, including minute, second, and tick.
This Field is protected.
OPTION_RESOLUTIONS
OPTION_RESOLUTIONS: List[Resolution] = ...
A list of resolutions support by Options
This Field is protected.
is_fill_forward
is_fill_forward: bool
True if this is a fill forward piece of data
__getitem__
__getitem__(factor_name: str) -> float
Gets the value of the given factor, e.g. factors
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the factor |
required |
contains_key
contains_key(factor_name: str) -> bool
Checks whether this data point carries a value for the given factor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the factor |
required |
data_time_zone
data_time_zone() -> Any
Specifies the data time zone for this data type. All factor timestamps are New York time.
Returns:
| Type | Description |
|---|---|
Any
|
The NodaTime.DateTimeZone of this data type. |
default_resolution
default_resolution() -> Resolution
Gets the default resolution for this data and security type
get_source
get_source(
config: SubscriptionDataConfig,
date: datetime,
is_live_mode: bool,
) -> SubscriptionDataSource
Return the URL string source of the file. This will be converted to a stream
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SubscriptionDataConfig
|
Configuration object |
required |
date
|
datetime
|
Date of this source file |
required |
is_live_mode
|
bool
|
true if we're in live mode, false for backtesting mode |
required |
Returns:
| Type | Description |
|---|---|
SubscriptionDataSource
|
String URL of source file. |
has_position
has_position(factor_name: str) -> bool
Checks whether this data point carries the given factor's position
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the factor |
required |
hedge_ratio
hedge_ratio(factor_name: str) -> float
Gets a pairs factor's hedge ratio on a pair row: the dollars of b held against each dollar of a
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the pairs factor |
required |
is_sparse_data
is_sparse_data() -> bool
Indicates whether the data is sparse. If true, we disable logging for missing files
Returns:
| Type | Description |
|---|---|
bool
|
true. |
position
position(factor_name: str) -> float
Gets the given factor's position, held from the first open after the data point's time: 1 is long, -1 is short and 0 is none
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the factor |
required |
reader
reader(
config: SubscriptionDataConfig,
line: str,
date: datetime,
is_live_mode: bool,
) -> BaseData
Parses the data from the line provided and loads it into LEAN. CSV format: a header line naming the columns, then a "yyyyMMdd HH:mm" time and a column per factor on each line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SubscriptionDataConfig
|
Subscription configuration |
required |
line
|
str
|
Line of data |
required |
date
|
datetime
|
Date |
required |
is_live_mode
|
bool
|
Is live mode |
required |
Returns:
| Type | Description |
|---|---|
BaseData
|
New instance, or null for the header line. |
requires_mapping
requires_mapping() -> bool
Indicates whether the data source is tied to an underlying symbol and requires that corporate events be applied to it as well, such as renames and delistings
Returns:
| Type | Description |
|---|---|
bool
|
true for a security's subscription, false for the unlinked one. |
supported_resolutions
supported_resolutions() -> List[Resolution]
Gets the supported resolution for this data and security type
to_string
to_string() -> str
Converts the instance to string
try_get_value
try_get_value(
factor_name: str, value: Optional[float]
) -> Tuple[bool, float]
Gets the value of the given factor if this data point carries one
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_name
|
str
|
Name of the factor |
required |
value
|
Optional[float]
|
The factor's value |
required |
protobuf_serialize
protobuf_serialize(guid: Guid) -> List[int]
protobuf_serialize(stream: Stream) -> None
Serialize a base data instance using protobuf
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guid
|
Optional[Guid]
|
Unique guid |
None
|
stream
|
Optional[Stream]
|
The destination stream |
None
|
Returns:
| Type | Description |
|---|---|
Optional[List[int]]
|
The resulting byte array. |
clone
clone() -> BaseData
Return a new instance clone of this object, used in fill forward
Returns:
| Type | Description |
|---|---|
BaseData
|
A clone of the current object. |
deserialize_message
deserialize_message(serialized: str) -> Sequence[BaseData]
Deserialize the message from the data server
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serialized
|
str
|
The data server's message |
required |
Returns:
| Type | Description |
|---|---|
Sequence[BaseData]
|
An enumerable of base data, if unsuccessful, returns an empty enumerable. |
get_update_price_scale_frontier
get_update_price_scale_frontier() -> datetime
Helper method to determine if price scales need an update based on the given data point
normalize
normalize(
factor: float,
normalization_mode: DataNormalizationMode,
sum_of_dividends: float,
) -> BaseData
Normalize prices based on configuration
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
float
|
Price scale |
required |
normalization_mode
|
DataNormalizationMode
|
The price scaling normalization mode |
required |
sum_of_dividends
|
float
|
The current dividend sum |
required |
Returns:
| Type | Description |
|---|---|
BaseData
|
The provided data point adjusted. |
scale
scale(
factor_func: Callable[[float, float, float], float],
volume_factor: float,
factor: float,
sum_of_dividends: float,
) -> BaseData
Scale data based on factor function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor_func
|
Callable[[float, float, float], float]
|
Function to factor prices by |
required |
volume_factor
|
float
|
Factor to multiply volume/askSize/bidSize/quantity by |
required |
factor
|
float
|
Price scale |
required |
sum_of_dividends
|
float
|
The current dividend sum |
required |
should_cache_to_security
should_cache_to_security() -> bool
Indicates whether this contains data that should be stored in the security cache
Returns:
| Type | Description |
|---|---|
bool
|
Whether this contains data that should be stored in the security cache. |
update
update(
last_trade: float,
bid_price: float,
ask_price: float,
volume: float,
bid_size: float,
ask_size: float,
) -> None
Update routine to build a bar/tick from a data update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_trade
|
float
|
The last trade price |
required |
bid_price
|
float
|
Current bid price |
required |
ask_price
|
float
|
Current asking price |
required |
volume
|
float
|
Volume of this trade |
required |
bid_size
|
float
|
The size of the current bid, if available |
required |
ask_size
|
float
|
The size of the current ask, if available |
required |
update_ask
update_ask(ask_price: float, ask_size: float) -> None
Updates this base data with the new quote ask information
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ask_price
|
float
|
The current ask price |
required |
ask_size
|
float
|
The current ask size |
required |
update_bid
update_bid(bid_price: float, bid_size: float) -> None
Updates this base data with the new quote bid information
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bid_price
|
float
|
The current bid price |
required |
bid_size
|
float
|
The current bid size |
required |
update_quote
update_quote(
bid_price: float,
bid_size: float,
ask_price: float,
ask_size: float,
) -> None
Updates this base data with new quote information
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bid_price
|
float
|
The current bid price |
required |
bid_size
|
float
|
The current bid size |
required |
ask_price
|
float
|
The current ask price |
required |
ask_size
|
float
|
The current ask size |
required |
update_trade
update_trade(last_trade: float, trade_size: float) -> None
Updates this base data with a new trade
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_trade
|
float
|
The price of the last trade |
required |
trade_size
|
float
|
The quantity traded |
required |
get_meta_object
get_meta_object(parameter: Any) -> Any
Get the metaObject required for Dynamism.
get_property
get_property(name: str) -> Object
Gets the property's value with the specified name. This is a case-insensitive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The property name to access |
required |
Returns:
| Type | Description |
|---|---|
Object
|
object value of BaseData. |
get_storage_dictionary
get_storage_dictionary() -> IDictionary[str, Object]
Gets the storage dictionary Python algorithms need this information since DynamicMetaObject does not work
Returns:
| Type | Description |
|---|---|
IDictionary[str, Object]
|
Dictionary that stores the parameters names and values. |
has_property
has_property(name: str) -> bool
Gets whether or not this dynamic data instance has a property with the specified name. This is a case-insensitive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The property name to check for |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the property exists, false otherwise. |
set_property
set_property(name: str, value: Any) -> Object
Sets the property with the specified name to the value. This is a case-insensitive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The property name to set |
required |
value
|
Any
|
The new property value |
required |
Returns:
| Type | Description |
|---|---|
Object
|
Returns the input value back to the caller. |