Download Historical Stock Quotes from 1962 to present for FREE

Discussion in 'Trading Software' started by OxonianTrader, Sep 13, 2003.

  1. derfel

    derfel

    I downloaded it, ran it, it retrieved quotes for 5 stocks and then got a connect timeout. Pretty much the same thing each time. I notice there's no real docs and support calls are $25/pop.... This was the Java version. Were you using that or the Perl version?
     
  2. derfel

    derfel

    Oops. That was quotemonster I was referring to above.
     
  3. Bob111

    Bob111

    everyone, who know basics in programming can write such app in less than hour.
    i did it for myself long time ago.

    peace
     
  4. :confused: :confused: :confused:

    I guess it depends on how much experience one has with creating programs that mine for data. Here's one of 5 files required for the program:

    // Decompiled by DJ v2.9.9.61 Copyright 2000 Atanas Neshkov Date: 8/30/2003 9:48:20 PM
    // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
    // Decompiler options: packimports(3)
    // Source File Name: YahooHistory.java

    import java.io.*;
    import java.net.URL;
    import java.util.*;

    public class YahooHistory
    {

    public YahooHistory()
    {
    startDate = "";
    endDate = "";
    outputFile = "";
    header = "";
    removeCarets = false;
    fileAppend = true;
    centuryDemarc = 10;
    proxy = "";
    proxyPort = "";
    }

    public boolean getQuotes(String s, String s1)
    {
    HashMap hashmap = new HashMap();
    Vector vector = new Vector();
    try
    {
    QMSettings qmsettings = new QMSettings();
    HashMap hashmap1 = qmsettings.getSettings();
    String s2 = (String)hashmap1.get("tickerFile");
    Vector vector1 = getTickers(s2);
    outputFile = (String)hashmap1.get("outputFile");
    proxy = (String)hashmap1.get("proxy");
    proxyPort = (String)hashmap1.get("proxyPort");
    header = (String)hashmap1.get("header");
    if("yes".equalsIgnoreCase((String)hashmap1.get("removeCarets")))
    removeCarets = true;
    if("no".equalsIgnoreCase((String)hashmap1.get("fileAppend")))
    fileAppend = false;
    if(header.length() > 0)
    initializeFile(outputFile, header);
    else
    if(!fileAppend)
    initializeFile(outputFile);
    centuryDemarc = (new Integer((String)hashmap1.get("centuryDemarc"))).intValue();
    String s3 = getYear(s);
    String s4 = getMonth(s);
    String s5 = getDay(s);
    String s6 = getYear(s1);
    String s7 = getMonth(s1);
    String s8 = getDay(s1);
    for(int i = 0; i < vector1.size(); i++)
    {
    String s9 = (String)vector1.elementAt(i);
    String s10 = "";
    if(proxy.length() > 0 && proxyPort.length() > 0)
    s10 = getURL(s9, s3, s4, s5, s6, s7, s8, proxy, proxyPort);
    else
    s10 = getURL(s9, s3, s4, s5, s6, s7, s8);
    if(removeCarets)
    s9 = cleanTicker(s9);
    readStoreURL(s9, s10, outputFile);
    }

    return true;
    }
    catch(Exception exception)
    {
    exception.printStackTrace();
    }
    return false;
    }

    private void initializeFile(String s)
    throws IOException
    {
    BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(s, false));
    bufferedwriter.close();
    }

    private void initializeFile(String s, String s1)
    throws IOException
    {
    BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(s, false));
    bufferedwriter.write(s1);
    bufferedwriter.newLine();
    bufferedwriter.close();
    }

    private String cleanTicker(String s)
    {
    StringBuffer stringbuffer = new StringBuffer(s);
    String s1 = "";
    for(int i = 0; i < stringbuffer.length(); i++)
    {
    String s2 = stringbuffer.charAt(i) + "";
    if(!"^".equals(s2))
    s1 = s1 + s2;
    }

    return s1;
    }

    private String getURL(String s, String s1, String s2, String s3, String s4, String s5, String s6)
    {
    return "http://table.finance.yahoo.com/table.csv?s=" + s + "&a=" + s2 + "&b=" + s3 + "&c=" + s1 + "&d=" + s5 + "&e=" + s6 + "&f=" + s4 + "&g=d&y=0&z=" + s + "&ignore=.csv";
    }

    private String getURL(String s, String s1, String s2, String s3, String s4, String s5, String s6,
    String s7, String s8)
    {
    java.util.Properties properties = System.getProperties();
    properties.put("proxySet", "true");
    properties.put("proxyHost", s7);
    properties.put("proxyPort", s8);
    return "http://table.finance.yahoo.com/table.csv?s=" + s + "&a=" + s2 + "&b=" + s3 + "&c=" + s1 + "&d=" + s5 + "&e=" + s6 + "&f=" + s4 + "&g=d&y=0&z=" + s + "&ignore=.csv";
    }

    private Vector getTickers(String s)
    throws IOException
    {
    Vector vector = new Vector();
    BufferedReader bufferedreader = new BufferedReader(new FileReader(s));
    for(boolean flag = false; !flag;)
    {
    String s1 = bufferedreader.readLine();
    if(s1 != null)
    {
    vector.add(s1);
    } else
    {
    bufferedreader.close();
    flag = true;
    }
    }

    return vector;
    }

    private String getYear(String s)
    {
    return s.substring(0, 4);
    }

    private String getMonth(String s)
    {
    int i = (new Integer(s.substring(4, 6))).intValue() - 1;
    return i + "";
    }

    private String getDay(String s)
    {
    return s.substring(6, 8);
    }

    public void readStoreURL(String s, String s1, String s2)
    {
    String s3 = "";
    try
    {
    URL url = new URL(s1);
    BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
    BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(s2, true));
    String s4;
    for(int i = 0; (s4 = bufferedreader.readLine()) != null; i++)
    if(i > 0)
    {
    s4 = qmParse(s, s4);
    if(s4.length() > 0)
    {
    bufferedwriter.write(s4);
    bufferedwriter.newLine();
    }
    }

    bufferedreader.close();
    bufferedwriter.close();
    }
    catch(Exception exception)
    {
    exception.printStackTrace();
    }
    }

    private String qmParse(String s, String s1)
    {
    StringTokenizer stringtokenizer = new StringTokenizer(s1, ",");
    int i = 0;
    String s2 = "";
    if(s1.indexOf("N/A") > -1)
    return "";
    while(stringtokenizer.hasMoreTokens())
    {
    String s3 = stringtokenizer.nextToken();
    if(++i == 1)
    {
    StringTokenizer stringtokenizer1 = new StringTokenizer(s3, "-");
    String s4 = stringtokenizer1.nextToken();
    if(s4.length() == 1)
    s4 = "0" + s4;
    String s5 = monthNumber(stringtokenizer1.nextToken());
    String s6 = stringtokenizer1.nextToken();
    int j = (new Integer(s6)).intValue();
    if(j < centuryDemarc)
    s6 = "20" + s6;
    else
    s6 = "19" + s6;
    String s7 = s6 + s5 + s4;
    s2 = s + "," + s7;
    } else
    {
    s2 = s2 + "," + s3;
    }
    }
    return s2;
    }

    private String monthNumber(String s)
    {
    HashMap hashmap = new HashMap();
    hashmap.put("Jan", "01");
    hashmap.put("Feb", "02");
    hashmap.put("Mar", "03");
    hashmap.put("Apr", "04");
    hashmap.put("May", "05");
    hashmap.put("Jun", "06");
    hashmap.put("Jul", "07");
    hashmap.put("Aug", "08");
    hashmap.put("Sep", "09");
    hashmap.put("Oct", "10");
    hashmap.put("Nov", "11");
    hashmap.put("Dec", "12");
    return (String)hashmap.get(s);
    }

    String startDate;
    String endDate;
    String outputFile;
    String header;
    boolean removeCarets;
    boolean fileAppend;
    int centuryDemarc;
    String proxy;
    String proxyPort;
    }

    So, less than an hour to write five files just like the one above and actually have the program work? I'm sorry to say, but not everyone can do that! I think an experienced programmer might take more than an hour....I consider myself more of a theoretical computer scientist and don't have much programming experience per say. I'm not saying I couldn't do it but I know it would take much longer than an hour...LOL

    :confused: :confused: :confused:
     
  5. It definately works. I downloaded data for every stock in yahoo's database from 1962 on. Now all I have to do is refresh my data once every so often (week?) so that the database stays up to date.

    here's the command line i used:

    c:\program files\quotemonster\java QM 01011962 09132003

    of course, you have to add the executable java to your path so that you can call it from any folder
     
  6. do you know how to write a program that can get historical quotes from Datek? Thanks
     
  7. Bob111

    Bob111

    you have to know how datek page build. if they use frames-you can't do nothing.
    BTW-why do you have to pick data from datek,if it is free and easy to get from yahoo?
     
  8. Bob111

    Bob111

    you can do it in excel too
     
    #10     Sep 13, 2003