Week 11: Natural Language Processing in Finance
Resources
- Core Reading
- Implementation Examples
- Modern NLP Approaches
- OpenAI API for Text Analysis
- FinBERT and Financial NLP Models
- Example Code:
import openai from transformers import pipeline # OpenAI approach def analyze_sentiment_openai(text): response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "Analyze the sentiment of this financial text. Return POSITIVE, NEGATIVE, or NEUTRAL."}, {"role": "user", "content": text} ] ) return response.choices[0].message['content'] # FinBERT approach sentiment_analyzer = pipeline("sentiment-analysis", model="ProsusAI/finbert") def analyze_sentiment_finbert(text): result = sentiment_analyzer(text) return result[0]['label'] # Example usage text = "Company X reported strong earnings growth and increased market share." print(analyze_sentiment_openai(text)) # Requires API key print(analyze_sentiment_finbert(text)) # Local model
Assignment
SEC Filings Analysis Project
- Process and analyze 10-K SEC filings
- Compare traditional and LLM-based sentiment analysis