DEV Community

Syeda Samina Hussain
Syeda Samina Hussain

Posted on

1

A Smart Financial Assistant with Google Vertex AI & Gemini API

Introduction

With the rise of AI in finance, people are looking for intelligent systems that can analyze stock trends, provide investment insights, and assist in decision-making. In this blog, I’ll walk you through my Smart Financial Assistant, a project built using Google Vertex AI and Gemini AI.

This assistant can:

  • Fetch real-time stock data** from Alpha Vantage
  • Provide AI-generated investment insights** using Gemini
  • Explain financial concepts** for beginners

Let’s dive into the implementation, code, and real-world outputs!

Prerequisites

Before you start building the Smart Financial Assistant, ensure you meet the following requirements:

Google Cloud Platform (GCP) Account – You need a GCP account to access Vertex AI and deploy AI models. If you don’t have one, you can sign up here.

Enable Vertex AI – Go to the Google Cloud Console and enable the Vertex AI API for your project.

Basic Understanding of Vertex AI – You should have some knowledge of Google Vertex AI, including:

  • How to initialize Vertex AI
  • How to deploy AI models
  • Basic concepts of function calling with AI

Google Cloud SDK Installed – Install the Google Cloud CLI for authentication and managing your project. Download it here.

Python Installed – Ensure you have Python 3.x installed on your system to run the AI scripts.


1. Project Overview

The Smart Financial Assistant is designed to:

✔️ Use Google Vertex AI for AI-powered interactions

✔️ Integrate Gemini function calling for answering financial queries

✔️ Provide basic insights on stock trends, market updates, and investments

✔️ Lay the groundwork for future enhancements, including real-time financial analysis


2. Tech Stack Used

  • Google Vertex AI: Manages AI models & cloud deployment
  • Gemini AI: Processes financial-related queries
  • Python: For coding and implementing the AI model
  • Google Cloud SDK: For authentication and API access

3. Implementation Steps

Step 1: Setup Google Vertex AI

Ensure you have Google Cloud SDK installed and Vertex AI enabled in your Google Cloud project.

# Authenticate Google Cloud (Run in your terminal)
gcloud auth application-default login --no-launch-browser
gcloud config set project your-project-id
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize Vertex AI in Python

from google.auth import default
from vertexai import init
from vertexai.generative_models import GenerativeModel, Content

# ✅ Replace with your actual Google Cloud project ID
PROJECT_ID = "your-project-id"
LOCATION = "us-central1"

# ✅ Initialize Vertex AI
init(
    project=PROJECT_ID,
    location=LOCATION,
    credentials=None  # Replace with actual credentials
)
Enter fullscreen mode Exit fullscreen mode

Step 3: Integrate Gemini for AI Function Calling

# ✅ Initialize Gemini Model
model = GenerativeModel("gemini-2.0-flash-001")

# ✅ Sample User Query (Financial Question)
user_query = "What are the latest stock market trends?"

# ✅ AI Processing
response = model.generate_content([Content(role="user", parts=[user_query])])

# ✅ Display AI Response
print("Financial Assistant Response:", response)
Enter fullscreen mode Exit fullscreen mode

4. Smart Financial Assistant: AI + Stock Market Data

Now, let’s integrate real-time stock data into our assistant!

Code Implementation

import requests
from vertexai.generative_models import GenerativeModel, Content, Part

# ✅ Alpha Vantage API Key (Replace with actual key)
API_KEY = "your_api_key_here"

# ✅ Function to Fetch Stock Data
def get_stock_price(symbol):
    """Fetches real-time stock data for the given symbol from Alpha Vantage."""
    url = f"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=5min&apikey={API_KEY}"
    response = requests.get(url)
    data = response.json()
    time_series = data.get("Time Series (5min)", {})
    if not time_series:
        return f"❌ No data found for {symbol}. Please check the stock symbol."
    latest_timestamp = max(time_series.keys())
    stock_data = time_series[latest_timestamp]
    return (
        f"📈 Stock Data for {symbol}:\n"
        f"- Open: {stock_data['1. open']}\n"
        f"- High: {stock_data['2. high']}\n"
        f"- Low: {stock_data['3. low']}\n"
        f"- Close: {stock_data['4. close']}\n"
        f"- Volume: {stock_data['5. volume']}\n"
    )
Enter fullscreen mode Exit fullscreen mode

Example Output

📈 Stock Data for IBM:
- Open: $198.40
- High: $200.00
- Low: $197.50
- Close: $198.90
- Volume: 3,200,000
Enter fullscreen mode Exit fullscreen mode

5. Check Out the Code on GitHub!

💻 GitHub Repository: Click Here

#AI #Finance #VertexAISprint #GoogleCloud #FinTech #MachineLearning #StockMarket

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more