{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "wrds_sp500_1.ipynb", "provenance": [], "collapsed_sections": [], "authorship_tag": "ABX9TyNkYy+6D/IpfNp0R4T4FSwc", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "BK41lkVxd9-K" }, "outputs": [], "source": [ "" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "y2C0OgijlDzv", "outputId": "31538ae4-da6c-4973-c94e-cfe5e84b8cdb" }, "source": [ "!pip install wrds" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", "Collecting wrds\n", " Downloading wrds-3.1.1-py3-none-any.whl (12 kB)\n", "Collecting mock\n", " Downloading mock-4.0.3-py3-none-any.whl (28 kB)\n", "Requirement already satisfied: sqlalchemy in /usr/local/lib/python3.7/dist-packages (from wrds) (1.4.37)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from wrds) (1.21.6)\n", "Collecting psycopg2-binary\n", " Downloading psycopg2_binary-2.9.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)\n", "\u001b[K |████████████████████████████████| 3.0 MB 8.6 MB/s \n", "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from wrds) (1.3.5)\n", "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->wrds) (2022.1)\n", "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->wrds) (2.8.2)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->wrds) (1.15.0)\n", "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from sqlalchemy->wrds) (4.11.4)\n", "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.7/dist-packages (from sqlalchemy->wrds) (1.1.2)\n", "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->sqlalchemy->wrds) (3.8.0)\n", "Requirement already satisfied: typing-extensions>=3.6.4 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->sqlalchemy->wrds) (4.1.1)\n", "Installing collected packages: psycopg2-binary, mock, wrds\n", "Successfully installed mock-4.0.3 psycopg2-binary-2.9.3 wrds-3.1.1\n" ] } ] }, { "cell_type": "code", "metadata": { "id": "TlUrRmTnlFD_" }, "source": [ "import wrds" ], "execution_count": 2, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "Kfij7381Oe4W" }, "source": [ "# Now I am connecting to WRDS site - you must ahve a WRDS account user id and password\n", "conn=wrds.Connection()" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "collapsed": true, "id": "zgpZF6Vo11y5" }, "source": [ "import pandas as pd \n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "plt.style.use('fivethirtyeight')\n", "\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'retina'" ], "execution_count": 4, "outputs": [] }, { "cell_type": "code", "source": [ "help(wrds)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "eneGwr9g3tDo", "outputId": "b7e4f31e-b675-430d-8c33-6b82b43d3d22" }, "execution_count": 5, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Help on package wrds:\n", "\n", "NAME\n", " wrds\n", "\n", "DESCRIPTION\n", " WRDS Python Data Access Library\n", " ==============================\n", " \n", " WRDS-Py is a library for extracting data from WRDS data sources and getting it into Pandas.\n", " \n", " >>> import wrds\n", " >>> db = wrds.Connection()\n", " >>> db.list_libraries()\n", " ['aha', 'aha_sample', 'ahasamp', 'audit', 'audit_audit_comp', ...]\n", " >>> db.list_tables(library='crsp')\n", " ['acti', 'asia', 'asib', 'asic', 'asio', 'asix', 'bmdebt', 'bmheader', ...]\n", " >>> data = db.raw_sql('SELECT * FROM crsp.stocknames', index_col='permno')\n", " >>> data.head()\n", " permco namedt nameenddt cusip ncusip ticker permno\n", " 10000.0 7952.0 1986-01-07 1987-06-11 68391610 68391610 OMFGA\n", " 10001.0 7953.0 1986-01-09 1993-11-21 36720410 39040610 GFGC\n", " 10001.0 7953.0 1993-11-22 2008-02-04 36720410 29274A10 EWST\n", " 10001.0 7953.0 2008-02-05 2009-08-03 36720410 29274A20 EWST\n", " 10001.0 7953.0 2009-08-04 2009-12-17 36720410 29269V10 EGAS\n", " ...\n", "\n", "PACKAGE CONTENTS\n", " sql\n", " test\n", "\n", "DATA\n", " __copyright__ = '2017-2021 Wharton Research Data Services'\n", " __title__ = 'wrds-py'\n", "\n", "VERSION\n", " 3.1.1\n", "\n", "AUTHOR\n", " Wharton Research Data Services\n", "\n", "FILE\n", " /usr/local/lib/python3.7/dist-packages/wrds/__init__.py\n", "\n", "\n" ] } ] }, { "cell_type": "code", "source": [ "#listing all dtabases or libraries in WRDS\n", "conn.list_libraries()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "pf-sgx9YwW3W", "outputId": "caf994c4-d58f-46da-8852-108995a059f0" }, "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['compbd',\n", " 'compgd',\n", " 'compnad',\n", " 'compsegd',\n", " 'crspa',\n", " 'evts',\n", " 'issm',\n", " 'nastraq',\n", " 'tass',\n", " 'wrds_lib_internal',\n", " 'aha',\n", " 'estimize',\n", " 'levin',\n", " 'ciqsamp_capstrct',\n", " 'toyo',\n", " 'ahasamp',\n", " 'ciqsamp_pplintel',\n", " 'crspm',\n", " 'tresgsmp',\n", " 'trsdcgs',\n", " 'columnar',\n", " 'trws',\n", " 'lspd',\n", " 'twoiq',\n", " 'wcai',\n", " 'tresg',\n", " 'wind',\n", " 'wqa',\n", " 'msrb_all',\n", " 'custom_jl',\n", " 'risk',\n", " 'centris',\n", " 'wrdsapps_link_supplychain',\n", " 'block_all',\n", " 'zacks',\n", " 'crsp',\n", " 'contrib',\n", " 'audit',\n", " 'boardex_trial',\n", " 'emdb',\n", " 'calcbnch',\n", " 'comp_na_monthly_all',\n", " 'auditsmp',\n", " 'boardsmp',\n", " 'comp_segments_hist',\n", " 'wrdsrpts_rep_usage',\n", " 'public_all',\n", " 'pwt_all',\n", " 'msfanly',\n", " 'etfg',\n", " 'snlsamp_fig',\n", " 'wrdsapps_backtest_plus',\n", " 'pacap',\n", " 'ciqsamp_transcripts',\n", " 'ciq',\n", " 'tr_ds',\n", " 'ppublica',\n", " 'crsp_a_stock',\n", " 'preqin',\n", " 'etfg_samp',\n", " 'fisdsamp',\n", " 'windsmp',\n", " 'rent',\n", " 'sustainalyticssamp_all',\n", " 'wrdsapps_evtstudy_int_ginsight',\n", " 'compmcur',\n", " 'tr_dealscan',\n", " 'markit',\n", " 'secsamp_all',\n", " 'rpna',\n", " 'ibes',\n", " 'rpa',\n", " 'sdcsamp',\n", " 'wrdssec_midas',\n", " 'cisdmsmp',\n", " 'cboe_all',\n", " 'snl',\n", " 'cboe',\n", " 'sprat',\n", " 'ciqsamp',\n", " 'fjc_litigation',\n", " 'trucost',\n", " 'sustain',\n", " 'trdssamp',\n", " 'risksamp',\n", " 'midas',\n", " 'snlsamp',\n", " 'public',\n", " 'pwt',\n", " 'repsamp',\n", " 'snapsamp',\n", " 'taqsamp',\n", " 'totalq',\n", " 'optionm',\n", " 'comp_execucomp',\n", " 'fjc_linking',\n", " 'compa',\n", " 'bank',\n", " 'blab',\n", " 'compb',\n", " 'compg',\n", " 'block',\n", " 'taqmsec',\n", " 'trsamp_ds_eq',\n", " 'contrib_ceo_turnover',\n", " 'cisdm',\n", " 'clrvt',\n", " 'clrvtsmp',\n", " 'compm',\n", " 'compseg',\n", " 'compsamp',\n", " 'comph',\n", " 'compsnap',\n", " 'comscore',\n", " 'pitchbk',\n", " 'crspsamp',\n", " 'dmef',\n", " 'eursamp',\n", " 'contrib_kpss',\n", " 'auditsmp_all',\n", " 'crspq',\n", " 'execcomp',\n", " 'taqmsamp_all',\n", " 'ff',\n", " 'ftse',\n", " 'cusipm',\n", " 'boardex',\n", " 'eureka',\n", " 'eventus',\n", " 'ftsesamp',\n", " 'ginsight',\n", " 'ktsamp',\n", " 'factset',\n", " 'ifgrsamp',\n", " 'imssamp',\n", " 'gmi',\n", " 'fssamp',\n", " 'govpxsmp',\n", " 'hbsamp',\n", " 'hbase',\n", " 'hfr',\n", " 'ibescorp',\n", " 'mrktsamp_msf',\n", " 'iri',\n", " 'govpx',\n", " 'kld',\n", " 'ifgr',\n", " 'ibeskpi',\n", " 'fisd',\n", " 'lspdsamp',\n", " 'ims',\n", " 'ktmine',\n", " 'taq',\n", " 'aha_sample',\n", " 'compdcur',\n", " 'calcbench_trial',\n", " 'ciqsamp_common',\n", " 'ppubsamp_d4d',\n", " 'mrktsamp',\n", " 'otc',\n", " 'msrbsamp',\n", " 'contrib_general',\n", " 'preqsamp_all',\n", " 'twoiq_samp',\n", " 'msrb',\n", " 'mrktsamp_cdx',\n", " 'phlx_all',\n", " 'zacksamp_all',\n", " 'mfl',\n", " 'sustsamp',\n", " 'etfgsamp',\n", " 'phlx',\n", " 'ppubsamp',\n", " 'preqsamp',\n", " 'ciqsamp_keydev',\n", " 'tfn',\n", " 'toyosamp',\n", " 'wappsamp',\n", " 'wrdsapps_evtstudy_lr',\n", " 'crsp_a_ccm',\n", " 'zacksamp',\n", " 'revere',\n", " 'eurekahedge_sample',\n", " 'comp_na_daily_all',\n", " 'ims_obp_trial',\n", " 'wrdsrpts',\n", " 'compsamp_snapshot',\n", " 'comp_na_annual_all',\n", " 'rq_all',\n", " 'infogroupsamp_business',\n", " 'infogroupsamp_residential',\n", " 'ktmine_patents_samp',\n", " 'djones_all',\n", " 'doe_all',\n", " 'factsamp_all',\n", " 'toyosamp_all',\n", " 'wrdsapps_eushort',\n", " 'wrdsapps_subsidiary',\n", " 'wrdsappssamp_all',\n", " 'wrdsapps_link_datastream_wscope',\n", " 'wrdsapps_patents',\n", " 'dmef_all',\n", " 'macrofin_comm_trade',\n", " 'mrktsamp_cds',\n", " 'pitchsmp',\n", " 'wrdsapps_link_comp_eushort',\n", " 'totalq_all',\n", " 'trsamp_dscom',\n", " 'trsamp_dsecon',\n", " 'wrdsapps_finratio',\n", " 'reprisk',\n", " 'comp',\n", " 'trcstsmp',\n", " 'rpnasamp',\n", " 'audit_corp_legal',\n", " 'csmar',\n", " 'trsamp_dsfut',\n", " 'wrdsapps_backtest_basic',\n", " 'wrdsapps_link_crsp_bond',\n", " 'ff_all',\n", " 'wrdsapps_link_crsp_taq',\n", " 'contrib_intangible_value',\n", " 'wrdssec',\n", " 'wrdsapps',\n", " 'audit_common',\n", " 'contrib_char_returns',\n", " 'crsp_q_indexhist',\n", " 'bvd',\n", " 'secsamp',\n", " 'factsamp_revere',\n", " 'frb_all',\n", " 'hbase_sample',\n", " 'hfrsamp_hfrdb',\n", " 'trown',\n", " 'lvnsamp_all',\n", " 'risksamp_all',\n", " 'optionmsamp_europe',\n", " 'optionmsamp_us',\n", " 'reprisk_sample',\n", " 'wrdsapps_finratio_ccm',\n", " 'trace_standard',\n", " 'trdstrm',\n", " 'trace_enhanced',\n", " 'fjc',\n", " 'lvnsamp',\n", " 'omtrial',\n", " 'trace',\n", " 'bvdsamp',\n", " 'djones',\n", " 'doe',\n", " 'frb',\n", " 'hfrsamp',\n", " 'macrofin',\n", " 'comp_bank',\n", " 'trsamp',\n", " 'wrdsapps_link_crsp_factset',\n", " 'twoiqsmp',\n", " 'comp_bank_daily',\n", " 'audit_audit_comp',\n", " 'comp_segments_hist_daily',\n", " 'otc_endofday',\n", " 'dealscan',\n", " 'ravenpack_trial',\n", " 'msfinst',\n", " 'crsp_a_indexes',\n", " 'taqmsamp',\n", " 'iss',\n", " 'sdc']" ] }, "metadata": {}, "execution_count": 6 } ] }, { "cell_type": "code", "source": [ "conn.list_tables(library='comp')" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dM7RPF23ZUJg", "outputId": "0ab1ee06-c513-4f5a-fc89-7d882ce1ba35" }, "execution_count": 7, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['aco_amda',\n", " 'aco_imda',\n", " 'aco_indfnta',\n", " 'aco_indfntq',\n", " 'aco_indfntytd',\n", " 'aco_indsta',\n", " 'aco_indstq',\n", " 'aco_indstytd',\n", " 'aco_notesa',\n", " 'aco_notesq',\n", " 'aco_notessa',\n", " 'aco_notesytd',\n", " 'aco_pnfnda',\n", " 'aco_pnfndq',\n", " 'aco_pnfndytd',\n", " 'aco_pnfnta',\n", " 'aco_pnfntq',\n", " 'aco_pnfntytd',\n", " 'aco_transa',\n", " 'aco_transq',\n", " 'aco_transsa',\n", " 'aco_transytd',\n", " 'adsprate',\n", " 'asec_amda',\n", " 'asec_imda',\n", " 'asec_notesa',\n", " 'asec_notesq',\n", " 'asec_transa',\n", " 'asec_transq',\n", " 'bank_aacctchg',\n", " 'bank_adesind',\n", " 'bank_afnd1',\n", " 'bank_afnd2',\n", " 'bank_afnddc1',\n", " 'bank_afnddc2',\n", " 'bank_afntind',\n", " 'bank_funda',\n", " 'bank_funda_fncd',\n", " 'bank_fundq',\n", " 'bank_fundq_fncd',\n", " 'bank_iacctchg',\n", " 'bank_idesind',\n", " 'bank_ifndq',\n", " 'bank_ifndytd',\n", " 'bank_ifntq',\n", " 'bank_ifntytd',\n", " 'bank_names',\n", " 'bank_namesq',\n", " 'chars',\n", " 'co_aacctchg',\n", " 'co_aaudit',\n", " 'co_adesind',\n", " 'co_adjfact',\n", " 'co_afnd1',\n", " 'co_afnd2',\n", " 'co_afnddc1',\n", " 'co_afnddc2',\n", " 'co_afntind1',\n", " 'co_afntind2',\n", " 'co_ainvval',\n", " 'co_amkt',\n", " 'co_busdescl',\n", " 'co_cotype',\n", " 'co_filedate',\n", " 'co_fortune',\n", " 'co_hgic',\n", " 'co_iacctchg',\n", " 'co_iaudit',\n", " 'co_idesind',\n", " 'co_ifndq',\n", " 'co_ifndsa',\n", " 'co_ifndytd',\n", " 'co_ifntq',\n", " 'co_ifntsa',\n", " 'co_ifntytd',\n", " 'co_imkt',\n", " 'co_industry',\n", " 'co_ipcd',\n", " 'co_mthly',\n", " 'co_offtitl',\n", " 'company',\n", " 'currency',\n", " 'dd_group',\n", " 'dd_group_xref',\n", " 'dd_item',\n", " 'dd_package',\n", " 'ecind_desc',\n", " 'ecind_mth',\n", " 'exrt_dly',\n", " 'exrt_mth',\n", " 'filings',\n", " 'funda',\n", " 'funda_fncd',\n", " 'fundq',\n", " 'fundq_fncd',\n", " 'g_chars',\n", " 'g_co_aaudit',\n", " 'g_co_adesind',\n", " 'g_co_afnd1',\n", " 'g_co_afnd2',\n", " 'g_co_afnddc1',\n", " 'g_co_afnddc2',\n", " 'g_co_afntind1',\n", " 'g_co_afntind2',\n", " 'g_co_ainvval',\n", " 'g_co_gsuppl',\n", " 'g_co_hgic',\n", " 'g_co_iaudit',\n", " 'g_co_idesind',\n", " 'g_co_ifndq',\n", " 'g_co_ifndsa',\n", " 'g_co_ifndytd',\n", " 'g_co_ifntq',\n", " 'g_co_ifntsa',\n", " 'g_co_ifntytd',\n", " 'g_co_industry',\n", " 'g_co_ipcd',\n", " 'g_co_offtitl',\n", " 'g_company',\n", " 'g_currency',\n", " 'g_ecind_desc',\n", " 'g_ecind_mth',\n", " 'g_exrt_dly',\n", " 'g_exrt_mth',\n", " 'g_funda',\n", " 'g_funda_fncd',\n", " 'g_fundq',\n", " 'g_fundq_fncd',\n", " 'g_idx_daily',\n", " 'g_idx_index',\n", " 'g_idx_mth',\n", " 'g_idxcst_his',\n", " 'g_names',\n", " 'g_names_ix',\n", " 'g_names_ix_cst',\n", " 'g_namesq',\n", " 'g_sec_adesind',\n", " 'g_sec_adjfact',\n", " 'g_sec_afnd',\n", " 'g_sec_afnddc',\n", " 'g_sec_afnt',\n", " 'g_sec_divid',\n", " 'g_sec_dprc',\n", " 'g_sec_dtrt',\n", " 'g_sec_history',\n", " 'g_sec_idesind',\n", " 'g_sec_ifnd',\n", " 'g_sec_ifnt',\n", " 'g_sec_split',\n", " 'g_secd',\n", " 'g_secnamesd',\n", " 'g_security',\n", " 'g_sedolgvkey',\n", " 'g_tmptable_pkg6153_tbl4023',\n", " 'idx_ann',\n", " 'idx_anndes',\n", " 'idx_daily',\n", " 'idx_index',\n", " 'idx_mth',\n", " 'idx_qrt',\n", " 'idx_qrtdes',\n", " 'idxcst_his',\n", " 'io_qaggregate',\n", " 'io_qbuysell',\n", " 'io_qchanges',\n", " 'io_qfloatadj',\n", " 'io_qholders',\n", " 'it_mbuysell',\n", " 'it_msummary',\n", " 'it_r_rltn',\n", " 'names',\n", " 'names_aco_indsta',\n", " 'names_aco_indstq',\n", " 'names_aco_pnfnda',\n", " 'names_aco_pnfndq',\n", " 'names_adsprate',\n", " 'names_ix',\n", " 'names_ix_cst',\n", " 'names_seg',\n", " 'namesd',\n", " 'namesm',\n", " 'namesq',\n", " 'r_accstd',\n", " 'r_acqmeth',\n", " 'r_auditors',\n", " 'r_auopic',\n", " 'r_balpres',\n", " 'r_cf_formt',\n", " 'r_co_status',\n", " 'r_coindpre',\n", " 'r_compstat',\n", " 'r_consol',\n", " 'r_country',\n", " 'r_cstclscd',\n", " 'r_datacode',\n", " 'r_datafmt',\n", " 'r_divtaxmarker',\n", " 'r_docsrce',\n", " 'r_ex_codes',\n", " 'r_exchgtier',\n", " 'r_exrt_typ',\n", " 'r_fndfntcd',\n", " 'r_footnts',\n", " 'r_foricd',\n", " 'r_giccd',\n", " 'r_hcalendr',\n", " 'r_idxclscd',\n", " 'r_inactvcd',\n", " 'r_incstats',\n", " 'r_indfmt',\n", " 'r_indsec',\n", " 'r_invval',\n", " 'r_issuetyp',\n", " 'r_majidxcl',\n", " 'r_mic_codes',\n", " 'r_naiccd',\n", " 'r_notetype',\n", " 'r_ntsubtype',\n", " 'r_offcrso',\n", " 'r_ogmethod',\n", " 'r_opinions',\n", " 'r_prc_stat',\n", " 'r_qsrcdoc',\n", " 'r_sec_stat',\n", " 'r_secannfn',\n", " 'r_sectors',\n", " 'r_siccd',\n", " 'r_spiicd',\n", " 'r_spmicd',\n", " 'r_statalrt',\n", " 'r_states',\n", " 'r_stko',\n", " 'r_titles',\n", " 'r_updates',\n", " 'sec_adesind',\n", " 'sec_adjfact',\n", " 'sec_afnd',\n", " 'sec_afnddc',\n", " 'sec_afnt',\n", " 'sec_divid',\n", " 'sec_dprc',\n", " 'sec_dtrt',\n", " 'sec_history',\n", " 'sec_idesind',\n", " 'sec_ifnd',\n", " 'sec_ifnt',\n", " 'sec_mdivfn',\n", " 'sec_mshare',\n", " 'sec_msptfn',\n", " 'sec_mth',\n", " 'sec_mthdiv',\n", " 'sec_mthprc',\n", " 'sec_mthspt',\n", " 'sec_mthtrt',\n", " 'sec_shortint',\n", " 'sec_spind',\n", " 'sec_split',\n", " 'secd',\n", " 'secm',\n", " 'security',\n", " 'sedolgvkey',\n", " 'seg_ann',\n", " 'seg_annfund',\n", " 'seg_customer',\n", " 'seg_geo',\n", " 'seg_naics',\n", " 'seg_product',\n", " 'seg_type',\n", " 'spidx_cst',\n", " 'spind',\n", " 'spind_dly',\n", " 'spind_mth',\n", " 'tmptable_pkg6153_tbl4023',\n", " 'wrds_seg_customer',\n", " 'wrds_seg_geo',\n", " 'wrds_seg_product',\n", " 'wrds_segmerged',\n", " 'xfl_column',\n", " 'xfl_table']" ] }, "metadata": {}, "execution_count": 7 } ] }, { "cell_type": "markdown", "source": [ "https://www.fredasongdrechsler.com/home" ], "metadata": { "id": "UfM8hjAwe3tk" } }, { "cell_type": "code", "source": [ "sp500 = conn.raw_sql(\"\"\"\n", " select a.*, b.date, b.ret\n", " from crsp.msp500list as a,\n", " crsp.msf as b\n", " where a.permno=b.permno\n", " and b.date >= a.start and b.date<= a.ending\n", " and b.date>='01/01/2000'\n", " order by date;\n", " \"\"\", date_cols=['start', 'ending', 'date'])" ], "metadata": { "id": "0C-0_6lbeTQT" }, "execution_count": 8, "outputs": [] }, { "cell_type": "code", "source": [ "sp500" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 424 }, "id": "v5QyVuSTeTNy", "outputId": "cca941f1-cae2-413a-d954-c2742e2e074a" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " permno start ending date ret\n", "0 40416.0 1967-05-18 2015-03-20 2000-01-31 -0.035985\n", "1 44062.0 1967-06-29 2000-12-11 2000-01-31 -0.089202\n", "2 26403.0 1976-07-01 2022-03-31 2000-01-31 0.241453\n", "3 60628.0 1980-11-06 2022-03-31 2000-01-31 -0.033588\n", "4 69032.0 1995-09-22 2022-03-31 2000-01-31 -0.069002\n", "... ... ... ... ... ...\n", "133917 17478.0 1957-03-01 2022-03-31 2022-03-31 0.091775\n", "133918 91152.0 2016-06-03 2022-03-31 2022-03-31 -0.022578\n", "133919 24985.0 1991-09-20 2022-03-31 2022-03-31 0.097731\n", "133920 29946.0 1982-10-14 2022-03-31 2022-03-31 0.030331\n", "133921 17700.0 2021-09-20 2022-03-31 2022-03-31 -0.062406\n", "\n", "[133922 rows x 5 columns]" ], "text/html": [ "\n", "
\n", " | permno | \n", "start | \n", "ending | \n", "date | \n", "ret | \n", "
---|---|---|---|---|---|
0 | \n", "40416.0 | \n", "1967-05-18 | \n", "2015-03-20 | \n", "2000-01-31 | \n", "-0.035985 | \n", "
1 | \n", "44062.0 | \n", "1967-06-29 | \n", "2000-12-11 | \n", "2000-01-31 | \n", "-0.089202 | \n", "
2 | \n", "26403.0 | \n", "1976-07-01 | \n", "2022-03-31 | \n", "2000-01-31 | \n", "0.241453 | \n", "
3 | \n", "60628.0 | \n", "1980-11-06 | \n", "2022-03-31 | \n", "2000-01-31 | \n", "-0.033588 | \n", "
4 | \n", "69032.0 | \n", "1995-09-22 | \n", "2022-03-31 | \n", "2000-01-31 | \n", "-0.069002 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
133917 | \n", "17478.0 | \n", "1957-03-01 | \n", "2022-03-31 | \n", "2022-03-31 | \n", "0.091775 | \n", "
133918 | \n", "91152.0 | \n", "2016-06-03 | \n", "2022-03-31 | \n", "2022-03-31 | \n", "-0.022578 | \n", "
133919 | \n", "24985.0 | \n", "1991-09-20 | \n", "2022-03-31 | \n", "2022-03-31 | \n", "0.097731 | \n", "
133920 | \n", "29946.0 | \n", "1982-10-14 | \n", "2022-03-31 | \n", "2022-03-31 | \n", "0.030331 | \n", "
133921 | \n", "17700.0 | \n", "2021-09-20 | \n", "2022-03-31 | \n", "2022-03-31 | \n", "-0.062406 | \n", "
133922 rows × 5 columns
\n", "\n", " | date | \n", "permno | \n", "comnam | \n", "ncusip | \n", "shrcd | \n", "exchcd | \n", "hsiccd | \n", "ticker | \n", "gvkey | \n", "iid | \n", "start | \n", "ending | \n", "ret | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2000-01-31 | \n", "40416.0 | \n", "AVON PRODUCTS INC | \n", "05430310 | \n", "11.0 | \n", "1.0 | \n", "2844.0 | \n", "AVP | \n", "001920 | \n", "01 | \n", "1967-05-18 | \n", "2015-03-20 | \n", "-0.035985 | \n", "
1 | \n", "2000-01-31 | \n", "44062.0 | \n", "SPRINGS INDUSTRIES INC | \n", "85178310 | \n", "11.0 | \n", "1.0 | \n", "2221.0 | \n", "SMI | \n", "009963 | \n", "01 | \n", "1967-06-29 | \n", "2000-12-11 | \n", "-0.089202 | \n", "
2 | \n", "2000-01-31 | \n", "26403.0 | \n", "DISNEY WALT CO | \n", "25468710 | \n", "11.0 | \n", "1.0 | \n", "4833.0 | \n", "DIS | \n", "003980 | \n", "01 | \n", "1976-07-01 | \n", "2022-03-31 | \n", "0.241453 | \n", "
3 | \n", "2000-01-31 | \n", "60628.0 | \n", "FEDEX CORP | \n", "31428X10 | \n", "11.0 | \n", "1.0 | \n", "4513.0 | \n", "FDX | \n", "004598 | \n", "01 | \n", "1980-11-06 | \n", "2022-03-31 | \n", "-0.033588 | \n", "
4 | \n", "2000-01-31 | \n", "69032.0 | \n", "MORGAN STANLEY DEAN WITTER & CO | \n", "61744644 | \n", "11.0 | \n", "1.0 | \n", "6282.0 | \n", "MWD | \n", "012124 | \n", "01 | \n", "1995-09-22 | \n", "2022-03-31 | \n", "-0.069002 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
169638 | \n", "2022-03-31 | \n", "17478.0 | \n", "S & P GLOBAL INC | \n", "78409V10 | \n", "11.0 | \n", "1.0 | \n", "6282.0 | \n", "SPGI | \n", "007163 | \n", "01 | \n", "1957-03-01 | \n", "2022-03-31 | \n", "0.091775 | \n", "
169639 | \n", "2022-03-31 | \n", "91152.0 | \n", "TRANSDIGM GROUP INC | \n", "89364110 | \n", "11.0 | \n", "1.0 | \n", "3728.0 | \n", "TDG | \n", "148349 | \n", "01 | \n", "2016-06-03 | \n", "2022-03-31 | \n", "-0.022578 | \n", "
169641 | \n", "2022-03-31 | \n", "24985.0 | \n", "AMEREN CORP | \n", "02360810 | \n", "11.0 | \n", "1.0 | \n", "4911.0 | \n", "AEE | \n", "010860 | \n", "01 | \n", "1991-09-20 | \n", "2022-03-31 | \n", "0.097731 | \n", "
169642 | \n", "2022-03-31 | \n", "29946.0 | \n", "BROWN FORMAN CORP | \n", "11563720 | \n", "11.0 | \n", "1.0 | \n", "2085.0 | \n", "BF | \n", "002435 | \n", "01 | \n", "1982-10-14 | \n", "2022-03-31 | \n", "0.030331 | \n", "
169643 | \n", "2022-03-31 | \n", "17700.0 | \n", "CERIDIAN H C M HOLDING INC | \n", "15677J10 | \n", "11.0 | \n", "1.0 | \n", "7372.0 | \n", "CDAY | \n", "023546 | \n", "01 | \n", "2021-09-20 | \n", "2022-03-31 | \n", "-0.062406 | \n", "
133640 rows × 13 columns
\n", "\n", " | Symbol | \n", "Security | \n", "SEC filings | \n", "GICS Sector | \n", "GICS Sub-Industry | \n", "Headquarters Location | \n", "Date first added | \n", "CIK | \n", "Founded | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "MMM | \n", "3M | \n", "reports | \n", "Industrials | \n", "Industrial Conglomerates | \n", "Saint Paul, Minnesota | \n", "1976-08-09 | \n", "66740 | \n", "1902 | \n", "
1 | \n", "AOS | \n", "A. O. Smith | \n", "reports | \n", "Industrials | \n", "Building Products | \n", "Milwaukee, Wisconsin | \n", "2017-07-26 | \n", "91142 | \n", "1916 | \n", "
2 | \n", "ABT | \n", "Abbott | \n", "reports | \n", "Health Care | \n", "Health Care Equipment | \n", "North Chicago, Illinois | \n", "1964-03-31 | \n", "1800 | \n", "1888 | \n", "
3 | \n", "ABBV | \n", "AbbVie | \n", "reports | \n", "Health Care | \n", "Pharmaceuticals | \n", "North Chicago, Illinois | \n", "2012-12-31 | \n", "1551152 | \n", "2013 (1888) | \n", "
4 | \n", "ABMD | \n", "Abiomed | \n", "reports | \n", "Health Care | \n", "Health Care Equipment | \n", "Danvers, Massachusetts | \n", "2018-05-31 | \n", "815094 | \n", "1981 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
498 | \n", "YUM | \n", "Yum! Brands | \n", "reports | \n", "Consumer Discretionary | \n", "Restaurants | \n", "Louisville, Kentucky | \n", "1997-10-06 | \n", "1041061 | \n", "1997 | \n", "
499 | \n", "ZBRA | \n", "Zebra Technologies | \n", "reports | \n", "Information Technology | \n", "Electronic Equipment & Instruments | \n", "Lincolnshire, Illinois | \n", "2019-12-23 | \n", "877212 | \n", "1969 | \n", "
500 | \n", "ZBH | \n", "Zimmer Biomet | \n", "reports | \n", "Health Care | \n", "Health Care Equipment | \n", "Warsaw, Indiana | \n", "2001-08-07 | \n", "1136869 | \n", "1927 | \n", "
501 | \n", "ZION | \n", "Zions Bancorporation | \n", "reports | \n", "Financials | \n", "Regional Banks | \n", "Salt Lake City, Utah | \n", "2001-06-22 | \n", "109380 | \n", "1873 | \n", "
502 | \n", "ZTS | \n", "Zoetis | \n", "reports | \n", "Health Care | \n", "Pharmaceuticals | \n", "Parsippany, New Jersey | \n", "2013-06-21 | \n", "1555280 | \n", "1952 | \n", "
503 rows × 9 columns
\n", "