Skip to content

Instantly share code, notes, and snippets.

View dashaluna's full-sized avatar

Dasha Luna dashaluna

View GitHub Profile
//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
@dashaluna
dashaluna / dailyPL.gs
Created August 5, 2023 12:48
GSheet script for plotting daily P/L
function plotDailyPL() {
//read the counter (#) in cell A1 of History, number in cell is the row of column to input data
var counter = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("History").getRange("E2");
// record DATE in cell A#
var date = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("History").getRange("D"+counter.getValue());
date.setValue(new Date(new Date().getFullYear(),new Date().getMonth(), new Date().getDate()));
//read portfolio value in "Portfolio Sheet"
@dashaluna
dashaluna / dailyValuation.gs
Created August 5, 2023 12:48
GSheet Script for daily valuation
function plotDailyValuation() {
//read the counter (#) in cell A1 of History, number in cell is the row of column to input data
var counter = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("History").getRange("D2");
// record DATE in cell A#
var date = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("History").getRange("A"+counter.getValue());
date.setValue(new Date(new Date().getFullYear(),new Date().getMonth(), new Date().getDate()));
//read portfolio value in "Portfolio Sheet"
var portfolioValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Portfolio").getRange("H18");