This post is not about economics, it’s about scripting. People who follow stocks love to see historic prices. Here I’ll show you how to get historic ASX data and do a simple plot with the wonderful open-source tool gnuplot.
Getting the data
I’m uncertain who runs it, but this site offers .zip
files containing basic daily data, updated each weekend. The archives have CSV files in them:
To make these useful, I joined them together and imported them into sqlite. On Debian this is in the sqlite3
package.
To turn the .zip
files into a sqlite
file:
- Download the files for the time period you need, and put them in a folder called “
data
” - Save the script below as “
import.sh
” and run it.
|
|
After running import.sh
, the data is in a file called “asx-historic.db
”. You should re-run this script with extra data when it comes out.
Querying an sqlite database
That file is a database, so you can query it with SQL like so:
|
|
Graphing closing prices
Line graphs in gnuplot are very simple. Save this file as line.gnuplot
:
|
|
Note: “fout” (file out) “fin” (file in) and “code” are variables.
This bash script lists closing prices for a code and saves them to a .dat
file under a folder called “plot”.
|
|
An example usage would be:
|
|
Which (given a few months of data) looked like this:
File list
If you follow this from start-to-finish, then you should have the following files:
- data/
- (Lots of zip files)
- plot/
- CSL.dat
- CSL.pdf
- txt/
- (Lots of text files)
- asx-historic.db
- import.sh
- line.sh
- line.gnuplot