Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thierrymoudiki/026834be69dfbc034ba05ee27e338ddf to your computer and use it in GitHub Desktop.
Save thierrymoudiki/026834be69dfbc034ba05ee27e338ddf to your computer and use it in GitHub Desktop.
#!/bin/bash
# === CONFIG ===
OUTPUT_JSON="sims.json"
OUTPUT_CSV="sims.csv"
OUTPUT_IMAGE="plot.png"
# === 1. Prompt for Bearer token ===
read -p "Enter your Bearer token: " AUTH_TOKEN
# === 2. Fetch data from API ===
curl -s -X GET "https://www.techtonique.net/scenarios/simulate/?model=GBM&n=6&horizon=5&frequency=quarterly&x0=100&theta1=0.1&theta2=0.2&theta3=0.3&seed=123" \
-H "accept: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" > "$OUTPUT_JSON"
if [ $? -ne 0 ]; then
echo "❌ Error fetching data from API"
exit 1
fi
# === 3. Convert JSON to long-format CSV ===
jq -r '
.sims as $sims
| $sims | length as $n_series
| range(0; $n_series) as $i
| range(0; $sims[$i] | length) as $t
| "\($t),\($sims[$i][$t]),\($i)"' "$OUTPUT_JSON" > "$OUTPUT_CSV"
# === 4. Add header row (macOS-safe) ===
echo "step,value,series" > temp.csv
tail -n +2 "$OUTPUT_CSV" >> temp.csv
mv temp.csv "$OUTPUT_CSV"
# === 5. Plot with rush ===
#rush plot --x step --y value --group series "$OUTPUT_CSV" > "$OUTPUT_IMAGE"
rush plot \
--x step \
--y value \
--group series \
--color series \
--alpha 0.6 \
--title "Simulated GBM Paths" \
"$OUTPUT_CSV" > "$OUTPUT_IMAGE"
echo "✅ Spaghetti plot saved to: $OUTPUT_IMAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment