Skip to content

Instantly share code, notes, and snippets.

@say4n
Last active May 10, 2024 11:20
Show Gist options
  • Save say4n/0f0775cfcb492e883cf7252d09dec6da to your computer and use it in GitHub Desktop.
Save say4n/0f0775cfcb492e883cf7252d09dec6da to your computer and use it in GitHub Desktop.
Compute real return instead of IRR on Vanguard UK's investment dashboard.
// ==UserScript==
// @name Vangugard Real Return
// @namespace https://sayan.page/
// @version 2024-05-10
// @description Vangugard show real return instead of IRR.
// @author say4n
// @match https://secure.vanguardinvestor.co.uk/en-gb/customer/home/*/investments/personals*
// @icon https://www.google.com/s2/favicons?sz=64&domain=www.vanguardinvestor.co.uk
// @run-at document-idle
// @grant none
// ==/UserScript==
(function() {
'use strict';
const intervalId = setInterval(() => {
let stats = [...document.querySelectorAll(".stat-row")];
if (stats.length > 1) {
let startedWith = parseFloat(stats.filter(it => it.innerText.includes("You started with"))[0].getElementsByClassName("figure")[0].innerText.replace("£", "").replace(",", ""));
let contributedAndWithdrew = parseFloat(stats.filter(it => it.innerText.includes("You contributed and withdrew"))[0].getElementsByClassName("figure")[0].innerText.replace("£", "").replace(",", ""));
let returnFromInvestment = parseFloat(stats.filter(it => it.innerText.includes("Your investments returned you"))[0].getElementsByClassName("figure")[0].innerText.replace("£", "").replace(",", ""));
console.log(startedWith, contributedAndWithdrew, returnFromInvestment);
const profitPercent = (returnFromInvestment * 100) / (contributedAndWithdrew + startedWith);
console.log("profitPercent", profitPercent);
const currentText = document.querySelector(".stat-return > .figure").innerText;
document.querySelector(".stat-return > .figure").innerText = currentText + ` (${profitPercent.toFixed(2)}%)`;
currentText && clearInterval(intervalId);
}
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment