Skip to content

Instantly share code, notes, and snippets.

@MEN8v
MEN8v / fifo_live.gs
Last active March 27, 2021 15:44
This Google Apps script will generate a list of your stock holdings for up to 6 accounts taking a list of transactions as input
//Create a map to store unique tickers for an account
var account1 = new Map();
var account2 = new Map();
var account3 = new Map();
var account4 = new Map();
var account5 = new Map();
var account6 = new Map();
function generateTrade(account, stockQuant, stockPrice, action) {
return {
//Get transactions from customer transaction history and sort them by date oldest to newest
var lastTransactionRow = SpreadsheetApp.getActive().getRangeByName('lastTransactionRow').getValue();
var transactions = SpreadsheetApp.getActive().getSheetByName("History").getRange("B3:J" + (lastTransactionRow - 1)).getValues();
transactions = transactions.sort(compareNthElements(4, basicComparator));
//specify which column contains the account name (arrays are 0 based)
var accountCol = 2;
//tickers may be duplicated across accounts; each key in a Map object must be unique; therefore each account needs it's own map
var account1 = new Map();
var account2 = new Map();
var account3 = new Map();
//***GLOBALS***//
var ss = SpreadsheetApp.getActive();
var portfolioSheet = ss.getSheetByName("master"); //replace master with name of the tab that has your portfolio data
var columnToCheck = portfolioSheet.getRange("A:A").getValues();
// Get the last row based on the data range of a single column.
var tickerCount = getLastRowSpecial(columnToCheck);
/************************************************************************
*
* Gets the last row number based on a selected column range values
@MEN8v
MEN8v / iex_msg_ctrl.gs
Last active May 31, 2020 00:58
Creates custom google sheet menu to pull dividend info from IEX and then replace the formulas with the fetched values
//***GLOBALS***//
var ss = SpreadsheetApp.getActive();
var portfolioSheet = ss.getSheetByName("master"); //replace master with name of the tab that has your portfolio data
var columnToCheck = portfolioSheet.getRange("A:A").getValues();
// Get the last row based on the data range of a single column.
var lastRow = getLastRowSpecial(columnToCheck);
/**
* Imports JSON data to your spreadsheet Ex: IMPORTJSON("http://myapisite.com","city/population")
* @param url URL of your JSON data as string