Skip to content

Commit

Permalink
Add CAGR calculation script within math folder (#965)
Browse files Browse the repository at this point in the history
* Add CAGR calculation script within math folder.

* Update calculate-CAGR.sh with descriptive naming

Co-authored-by: Thiago Holanda <unnamedd@gmail.com>

---------

Co-authored-by: Thiago Holanda <unnamedd@gmail.com>
  • Loading branch information
samueldbarton and unnamedd authored Nov 18, 2024
1 parent 3bea3b8 commit 51a84ea
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions commands/math/calculate-CAGR.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 51a84ea

Please sign in to comment.