This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 735
Adding Earning Call transcripts of US based companies #658
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c127691
Add files IMDB
Athe-kunal dad61e1
Add files IMDB
Athe-kunal 678acf1
Add to library json
Athe-kunal 4d30b77
Linting checks
Athe-kunal 5be6ac7
Add to linting
Athe-kunal 37c1970
Black linting
Athe-kunal 6b50a75
Import fixes
Athe-kunal ca8c63a
Readme and import os changes
Athe-kunal c17bd94
linting via black
Athe-kunal 5b41cdb
match id
Athe-kunal d1b3f07
dataframe to docs
Athe-kunal 74cd66f
Remove extra files
Athe-kunal 223a580
make dataframe optional
Athe-kunal af55ce6
Merge branch 'main' into main
Athe-kunal a8554cc
Merge branch 'main' into main
Athe-kunal aa6010d
Merge branch 'run-llama:main' into main
Athe-kunal 62f8ea6
Add links for IMDB reviews
Athe-kunal 95cde87
Merge branch 'run-llama:main' into main
Athe-kunal 87e2807
Merge branch 'run-llama:main' into main
Athe-kunal 96f4582
Bug fix for spoilers
Athe-kunal ae1c352
Merge branch 'run-llama:main' into main
Athe-kunal e2d1ac7
expected conditions and voting features
Athe-kunal 623c83a
linting
Athe-kunal da41407
liniting checks
Athe-kunal 89c5d72
readme updates
Athe-kunal d89043a
readme updates on metadata
Athe-kunal d2aeb96
Merge branch 'run-llama:main' into main
Athe-kunal a5d1722
Add earnings call transcript and update to imdb review
Athe-kunal 779f181
satisfy the linting gods
Athe-kunal dad76e0
add to library.json
Athe-kunal 29ef08c
Update library.json
Athe-kunal a467ac8
Merge branch 'run-llama:main' into main
Athe-kunal a47b364
Update library.json
Athe-kunal ad463c5
Merge branch 'run-llama:main' into main
Athe-kunal 7adc270
name change for the nit
Athe-kunal a2a0a1a
Merge branch 'run-llama:main' into main
Athe-kunal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# EARNING CALL TRANSCRIPTS LOADER | ||
|
||
This loader fetches the earning call transcripts of US based companies from the website [discountingcashflows.com](https://discountingcashflows.com/). It is not available for commercial purposes | ||
|
||
Install the required dependencies | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
The Earning call transcripts takes in three arguments | ||
|
||
* Year | ||
* Ticker symbol | ||
* Quarter name from the list ["Q1","Q2","Q3","Q4"] | ||
|
||
## Usage | ||
|
||
```python | ||
from llama_index import download_loader | ||
|
||
IMDBReviewsloader = download_loader('EarningsCallTranscript') | ||
|
||
loader = EarningsCallTranscript(2023,'AAPL','Q3') | ||
docs = loader.load_data() | ||
``` | ||
|
||
The metadata of the transcripts are the following | ||
|
||
* ticker | ||
* quarter | ||
* date_time | ||
* speakers_list | ||
|
||
## Examples | ||
|
||
#### Llama Index | ||
```python | ||
from llama_index import download_loader | ||
from llama_index import VectorStoreIndex, download_loader | ||
|
||
EarningsCallTranscript = download_loader('EarningsCallTranscript') | ||
|
||
loader = EarningsCallTranscript(2023,'AAPL','Q3') | ||
docs = loader.load_data() | ||
|
||
index = VectorStoreIndex.from_documents(documents) | ||
query_engine = index.as_query_engine() | ||
|
||
response = query_engine.query( | ||
"What was discussed about Generative AI?", | ||
) | ||
print(response) | ||
|
||
``` | ||
|
||
#### Langchain | ||
|
||
```python | ||
from llama_index import download_loader | ||
from langchain.agents import Tool | ||
from langchain.agents import initialize_agent | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.llms import OpenAI | ||
|
||
EarningsCallTranscript = download_loader('EarningsCallTranscript') | ||
|
||
loader = EarningsCallTranscript(2023,'AAPL','Q3') | ||
docs = loader.load_data() | ||
|
||
tools = [ | ||
Tool( | ||
name="LlamaIndex", | ||
func=lambda q: str(index.as_query_engine().query(q)), | ||
description="useful for questions about investor transcripts calls for a company. The input to this tool should be a complete english sentence.", | ||
return_direct=True, | ||
), | ||
] | ||
llm = ChatOpenAI(temperature=0) | ||
agent = initialize_agent( | ||
tools, llm, agent="conversational-react-description" | ||
) | ||
agent.run("What was discussed about Generative AI?") | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from llama_hub.earnings_call_transcript.base import EarningsCallTranscript | ||
|
||
from llama_hub.earnings_call_transcript.utils import ( | ||
get_earnings_transcript, | ||
extract_speakers, | ||
correct_date, | ||
) | ||
|
||
__all__ = [ | ||
"EarningsCallTranscript", | ||
"get_earnings_transcript", | ||
"extract_speakers", | ||
"correct_date", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from llama_index.readers.base import BaseReader | ||
from llama_index.readers.schema.base import Document | ||
from datetime import datetime | ||
from typing import List | ||
|
||
try: | ||
from llama_hub.earnings_call_transcript.utils import get_earnings_transcript | ||
except ImportError: | ||
from utils import get_earnings_transcript | ||
|
||
|
||
class EarningsCallTranscript(BaseReader): | ||
def __init__(self, year: int, ticker: str, quarter: str): | ||
"""Get the earning call transcripts for a given company, in a given year and quarter | ||
|
||
Args: | ||
year (int): Year of the transcript | ||
ticker (str): ticker symbol of the stock | ||
quarter (str): quarter | ||
""" | ||
curr_year = datetime.now().year | ||
assert year <= curr_year, "The year should be less than current year" | ||
|
||
assert quarter in [ | ||
"Q1", | ||
"Q2", | ||
"Q3", | ||
"Q4", | ||
], 'The quarter should from the list ["Q1","Q2","Q3","Q4"]' | ||
self.year = year | ||
self.ticker = ticker | ||
self.quarter = quarter | ||
|
||
def load_data(self) -> List[Document]: | ||
resp_dict, speakers_list = get_earnings_transcript( | ||
self.quarter, self.ticker, self.year | ||
) | ||
return Document( | ||
text=resp_dict["content"], | ||
extra_info={ | ||
"ticker": resp_dict["symbol"], | ||
"quarter": "Q" + str(resp_dict["quarter"]), | ||
"date_time": resp_dict["date"], | ||
"speakers_list": speakers_list, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#API-calling | ||
tenacity | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from tenacity import retry, stop_after_attempt, wait_random_exponential | ||
import requests | ||
import json | ||
from datetime import datetime | ||
import re | ||
from typing import List | ||
|
||
|
||
def correct_date(yr, dt): | ||
"""Some transcripts have incorrect date, correcting it | ||
|
||
Args: | ||
yr (int): actual | ||
dt (datetime): given date | ||
|
||
Returns: | ||
datetime: corrected date | ||
""" | ||
dt = datetime.strptime(dt, "%Y-%m-%d %H:%M:%S") | ||
if dt.year != yr: | ||
dt = dt.replace(year=yr) | ||
return dt.strftime("%Y-%m-%d %H:%M:%S") | ||
|
||
|
||
def extract_speakers(cont: str) -> List[str]: | ||
"""Extract the list of speakers | ||
|
||
Args: | ||
cont (str): transcript content | ||
|
||
Returns: | ||
List[str]: list of speakers | ||
""" | ||
pattern = re.compile(r"\n(.*?):") | ||
matches = pattern.findall(cont) | ||
|
||
return list(set(matches)) | ||
|
||
|
||
@retry(wait=wait_random_exponential(min=1, max=5), stop=stop_after_attempt(2)) | ||
def get_earnings_transcript(quarter: str, ticker: str, year: int): | ||
"""Get the earnings transcripts | ||
|
||
Args: | ||
quarter (str) | ||
ticker (str) | ||
year (int) | ||
""" | ||
response = requests.get( | ||
f"https://discountingcashflows.com/api/transcript/{ticker}/{quarter}/{year}/", | ||
auth=("user", "pass"), | ||
) | ||
|
||
resp_text = json.loads(response.text) | ||
speakers_list = extract_speakers(resp_text[0]["content"]) | ||
corrected_date = correct_date(resp_text[0]["year"], resp_text[0]["date"]) | ||
resp_text[0]["date"] = corrected_date | ||
return resp_text[0], speakers_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to make this change in this PR? if there's imdb changes let's make that in a sep PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I contributed imdb_scraper sometime back, but this was just a minor change that does not change much. For making it a separate PR, do I have to undo the changes and commit again, or is there any other way? Sorry if this is a stupid question