Rohithms/camarilla-levels-calculator
0
๐ Weekly Camarilla Levels Calculator
A LangChain-based Financial Analysis Assistant that calculates Weekly Camarilla Levels for swing trading.
What are Camarilla Levels?
Camarilla Pivot Points are a set of support and resistance levels used in technical analysis for swing trading:
- R3/S3: Primary reversal points where price is likely to reverse
- R4/S4: Breakout levels - if breached, expect strong momentum continuation
- Timeframe: Weekly (using previous week's High, Low, Close)
Features
- ๐ฏ Automatic ticker identification from company names
- ๐ Real-time stock data fetching using yfinance
- ๐งฎ Precise Camarilla levels calculation (R4, R3, S3, S4)
- ๐ฌ Conversational AI interface using LangChain agents
- ๐ Beautiful formatted output with trading strategies
Installation
# Navigate to the project folder
cd 5_camarilla
# Install dependencies
pip install -r requirements.txtSetup
Make sure your .env file in the root project directory contains your OpenAI API key:
OPENAI_API_KEY=your-openai-api-key-hereUsage
Run the Interactive Agent
python camarilla_agent.pyExample Queries
๐ค You: Calculate Camarilla levels for AAPL
๐ค You: Show me Tesla levels
๐ค You: What are the weekly levels for Microsoft?
๐ค You: I want to analyze NVDAHow It Works
- Ticker Identification: The agent uses a custom tool to identify ticker symbols from company names
- Data Fetching: Uses yfinance to get the previous week's OHLC data
- Calculation: Applies Camarilla formula:
- R = High - Low
- R4 = Close + (R ร 1.1 / 2)
- R3 = Close + (R ร 1.1 / 4)
- S3 = Close - (R ร 1.1 / 4)
- S4 = Close - (R ร 1.1 / 2)
- Response: Formats and presents the levels with trading guidance
Architecture
User Input
โ
LangChain Agent (GPT-4)
โ
Tool Selection
โโโ identify_ticker (company โ ticker)
โโโ calculate_camarilla_levels (ticker โ levels)
โ
Formatted OutputTools
1. calculate_camarilla_levels
- Fetches previous week's stock data
- Calculates R4, R3, S3, S4 levels
- Returns formatted output with strategy
2. identify_ticker
- Maps company names to ticker symbols
- Handles common stocks (FAANG, etc.)
- Provides suggestions if uncertain
Trading Strategy
R3/S3 - Reversal Zones:
- Price approaching R3: Consider selling/shorting
- Price approaching S3: Consider buying/going long
- High probability reversal points
R4/S4 - Breakout Levels:
- Price breaks above R4: Strong bullish momentum, consider buying
- Price breaks below S4: Strong bearish momentum, consider shorting
- Indicates trend continuation
Example Output
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ WEEKLY CAMARILLA LEVELS FOR AAPL
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐
Previous Week Data:
โข High: $185.50
โข Low: $180.25
โข Close: $183.75
โข Range: $5.25
๐ Camarilla Levels:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Level โ Price โ Description โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ R4 โ $186.64 โ ๐ด Strong Breakout Resistance โ
โ R3 โ $185.19 โ ๐ก Primary Reversal Resistance โ
โ S3 โ $182.31 โ ๐ก Primary Reversal Support โ
โ S4 โ $180.86 โ ๐ข Strong Breakout Support โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ก Trading Strategy:
โข R3/S3: Primary reversal zones - consider counter-trend trades
โข R4/S4: Breakout levels - momentum continuation if breached
โข Best for swing trading with weekly timeframeCustomization
You can modify the agent behavior by editing:
camarilla_agent.py: Main logic and tools- Camarilla multiplier: Currently
1.1, can be adjusted in the formula - LLM model: Change from
gpt-4o-minitogpt-4for better performance
Limitations
- Only supports weekly Camarilla calculations (optimized for swing trading)
- Requires valid ticker symbols or recognizable company names
- Depends on yfinance API availability
- Previous week data must be available
Dependencies
- LangChain: Agent framework and orchestration
- OpenAI: GPT-4 for natural language understanding
- yfinance: Real-time stock data fetching
- python-dotenv: Environment variable management
License
MIT License - See root project LICENSE file
Contributing
Feel free to submit issues or pull requests for:
- Additional technical indicators
- More ticker symbol mappings
- UI improvements
- Performance optimizations
Happy Trading! ๐
