From 51a84ead20bbd2b1c3f441c0c0715de2fe7e0d5d Mon Sep 17 00:00:00 2001 From: Samuel Barton <31374086+samueldbarton@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:32:56 -0600 Subject: [PATCH] Add CAGR calculation script within math folder (#965) * Add CAGR calculation script within math folder. * Update calculate-CAGR.sh with descriptive naming Co-authored-by: Thiago Holanda --------- Co-authored-by: Thiago Holanda --- commands/math/calculate-CAGR.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 commands/math/calculate-CAGR.sh diff --git a/commands/math/calculate-CAGR.sh b/commands/math/calculate-CAGR.sh new file mode 100755 index 000000000..671876a94 --- /dev/null +++ b/commands/math/calculate-CAGR.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Calculate CAGR Percentage +# @raycast.mode compact +# @raycast.packageName Math + +# Optional parameters: +# @raycast.argument1 { "type": "text", "placeholder": "From" } +# @raycast.argument2 { "type": "text", "placeholder": "To" } +# @raycast.argument3 { "type": "text", "placeholder": "Years" } + +# Documentation: +# @raycast.author Samuel Barton +# @raycast.authorURL https://github.com/samueldbarton +# @raycast.description Calculate the CAGR between "from" and "to" values over given "years," then copy the result. + +CAGR=$(echo "scale=4; e( l($2 / $1) / $3 ) - 1" | bc -l) +CAGR=$(echo "scale=2; $CAGR * 100" | bc -l) +CAGR=$(printf "%.2f" "$CAGR") +echo "$CAGR" | pbcopy +echo "The CAGR from $1 to $2 over $3 years is $CAGR%. CAGR copied to clipboard." \ No newline at end of file