📈 Monitor portfolio correlation and diversification with Google Sheets and Slack

⚡ 18 views · 📈 Crypto Trading & Stock Market

Description

Quick overview

This workflow runs monthly to read portfolio holdings from Google Sheets, fetch 90 days of historical prices via an HTTP endpoint, calculate pairwise correlations and a diversification score, store results back to Google Sheets, generate a QuickChart visualization, and post a diversification report to Slack.

How it works

  1. Runs on a monthly schedule trigger.
  2. Loads portfolio holdings from Google Sheets and filters to rows with a non-empty ticker and asset type plus a positive quantity.
  3. Calculates per-holding portfolio weights and calls an HTTP market-data endpoint to retrieve 90 days of historical closing prices for each ticker.
  4. Consolidates the returned price data, converts prices into daily returns, and computes a Pearson correlation matrix and pairwise correlation list across all holdings.
  5. Derives portfolio diversification metrics such as average correlation, diversification score, risk level, and the highest/lowest correlated pairs.
  6. Builds a QuickChart bar chart URL from the pairwise correlations and requests the rendered chart image.
  7. Appends the diversification summary and pairwise correlation records to separate Google Sheets tabs and posts the formatted diversification report to a Slack channel.

Setup

  1. Create a Google Sheets OAuth credential and point the workflow to your spreadsheet, ensuring you have tabs for “Portfolio Holdings”, “Diversification Log”, and “Pairwise Correlations” with matching column names.
  2. Populate the “Portfolio Holdings” sheet with at least two rows containing ticker, quantity, and asset_type values.
  3. Update the HTTP Request URL (and add any required authentication headers) to a market-data service that returns each ticker’s historical daily close prices for the requested number of days.
  4. Create a Slack credential/connection, select the destination channel, and verify the workflow has permission to post messages.

Additional info

Add-ons

The following are optional extensions and are not included in the current workflow:

Use Case Examples

  1. Monthly Portfolio Review: Automatically analyze asset correlations and diversification as part of a recurring portfolio review.

  2. Diversification Monitoring: Track the relationship between portfolio holdings and identify highly correlated assets.

  3. Investment Research: Review the strongest and weakest relationships between assets using historical price data.

  4. Team Risk Reporting: Send a concise diversification summary to a Slack channel after each scheduled analysis.

  5. Historical Correlation Tracking: Maintain portfolio-level and pairwise correlation records in Google Sheets for future analysis.

Additional use cases can be supported through workflow customization.

Troubleshooting Guide

IssuePossible CauseSolution
Workflow does not startThe workflow is inactive or the schedule has not executedRun the workflow manually for testing and verify the schedule configuration
Holdings are rejectedTicker, quantity, or asset type is missing or invalidCheck the Portfolio Holdings sheet and provide valid values
Fewer than two assets are availableNot enough valid portfolio holdings or market-data resultsEnsure at least two holdings contain valid historical price data
Market data request failsThe webhook-test endpoint is unavailable or the production API is incorrectly configuredConfigure the appropriate production endpoint and verify its request and response format
Correlation calculation failsInsufficient overlapping historical observationsEnsure the assets have enough overlapping daily price data
Google Sheets records are missingGoogle Sheets credential or sheet configuration is incorrectVerify the credential, spreadsheet, and target sheet configuration
Slack notification is not receivedSlack credential or channel configuration is incorrectVerify the Slack credential and selected destination channel
Correlation chart is not generatedQuickChart URL or chart configuration is invalidReview Build Correlation Chart Configuration and verify the generated chart request

Need Help

WeblineIndia can help with n8n workflow setup, Google Sheets and Slack integration, production market-data API configuration, customization, troubleshooting, and optional add-ons. If you need a similar n8n automation for portfolio monitoring, financial analysis, reporting or another business process, contact WeblineIndia for implementation and customization support.

🔗 Nodes Used

Google Sheets, HTTP Request, Slack, Schedule Trigger

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup