# 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:** 31 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/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# 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(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).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": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bala-ceg/ai-financial-analyst"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

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