Skip to content

Instantly share code, notes, and snippets.

@blippy
Last active June 19, 2016 12:22
Show Gist options
  • Select an option

  • Save blippy/cbb24c5a1532b3ab20dcdfa968016386 to your computer and use it in GitHub Desktop.

Select an option

Save blippy/cbb24c5a1532b3ab20dcdfa968016386 to your computer and use it in GitHub Desktop.
Download a decade's worth of yahoo data
#!/usr/bin/env bash
# download a decade's worth of Yahoo data
# Specify symbol (e.g. VOD.L) in first argument
#echo "$d0" | awk -v T=0 '
dfield () {
echo "$1" | awk -v T="$2" '
BEGIN {
if(T == 0) { keys[1] = "a" ; keys[2] = "b" ; keys[3] = "c" }
else { keys[1] = "d" ; keys[2] = "e" ; keys[3] = "f" };
}
{
split($0, arr, "-");
# month requires decrement due to Yahoo
y = arr[1]; m = arr[2] -1; d = arr[3];
printf "%s=%s&%s=%s&%s=%s", keys[1], m, keys[2], d, keys[3], y;
}
'
}
d0=$(date -d '10 years ago' -I)
f0=$(dfield $d0 0)
d1=$(date -I)
f1=$(dfield $d1 1)
sym="$1"
pre="http://ichart.finance.yahoo.com/table.csv?s=$sym&"
post="&g=d&ignore=.csv"
url="$pre$f0&$f1$post"
echo $url
curl -s $url > raw.dat
h5sort raw.dat
#{if(T=1) { k = print arr[2], T}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment