Skip to main content

Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail

Workflow preview

Workflow preview
100%
Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail preview
Open on n8n.io

1. Workflow Overview

Sector Rotation Tracker & Alert System of Equity Market This workflow automates the tracking of stock market sector rotation. It fetches a list of active stocks from Google Sheets, pulls their last...

Best for

  • Crypto Trading automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.code, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.lmchatgroq, n8n-nodes-base.googlesheets, n8n-nodes-base.httprequest, n8n-nodes-base.manualtrigger, n8n-nodes-base.set, n8n-nodes-base.merge

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by WeblineIndia.

Original n8n.io source

1.1 Workflow description

Title
Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail
Workflow name
Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail

Sector Rotation Tracker & Alert System of Equity Market

This workflow automates the tracking of stock market sector rotation. It fetches a list of active stocks from Google Sheets, pulls their last 5 days of market data from Yahoo Finance and calculates momentum and sector strength using custom code. It then compares this current data against historical data to detect capital rotation signals. Finally, an AI Agent (powered by Groq's Llama-3 model) acts as a financial analyst to interpret the shifts and sends an automated Gmail alert if a high-confidence bullish trend is detected.

Quick Implementation Steps

Don't want to read the details? Follow these quick steps to get started:

  1. Connect Credentials: Authenticate your Google Sheets, Gmail and Groq API accounts in n8n.
  2. Setup Google Sheets: Create a Google Sheet with two tabs. "Sheet1" needs an active column set to true for stocks you want to track. "Sheet2" is used to store daily historic data.
  3. Update Sector Map: Open the Group By Sector code node and update the sectorMap with your specific stock symbols and their corresponding sectors.
  4. Configure Email: Open the Send Email Alert node and enter your destination email address.
  5. Test and Run: Click "Test Workflow" to ensure data flows correctly, then activate it to run on your schedule!

What It Does

The Stock Sector Rotation Tracker acts as your personal automated quantitative analyst. It starts by pulling a predefined watchlist of active stocks from a connected Google Sheet. Using Yahoo Finance's API, it retrieves the daily closing prices and trading volumes over the past 5 days for each stock.

Once the raw data is gathered, a series of custom JavaScript nodes process the information. It calculates 1-day, 3-day and 5-day returns, assigns momentum scores and evaluates volume ratios. The stocks are then grouped into their respective market sectors (e.g., IT, Banking, Auto) to calculate an aggregate "Sector Strength Score." This score is compared against historical data saved from previous days to determine if money is rotating into or out of a specific sector.

To add a layer of human-like intelligence, the compiled data is sent to an AI Agent powered by Groq. The AI acts as an institutional equity researcher, providing a concise summary, explaining the possible reasons for the market movement and assigning a trading bias (Bullish, Bearish or Neutral) along with a confidence score out of 10. If the AI identifies a strong bullish signal, a detailed email alert is instantly dispatched via Gmail.

Who It's For

  • Retail Investors & Day Traders

Looking for automated daily watchlists and momentum alerts without paying for expensive terminal subscriptions.

  • Financial Analysts & Wealth Managers

Needing an automated way to track institutional capital flows and sector rotation over time.

  • Quant Enthusiasts

Wanting a foundation to build custom algorithmic trading indicators using n8n and AI.

Requirements to Use This Workflow

To successfully run this workflow, you will need:

  • An active n8n account (Cloud or Self-Hosted).
  • A Google Account to access Google Sheets (for data storage) and Gmail (for sending alerts).
  • A free Groq API key to power the Llama 3 AI model.
  • A basic understanding of stock symbols (tickers) as used on Yahoo Finance (e.g., INFY.NS or AAPL).

How It Works & Set Up

Step 1: Prepare Your Google Sheets

You need a Google Spreadsheet with two specific tabs.

  • Tab 1 (Watchlist): Must include columns for stock symbols and an active column (set to true or false).
  • Tab 2 (Historic Data): Must include columns for date, sector, sector_strength_score, trend, rotation_signal and score_change.

Step 2: Configure Credentials in n8n

  • Google Sheets & Gmail: Set up OAuth2 credentials for your Google account. Connect these to the Google Sheets nodes and the final Gmail node.
  • Groq API: Generate an API key from the Groq console and add it to the Insights from Model node.

Step 3: Update Stock and Sector Mappings

  • Open the Group By Sector code node.
  • Modify the sectorMap JavaScript object to match the stock symbols in your Google Sheet. For example, change "INFY.NS": "IT" to match your desired ticker and sector.

Step 4: Review AI and Email Thresholds

  • The workflow uses an If node named Check if Bullish. By default, it sends an email if the AI Action is exactly Bullish OR if the AI Confidence score is greater than 7. You can adjust these thresholds based on how strict you want your alerts to be.

How To Customize Nodes

  • Modify the Timeframe

In the Get stocks Data node, the Yahoo Finance URL ends with ?range=5d&interval=1d. You can change this to 1mo (1 month) or interval to 1wk (1 week) to track macro trends instead of short-term momentum.

  • Tweak the Math Formula

The Calculate Stock Returns code node assigns weights to different days (e.g., 1-day return is weighted at 50%, 3-day at 30%). You can easily adjust these multipliers to fit your personal trading strategy.

  • Change the AI Prompt

Open the Prepare AI Insights Prompt code node or the AI Analyzer agent node to rewrite the AI's instructions. You can ask it to adopt a different persona, like a conservative dividend investor, rather than a momentum trader.

Add-ons

Want to take this workflow to the next level? Here are a few ideas:

  • Slack / Discord Integration

Replace or supplement the Gmail node with a Slack or Discord node to push alerts directly to a trading community channel.

  • SMS Notifications

Add a Twilio node to get instant text messages when a high-confidence rotation signal fires.

  • Multiple AI Perspectives

Add a secondary AI node (like OpenAI's GPT-4o or Anthropic's Claude 3.5) to analyze the same data, then use an IF node to only send an alert if both models agree on a Bullish trend.

Use Case Examples

  1. Daily Morning Briefing

Schedule the workflow to run 30 minutes before the market opens to get a fresh perspective on where capital moved the previous day.

  1. Swing Trading Assistant

Use the automated "ROTATION_IN" signals to build a shortlist of swing trade opportunities before the broader market catches on.

  1. Portfolio Rebalancing

Track sector strength over weeks or months to decide when to rebalance a long-term retirement portfolio from lagging sectors to leading ones.

  1. Institutional Capital Flow Tracking

Identify "volume boosts" alongside price momentum to spot hidden institutional buying in specific market sectors.

  1. Educational Paper Trading

Forward the AI insights to a journal or note-taking app (like Notion) to learn how data-driven momentum aligns with actual market performance over time.

Troubleshooting Guide

Issue Possible Cause Solution
Yahoo Finance HTTP Request Fails Rate limits or invalid ticker symbol. Check that the symbols in your Google Sheet exactly match Yahoo Finance tickers (e.g., adding .NS for Indian stocks). Add a longer batching interval in the HTTP node settings.
No Data Moving Past "Group By Sector" sectorMap doesn't match incoming symbols. Open the Group By Sector node and ensure the ticker names in your code exactly match the tickers coming from the API.
AI Node Throws JSON Parse Error The AI responded with conversational text instead of strict JSON. The Parse AI Output node has a fallback to catch this, but you can improve reliability by emphasizing Respond ONLY in valid JSON format in the AI Agent's system prompt.
Google Sheets Node "Cannot find sheet" Document ID or Sheet ID mismatch. Re-select your specific Spreadsheet and Worksheet directly from the dropdown menus inside the Google Sheets nodes.
Emails Are Not Sending The IF node condition is not being met or Gmail authentication expired. Check the execution logs. If the AI is returning a confidence of 6, it won't send. Re-authenticate your Google account if the node shows an OAuth error.

Need Help?

Building financial automation workflows can be complex and tweaking momentum formulas or AI prompts sometimes requires a bit of trial and error. If you need assistance setting up this workflow, customizing the JavaScript nodes, integrating additional trading APIs or building entirely new automation systems tailored to your business, our n8n workflow developers are here to help!

Reach out to WeblineIndia for expert n8n consulting, development and support to turn your automation ideas into reality.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Normalize Data

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 2 - Calculate Stock Returns

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 3 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Group By Sector

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 5 - Detect Rotation and Compare Historic Data

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 6 - Parse AI Output

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - Insights from Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGroq - lmChatGroq
Config choices
Version 1

Block 8 - Prepare AI Insights Prompt

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 9 - Save Today's Market Data

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.7

Block 10 - Get stocks Data

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.3

Block 11 - Generate Daily Rotation

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 12 - Fetch Active Stocks

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.7

Block 13 - Set API Base URL

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 14 - Fetch Historic Data

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.7

Block 15 - Calculate Sector Strength

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 16 - Merge Current & Historic Data

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 17 - AI Analyzer

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 3.1

Block 18 - Check if Bullish

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 19 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 22 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 23 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 24 - Send Email Alert

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.2

3. Summary Table

Workflow Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail
Complexity advanced
Nodes 24
Categories Crypto Trading, AI Summarization
Author WeblineIndia
Published 15 Apr 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/15068/15068.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Track equity sector rotation with Google Sheets, Yahoo Finance, Groq and Gmail do?

Sector Rotation Tracker & Alert System of Equity Market This workflow automates the tracking of stock market sector rotation. It fetches a list of active stocks from Google Sheets, pulls their last...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Crypto Trading, AI Summarization use case.