CoolFace
Apppublic

Rohithms/camarilla-levels-calculator

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿ“Š 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

bash
# Navigate to the project folder
cd 5_camarilla

# Install dependencies
pip install -r requirements.txt

Setup

Make sure your .env file in the root project directory contains your OpenAI API key:

bash
OPENAI_API_KEY=your-openai-api-key-here

Usage

Run the Interactive Agent

bash
python camarilla_agent.py

Example 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 NVDA

How It Works

  1. 1.Ticker Identification: The agent uses a custom tool to identify ticker symbols from company names
  2. 2.Data Fetching: Uses yfinance to get the previous week's OHLC data
  3. 3.Calculation: Applies Camarilla formula:
  4. 4.R = High - Low
  5. 5.R4 = Close + (R ร— 1.1 / 2)
  6. 6.R3 = Close + (R ร— 1.1 / 4)
  7. 7.S3 = Close - (R ร— 1.1 / 4)
  8. 8.S4 = Close - (R ร— 1.1 / 2)
  9. 9.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 Output

Tools

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 timeframe

Customization

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-mini to gpt-4 for 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! ๐Ÿ“ˆ