Skip to main content

Python toolkit for PEAD research and earnings calendar analysis.

Project description

Run Tests Bump Version on Merge Publish Wheel to PyPi

EarningsPy 📈

EarningsPy is the elegant Python alternative for studying Post Earnings Announcement Drift (PEAD) in financial markets. Designed for quant researchers, data scientists, and finance professionals, this package provides robust tools to analyze earnings calendars, automate data collection, and perform advanced event studies with ease.

Features

  • 🗓️ Earnings Calendar Access: Effortlessly retrieve earnings dates by sector, industry, index, or market capitalization.
  • 🚀 PEAD Analysis: Built-in utilities to compute post-earnings drift and related statistics.
  • 🏦 Data Integration: Seamless integration with Finviz for comprehensive earnings and 20 min delayed market data.
  • 🔍 Flexible Filtering: Filter earnings events by week, month, or custom criteria.
  • 🛠️ Quant-Friendly API: Pandas-based workflows for easy integration into quant research pipelines.
  • 📊 Excel-Ready Data: Generate profiled, ready-to-use datasets for calculations and modeling directly in Excel.

Installation

pip install earningspy

Usage (WIP)

Fetch next week earnings

from earningspy.calendars.earnings import EarningSpy
EarningSpy.get_next_week_earnings()

Fetch earnings by ticker

from earningspy.calendars.earnings import EarningSpy
EarningSpy.get_by_tickers(['AAPL', 'MSFT', 'GOOGL'])

Inspect PEAD anomaly with after-earnings data

This is useful to build timeseries, dashboards and graphs to study historical information, not suitable to train models because you will have look ahead bias. The data fetched using this approach will contain post earning information. Meaning, it will contain the fundamentals lastly reported.

First time (create your local calendar file)

from earningspy.calendars.earnings import EarningSpy
from earningspy.inspectors.pead import PEADInspector
import nest_asyncio  # Only if ran on a notebook
nest_asyncio.apply()

# Get after earning data
previous_week = EarningSpy.get_this_week_earnings()
inspector = PEADInspector(
    calendar=previous_week
)

# Inspect on stocks with three days passed from the earnings
# dry_run=True shows the list of stocks to be processed without inspecting
inspector.inspect(days=3, dry_run=True, post_earnings=True)

# dry_run=False gets timeseries data to calculate anomaly metrics (CAPM, CAR, BHAR, VIX, etc)
inspector.inspect(days=3, dry_run=False, post_earnings=True)

# check new columns created
inspector.calendar

# Store in a safe place
inspector.calendar.to_csv('post_earnings.csv')

Second time (load local calendar and append new information)

from earningspy.calendars.earnings import EarningSpy
from earningspy.inspectors.pead import PEADInspector
import nest_asyncio  # Only if ran on a notebook
nest_asyncio.apply()

# Get after earning data
# Use .get_this_week_earnings() if the week has not ended
# Use .get_previous_week_earnings() if the week already passed
previous_week = EarningSpy.get_this_week_earnings()
inspector = PEADInspector(
    calendar=previous_week
)

# load local storage
storage = pd.read_csv('post_earnings.csv', index_col=0, parse_dates=True)

# join new calendar with local storage
merged = pead.join(storage, type_='post')

# you can see the data that is going to be processed without processing it on a given days window
inspector.inspect(days=3, dry_run=True, post_earnings=True)

# you can chain the inspector this will calculate metrics for 60, 30, and 3 event windows
inspector = inspector.inspect(days=60, post_earnings=True) \
                     .inspect(days=30, post_earnings=True) \
                     .inspect(days=3, post_earnings=True)

# Put the updated calendar back on local storage
inspector.calendar.to_csv('post_earnings.csv')

Then you can use the local storge with your preferable BI tool (PowerBI, Tableau, Excel)

Inspect PEAD anomaly with before-earnings data (WIP)

This is useful to train models and perform statistical regressions, it could also be used to build dashboards and graphs but bear in mind that the data fetched using this approach will contain pre earning information. Meaning, the date will point to fundamentals 1 to 5 days before the earnings. For example, if you plot a timeseries over the EPS you will see the EPS previous to the one reported on that given date.

First time (create your local calendar file)

from earningspy.calendars.earnings import EarningSpy
from earningspy.inspectors.pead import PEADInspector
import nest_asyncio  # Only if ran on a notebook
nest_asyncio.apply()

# Get before earning data
# Use .get_next_week_earnings() because you are seeking before earnings information
next_week = EarningSpy.get_next_week_earnings()
inspector = PEADInspector(
    calendar=previous_week
)

# nothing to inspect here because the earnings did not come yet
inspector.calendar.to_csv('post_earnings.csv')

Second time (load local calendar and append new information)

from earningspy.calendars.earnings import EarningSpy
from earningspy.inspectors.pead import PEADInspector
import nest_asyncio  # Only if ran on a notebook
nest_asyncio.apply()

# Get before earning data
previous_week = EarningSpy.get_next_week_earnings()
inspector = PEADInspector(
    calendar=previous_week
)

# load local storage
storage = pd.read_csv('pre_earnings.csv', index_col=0, parse_dates=True)

# join new calendar with local storage
merged = pead.join(storage, type_='pre')

# you can see the data that is going to be processed without processing it on a given days window
inspector.inspect(days=3, dry_run=True)
inspector.inspect(days=30, dry_run=True)
inspector.inspect(days=60, dry_run=True)

# you can chain the inspector this will calculate metrics for 60, 30, and 3 event windows
inspector = inspector.inspect(days=60) \
                     .inspect(days=30) \
                     .inspect(days=3)

# Put the updated calendar back on local storage
inspector.calendar.to_csv('pre_earnings.csv')

Then you can use the local storge with your preferable BI tool (PowerBI, Tableau, Excel). At this point you should already have anomaly metrics.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

earningspy-0.1.21.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earningspy-0.1.21-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file earningspy-0.1.21.tar.gz.

File metadata

  • Download URL: earningspy-0.1.21.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for earningspy-0.1.21.tar.gz
Algorithm Hash digest
SHA256 24571fa156037ef66cda33e8ddd32cf89e3e6da9277c9983d6bdb852dd9f6f2a
MD5 5ddb2a855954636713d0a453e56b57f3
BLAKE2b-256 78e10d53c84ce6f2e68f34aca713f54874d35d73ce23817d8bf1cd89ed30ce8f

See more details on using hashes here.

File details

Details for the file earningspy-0.1.21-py3-none-any.whl.

File metadata

  • Download URL: earningspy-0.1.21-py3-none-any.whl
  • Upload date:
  • Size: 39.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for earningspy-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 9425c63083c288b93785bd344817e43698ef0ad4eec75faaf6f5ab8b4f0abaaa
MD5 cfa150797670ca22d311aad184ced891
BLAKE2b-256 05be8f81dfcf1f9b66202624a2501983934030728ae77b056092c3b5474fd9e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page