# AI Financial Analyst (`bala-ceg/ai-financial-analyst`) Actor

AI Financial Analyst is an Apify Actor that provides detailed stock market insights using AI-powered fundamental analysis, technical analysis, and sentiment analysis

- **URL**: https://apify.com/bala-ceg/ai-financial-analyst.md
- **Developed by:** [Balaji Seetharaman](https://apify.com/bala-ceg) (community)
- **Categories:** AI, Automation
- **Stats:** 32 total users, 0 monthly users, 0.0% runs succeeded, 2 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## 📊 AI Financial Analyst

🚀 **AI Financial Analyst** is an **Apify Actor** that provides **detailed stock market insights** using AI-powered **fundamental analysis, technical analysis, and sentiment analysis**.

It leverages:

- 📈 **Yahoo Finance (`yfinance`)** for real-time financial data.
- 🤖 **OpenAI GPT models** for AI-driven market insights.
- 📰 **Alpha Vantage News Sentiment API** for sentiment analysis.
- ⚙ **Apify Actor** framework for automation.

***

### 🏆 **Features**

✔ **Technical Analysis** (SMA, EMA, RSI, MACD, Bollinger Bands, Supertrend)\
✔ **Fundamental Analysis** (P/E Ratio, EBITDA, Net Income, Debt-to-Equity)\
✔ **Sentiment Analysis** (News Headlines, Market Mood)\
✔ **AI-Generated Insights** (Bullish/Bearish Signals, Risks & Opportunities)\
✔ **Markdown Reports** (Auto-saved to Apify Key-Value Store)

***

### 🚀 **How It Works**

1️⃣ **Fetch Stock Data** – Pulls financials, technical indicators & sentiment.\
2️⃣ **Perform Analysis** – Uses AI to analyze market conditions.\
3️⃣ **Generate Report** – Saves insights in a `report.md` file.\
4️⃣ **Store in Apify** – Saves report to Apify's Key-Value Store.\
5️⃣ **Token Billing** – Charges based on GPT token usage.

***

### 📦 **Installation & Setup**

#### 1️⃣ Clone the Repository

```bash
git clone https://github.com/yourusername/ai-financialanalyst.git
cd ai-financialanalyst
```

#### 2️⃣ Create a Virtual Environment (Optional)

```bash
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
```

#### 3️⃣ Install Dependencies

```bash
pip install -r requirements.txt
```

#### 4️⃣ Set API Keys

Create a `.env` file and add your API keys:

```ini
OPENAI_API_KEY=your-openai-key
ALPHAVANTAGE_API_KEY=your-alpha-vantage-key
```

***

### 🎯 **How to Run Locally**

```bash
apify run --input-file=input.jso
```

📜 **Example `input.json`**

```json
{
    "ticker": "AAPL"
}
```

***

### 🛠 **Project Structure**

```
ai-financialanalyst/
│── src/
│   ├── main.py         # Apify Actor entry point
│   ├── tools.py        # Financial, technical, sentiment analysis tools
│   ├── models.py       # Pydantic data models
│   ├── utils.py        # Helper functions
│   ├── report.md       # Generated stock analysis report
│── .venv/              # Virtual environment (optional)
│── requirements.txt    # Python dependencies
│── README.md           # Project documentation
│── input.json          # Example input format
│── .env                # API keys (gitignore this file)
```

***

### 📊 **Example Report Output**

A sample AI-generated **Markdown Report**:

```markdown
## 📊 AI Financial Analyst Report

### 📌 **Stock Analysis Report**
- **Ticker Symbol:** `AAPL`
- **Generated by:** Apify AI Financial Analyst

---

### 🔍 **AI-Generated Insights**
- **Momentum:** AAPL has strong bullish momentum.
- **Risks:** Overbought RSI, potential short-term pullback.
- **Financial Stability:** Strong revenue & cash flow.
- **Bullish Signals:** Revenue growth, brand loyalty.
- **Bearish Signals:** Market saturation, competition.

---

### 📈 **Technical Analysis**
| Indicator | Value |
|-----------|------|
| **SMA (50)** | 180.25 |
| **RSI** | 72.3 (Overbought) |
| **MACD** | Bullish |

---

### 📰 **Sentiment Analysis**
- **Highest Sentiment:** `Positive`
- **Recent News:**
  - [Apple reports record iPhone sales](https://example.com/news1)
  - [AAPL stock hits all-time high](https://example.com/news2)
```

***

### 🚀 **Contributing**

We welcome contributions! Feel free to:

- **Open Issues** for bug reports or feature requests.
- **Submit Pull Requests** to improve the code.

***

### 📜 **License**

This project is licensed under the **MIT License**.

# Actor input Schema

## `ticker` (type: `string`):

The ticker of the stock to analyze (e.g. TSLA, AAPL, AMZN).

## Actor input object example

```json
{
  "ticker": "AAPL"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "ticker": "AAPL"
};

// Run the Actor and wait for it to finish
const run = await client.actor("bala-ceg/ai-financial-analyst").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "ticker": "AAPL" }

# Run the Actor and wait for it to finish
run = client.actor("bala-ceg/ai-financial-analyst").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "ticker": "AAPL"
}' |
apify call bala-ceg/ai-financial-analyst --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=bala-ceg/ai-financial-analyst",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/TY1DMGZ8998j9sCdO/builds/bcG7PhBBaQFuqBIfs/openapi.json
