Python Charting Stocks/Forex for Technical Analysis Part 2 - How to get free Stock Prices



Charting Stocks in Python playlist: http://www.youtube.com/watch?v=u6Xd3kRHhJI&feature=share&list=PLQVvvaa0QuDcR-u9O8LyLR7URiKuW-XZq This is the second video in the series for stock price analysis, which shows how to acquire free stock prices of varying granularity. The purpose of the videos in this series is to teach you how to program your own charting and analysis of stocks or Forex. This is beneficial for you if you plan to do any sort of algorithmic, high-frequency, or any sort of automated trading. Sentdex.com Facebook.com/sentdex Twitter.com/sentdex

Comments

  1. I am following this tutorial, I have used urllib.request.urlopen rather than urllib and it is not giving any output, any reason for that ?
  2. Python 3.5.1 getting main loop module 'urllib' has no attribute 'urlopen' New to Python read something about needing to use urllib.request but I must be using it incorrectly. Can anyone help?
  3. Great job mate, i really like all your videos ^_^ !
    Keep the good work, best from Romania!
  4. I'm running Python 3.5.2 and I'm noticing one issue that I can't seem to resolve. The pulled data isn't been saved to a file. it displays below the sleeping message. Is there something different that I need to do to make this work properly?
  5. I am having the following message:
    main loop 'str' object has no attribute 'Split'

    My Code is:

    import urllib2
    import time

    stockToPull = 'AAPL'

    def pullData(stock) :
    try:
    fileLine = stock+'.txt'
    urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1y/csv'
    sourcecode = urllib2.urlopen(urlToVisit).read()
    splitsource = sourcecode.Split('\n')

    for eachLine in splitSource:
    splitLine = eachLine.split(',')
    if len(splitLine) ==6:
    if 'values' not in eachLine:
    savefile = open(fileLine,'a')
    lineToWrite = eachLine+'\n'
    saveFile.write(lineToWrite)

    print 'Pulled',stock
    print 'sleeping'
    time.sleep(5)




    except Exception,e:
    print 'main loop',str(e)



    pullData(stockToPull)



    What Am I doing wrong?I am using the 2.7.11 version. Thanks for the help
  6. Hey, firstly, thank you for taking the time to upload these series.

    I am new to Python, and tried to do the same thing you did, but I am having a syntax error highlighting the "," in the "except Exception,e" " line. Can you please advise what I am doing wrong here. Thank you in advance

    import urllib2
    import time

    stockToPull = 'AAPL'

    def pullData(stock):
    try:
    fileLine= stock+'.txt'
    urlToVisit= 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=10d/csv'
    sourceCode= urllib2.urlopen(urlToVisit).read()
    splitSource= sourceCode.split('\n')

    for eachLine in splitSource:
    splitLine = eachLine.split(',')
    if len(splitLine)==6:
    if 'value' not in eachLine:
    saveFile = open(fileLine,'a')
    LineToWrite = eachLine+'\n'
    saveFile.write(lineToWrite)

    print ('Pulled'), stock
    print ('sleeping')
    time.sleep(5)


    except Exception,e:
    print 'main loop',str (e)



    pullData(stockToPull)
  7. I have a bunch of programs I wrote on my own for moving average, RSI, everything. I'm trying to use this as my crawler to get the data, and the blank line at the end is wrecking everything and I can't get rid of it. I've been working for like 4 hours trying to get rid of it and I can't figure it out.
  8. Good tutorials! keep up the good work.
  9. Aaah, this is awesome, you cover exactly what i was planning to do. Is there a well-maintained Python toolkit / library for interactive chart analysis yet? Maybe even including backtesting etc.?
  10. Thank you sir, you have an amazing set of video tutorials!
  11. Just ran the script using JES-4.3. Ran fine but YHOO.txt is no where to be found on my machine. Using MacBook running Yosemite. I embedded some print statements and the data did show in the Command area, just not in ant .txt file. HELP. Thanks. 
  12. Hi :)
    I am doing this series in python 3.4 but I get an error in this one. the error is: Type str doesn't support the buffer API
    and my code is:

    import urllib.request
    import time
    stockToPull = 'AAPL'
    def pullData(stock):
        try:
            fileLine = stock+'.txt'
            urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1y/csv'
            sourceCode = urllib.request.urlopen(urlToVisit).read()
            splitSource = sourceCode.split('\n')#split koden når der kommer ny linje
            for eachLine in splitSource:
                splitLine = eachLine.split(',')
                if len(splitLine) == 6:#vi vil kun se det der indeholder 6 kommaer
                    if 'values' not in eachLine:#vi vil ikke se linjen values (for den har også 6 komma ligesom tallene)
                        saveFile = open(fileLine,'a')
                        lineToWrite = eachLine+'\n'
                        saveFile.write(lineToWrite)
            print('Pulled', stock)
            print('Sleeping... zzz')
            time.sleep(3)
        except Exception as e:
            print('mainloop', str(e))

    pullData(stockToPull)

    I would really appreciate if someone can tell me what is wrong :)
  13. hey, your videos are really excellent for python learners!! Following your steps I can't get the same output as yours. I'm using Python 3.4.1 and already slightly changed the print function by adding (). However it finally pops up to me that "main loop an integer is required (got type str)" . How can I fix it?
  14. hey, thanks alot for your videos! i really enjoy them!
    the program seems to work and shows "Pulled AAPL, sleeping, >>>" at the end. issue is, that there is just an empty AAPL-text file. I checked the code and the url, but cannot find the mistake. maybe you can help out?

    import urllib2
    import time

    stockToPull = 'AAPL'

    def pullData(stock):
        try:
            fileLine = stock+'.txt'
            urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1y/csv'
            sourceCode = urllib2.urlopen(urlToVisit).read()
            splitSource = sourceCode.split('\n')

            for eachLine in splitSource:
                splitLine = eachLine.split(',')
                if len(splitLine)==6:
                    if 'values' not in eachLine:
                        saveFile = open(fileLine,'a')
            lineToWrite = eachLine+'\n'
            saveFile.write(lineToWrite)

            print 'Pulled',stock
            print 'sleeping'
            time.sleep(5)

        except Exception,e:
            print 'main loop',str(e)
            
    pullData(stockToPull)
  15. Tried it in ubuntu, and it seems to be working fine but it doesn't save the file.txt, I just couldn't find it(even when I ran the script using sudo). what could be the problem?
    Thanks
  16. p.s. I know you have vids for building a monte carlo simulation and have watched them 
  17. Love the vids thanks for all of this. Could we do this to get statistics for sports " individual players, team...etc" and use that data to build a monte carlo simulation to get a probability of team A beating Team B in any given game? thanks 
  18. +Martin Roffe Haha, great, glad you got it!
  19. I am getting a 404 error when i run the code. Has yahoo stopped supporting this?

    urltovisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata:type=quote;range=1y/csv'

    * Remote Interpreter Reinitialized  ***
    >>> 
    main loop HTTP Error 404: Not Found
  20. I'm getting an error for indentation on "except". I've tried doing tabs, and spaces - but nothing.
    This is the error i'm encountering on Eclipse.
      File "/Users/MountainLion/Documents/workspace/sentdex3/sentdex.py", line 26
        except Exception,e                                                         
        ^
    IndentationError: unexpected indent


Additional Information:

Visibility: 23055

Duration: 13m 5s

Rating: 99