CITE THIS NOTEBOOK: Equity analysis: Entity Store by Jonathan Kinlay. Wolfram Community NOV 8 2022.

Entity Stores

Somewhat incongruously for a functional programming language, WL incorporates a powerful object-oriented concept known as the Entity Store
◼
  • Details: https://reference.wolfram.com/language/ref/EntityStore.html
  • ◼
  • An Entity Store appears at first to be only a partial implementation of the OO idea:
  • ◼
  • Entities have properties
  • ◼
  • No methods
  • ◼
  • However, Entity Store “properties” can be functions, i.e. “methods”
  • Equities Entity Store

    ◼
  • Includes over 1,000 equity entities
  • ◼
  • Stocks and stock indices
  • ◼
  • Fundamental, technical and historical data
  • ◼
  • Ideal for cross-sectional analysis
  • ◼
  • Applications:
  • ◼
  • Portfolio construction
  • ◼
  • Statistical Arbitrage
  • Installation

    Get[StringJoin[dirEntityStore,"EquitiesEntityStore.mx"]];
    Typically you would register the store on all kernels, to enable parallelization:
    In[]:=
    task=Quiet@Table[ParallelSubmit[{i},{EntityUnregister[EquitiesEntityStore],$KernelID}],{i,Length@Kernels[]}];​​WaitAll[task];​​task=Table[ParallelSubmit[{i},{EntityRegister[EquitiesEntityStore],$KernelID}],{i,Length@Kernels[]}];​​WaitAll[task]
    {{{"Equities"},1},{{"Equities"},2},{{"Equities"},3},{{"Equities"},4}}

    Equity Store Properties

    In[]:=
    EntityList["Equities"]//Length
    Out[]=
    1005

    Equity Indices

    In[]:=
    EntityList[EntityClass["Equities","Stock Indices"]]
    Out[]=
    
    SP500
    

    Stocks

    Select a sample of individual equity entities:
    In[]:=
    selectedStocks=
    APA
    EQUITIES
    ,
    CTSH
    EQUITIES
    ,
    CZR
    EQUITIES
    ,
    DD
    EQUITIES
    ,
    FIVN
    EQUITIES
    ,
    HUBS
    EQUITIES
    ,
    MPC
    EQUITIES
    ,
    PRU
    EQUITIES
    ,
    UMPQ
    EQUITIES
    ,
    WMT
    EQUITIES
    ;

    Select Index Components

    Often we want to define a universe of stocks for analysis that correspond to common index memberships, for example:
    In[]:=
    SelectIndexComponents[selectedStocks,"DOW30"]
    Out[]=
    
    WMT
    
    In[]:=
    SelectIndexComponents[selectedStocks,"SP500"]
    Out[]=
    
    APA
    ,
    CTSH
    ,
    CZR
    ,
    DD
    ,
    MPC
    ,
    PRU
    ,
    WMT
    

    Select by Start Date

    When performing time series cross-sectional analysis we typically want to select subsets of stocks that were extant on or before specified dates:
    In[]:=
    EntityStartDate[#]&/@selectedStocks
    Out[]=
    
    Tue 2 Jan 1990
    ,
    Fri 19 Jun 1998
    ,
    Mon 22 Sep 2014
    ,
    Fri 1 Sep 2017
    ,
    Fri 4 Apr 2014
    ,
    Thu 9 Oct 2014
    ,
    Thu 23 Jun 2011
    ,
    Thu 13 Dec 2001
    ,
    Wed 18 Dec 1996
    ,
    Tue 2 Jan 1990
    
    This is easy to accomplish in the WL operating on the Entity Store:
    In[]:=
    SelectEntitiesStartDateBefore[selectedStocks,{2001,1,1}]
    Out[]=
    
    APA
    ,
    CTSH
    ,
    UMPQ
    ,
    WMT
    

    Equity Properties

    Each entity in the Equities Entity Store contains the following properties:
    In[]:=
    WMT
    EQUITIES
    ["Properties"]
    Out[]=
    
    Company Information
    ,
    Fundamentals
    ,
    Historical Data
    ,
    Index Memberships
    ,
    Performance
    ,
    Price-Volume
    

    Company Information

    We can use the company information to group equities by sector:
    In[]:=
    WMT
    EQUITIES
    ["Company Information"]
    Out[]=
    SymbolNYSE:WMT,ExchangeNYSE,Start Date
    Tue 2 Jan 1990 00:00:00GMT-5
    ,Company
    Walmart
    ,SectorDiscountStores,SICCode5331

    Fundamental Information

    The fundamental information property gives a limited snapshot of current fundamental data for the stock:
    In[]:=
    WMT
    EQUITIES
    ["Fundamentals"]
    Out[]=
    MarketCap3.8642×
    11
    10
    ,PERatio28.14,EarningsPerShare5.0096,EBITDA35286000000
    However, a much more complete dataset of fundamental information is available, as properties of the Company entity:
    In[]:=
    WMT
    EQUITIES
    ["Company Information"]["Company"]["Properties"]//Short
    Out[]//Short=
    
    accounts payable
    ,
    accounts receivable
    ,
    accumulated depreciation
    ,
    additional paid in capital
    ,
    address
    ,
    amortization
    ,
    assets turnover
    ,
    beginning cash position
    ,
    capital expenditures
    ,
    cash
    ,
    cash and cash equivalents
    ,
    cash dividends paid
    ,
    cash equivalents
    ,
    cash flow from continuing financing activities
    ,
    cash flow from continuing investing activities
    ,
    cash flow from continuing operating activities
    ,
    cash flow from discontinued operation
    ,
    cash from discontinued financing activities
    ,
    cash from discontinued investing activities
    ,
    change in accrued expense
    ,
    change in interest payable
    ,
    change in inventory
    ,
    change in payable
    ,
    change in tax payable
    ,
    change in working capital
    ,
    change in cash and cash equivalents
    ,
    change in receivables
    ,
    city
    ,
    common shares
    ,
    common stock
    ,
    common stock issuance
    ,
    common stock payments
    ,
    coordinates
    ,
    corporate structure
    ,
    cost of revenue
    ,
    current accrued expenses
    ,
    current assets
    ,
    current debt
    ,
    current liabilities
    ,
    current notes payable
    ,
    current ratio
    ,
    deferred assets
    ,
    deferred costs
    ,
    deferred tax assets
    ,
    defunct date
    ,
    depreciation
    ,
    depreciation amortization depletion
    ,
    depreciation and amortization
    ,
    earnings before interest and tax
    ,
    earnings before interest tax depreciation and amortization
    ,
    total employees
    ,
    end cash position
    ,
    entity classes
    ,
    equity investments
    ,
    financial health grade
    ,
    financial leverage
    ,71,
    position
    ,
    postal code
    ,
    predecessor companies
    ,
    preferred stock
    ,
    preferred stock dividends
    ,
    preferred stock issuance
    ,
    preferred stock payments
    ,
    pre-tax income
    ,
    profitability grade
    ,
    purchase of business
    ,
    purchase of equity securities
    ,
    purchase of fixed maturity securities
    ,
    purchase of intangibles
    ,
    purchase of investment
    ,
    purchase of long-term investments
    ,
    purchase of properties plants and equipments
    ,
    purchase of short-term investments
    ,
    purchase of technology
    ,
    research and development
    ,
    retained earnings
    ,
    revenue growth
    ,
    revenue per employee
    ,
    return on assets
    ,
    return on equity
    ,
    sales of business
    ,
    sale of intangibles
    ,
    sales of investment
    ,
    sale of long-term investments
    ,
    sales of properties plants and equipments
    ,
    sales of short-term investments
    ,
    sales of equity securities
    ,
    sales of fixed maturity securities
    ,
    selling and marking expense
    ,
    selling general and administration
    ,
    short-term debt issuance
    ,
    short-term debt payments
    ,
    status
    ,
    stockholders equity
    ,
    successor companies
    ,
    tax provision
    ,
    total assets
    ,
    total debt
    ,
    total deposits
    ,
    total expenses
    ,
    total investments
    ,
    total liabilities
    ,
    total non-current assets
    ,
    total non-current liabilities
    ,
    total revenue
    ,
    total tax payable
    ,
    trading liabilities
    ,
    trading securities
    ,
    treasury stock
    ,
    unearned income
    ,
    website
    ,
    working capital
    

    Index Memberships

    In[]:=
    WMT
    EQUITIES
    ["Index Memberships"]
    Out[]=
    DOW30True,SP500True,Russell 1000True

    Price-Volume Information

    In[]:=
    WMT
    EQUITIES
    ["Price-Volume"]//Dataset
    Out[]=
    Volume
    4889768
    AverageVolume3Month
    7171903.
    AdjustedClose
    140.97
    High52Week
    160.77
    Low52Week
    117.27
    Average200Day
    136.235
    Average50Day
    134.658
    FractionalChange200Day
    3.4758
    FractionalChange50Day
    4.68712
    Volatility250Day
    26.6432
    Volatility50Day
    19.7909
    Volatility20Day
    17.6923

    Historical Data

    Historical data associated with each entity includes daily/monthly price and returns series from Jan 2, 1990 (or the start date of the series, if later).
    We can access historical data immediately for analysis, without requiring any data downloading or database retrieval:
    Of course, it is also easy to perform a combined analysis for equity entities in the WL, for instance:
    We can construct trading charts using the historical price series:

    Performance Data

    The information we have considered so far can be retrieved using the FinancialData function, albeit that it is presented in a much more convenient and rapidly accessible form in the Equities Entity Store.
    However, the Performance property of equity entities contains a substantial amount of pre-computed information that is not directly available from Wolfram:
    Most of the data items are self explanatory, but some require others elucidation:
    ◼
  • Autocorrelation refers to the autocorrelation in 1-month, 3-month,... etc, returns. The autocorrelation from inception is the autocorrelation in daily returns, from the start of the data series.
  • ◼
  • The IR is the information ratio, defined here as the ratio of the CAGR to the annualized volatility, estimated for the last 1-month, 3-month,... etc period.
  • ◼
  • The Alpha and Beta are the CAPM regression estimates obtained by regressing the (excess) daily returns in the stock against those of the index, for the corresponding 1-month, 3-month,.. etc period.
  • ◼
  • μ and σ are the annualized, instantaneous drift and volatility parameters for a Geometric Brownian Motion process estimated using daily closing prices over the last 1-month, 3-month, .. etc period.
  • Cross-Sectional Analysis

    Fundamental Information Dataset

    Cross-Sectional Performance Dataset

    We might want to carry out a comparative analysis, looking at performance over, say, the last nine months:

    Correlation Plots (with outlier detection)

    In this example we are looking at correlation plots for pairs of equities, using WL’s Anomaly Detection functionality to remove outliers from the data:

    Historical Performance Data

    While the snapshot performance information contained in the Performance property of each equity entity is interesting, much more useful is the historical performance data contained in the Historical Data property:
    Why is this useful?
    ​
    In cross-sectional strategy design we typically look at performance metics for a universe of stocks at the end of each month, using these to decide which stocks to go long and which to short for the next month.
    ​
    The Historical Performance Data contained in the Equities Entity Store provides exactly the information we would need to construct such long/short equity portfolios.
    ​
    We will discuss this application in Part 2 of the presentation.