Course Name: [Getting Market Data: Stocks, Crypto, News
Free API:
import yfinance as yf
# Define the stock ticker
ticker = "RELIANCE.NS" # NSE-listed stock
stock = yf.Ticker(ticker)
# Get basic info
info = stock.info
print("Company Info:", info)
# Get financials
financials = stock.financials
print("Financials:", financials)
# Get balance sheet
balance_sheet = stock.balance_sheet
print("Balance Sheet:", balance_sheet)
Paid API:
Capital Market
-
You can get filing Financial Results from NSE: https://www.nseindia.com/companies-listing/corporate-filings-financial-results, then use LLMs to extract the information.
-
Here are some database list by IIMB:
Others:
- https://sharpely.in/: offers inbuilt factor-based portfolio backtester
- https://www.screener.in/
- https://ticker.finology.in/
- https://www.tickertape.in/
- Bloomberg Finance LP.
- Factset Research Systems Inc.
- IHS Markit
- MSCI Inc.
- Thomson Financial Limited/ Thomson Reuters (Markets Ltd.)
However, note that QuantInsti is not affiliated with these vendors, and before getting the data from any vendor, it is essential that traders carry out necessary research about the vendor.
Thanks
@Ajay_Pawar yfinance is giving empty dataframe as output
Can you update yfinance and try again with:
import yfinance as yf
ticker = "RELIANCE.NS" # Replace with your stock symbol
stock = yf.Ticker(ticker)
# Income Statement
income_stmt = stock.financials
print(income_stmt)
Thanks it is working
@Ajay_Pawar Can you please let me know how can LLMs be used to extract information from the filings? Are there any resources that can guide me through this?
Hi Shreyas,
We do have blog on implementing the LLM : https://blog.quantinsti.com/application-llm-portfolio-management-thematic-index/
You can try:
import openai
openai.api_key = "your-api-key"
file = openai.files.create(
file=open("example_10k.pdf", "rb"),
purpose="assistants"
)
assistant = openai.beta.assistants.create(
name="Filing Extractor",
instructions="Extract specific financial data from uploaded company filings and return it as a Python dictionary.",
tools=[{"type": "retrieval"}],
model="gpt-4-1106-preview"
)
thread = openai.beta.threads.create()
openai.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="""
From the attached filing, extract the following fields and return them in a Python dictionary:
- Company Name
- Filing Date
- Fiscal Year
- Revenue
- Net Income
- Risk Factors (as a list)
- Summary of Management Discussion
""",
file_ids=[file.id]
)
run = openai.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)
However you will have to develop method to validate the extracted numbers.
like sampling, compare with benchmark etc.
Okay thanks.