Python Charting Stocks/Forex for Technical Analysis Part 7 - Basic Financial Graph

preview_player
Показать описание
This is the seventh video in the series for stock price analysis and financial charting, showing you how to make a very basic stock price chart. 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.

Рекомендации по теме
Комментарии
Автор

Sounds like you're trying to plot with the intra-day data maybe? Open the file. Are the time stamps in unix time? Or date time format?

sentdex
Автор

Are you working with python 3 or python 2.7?

sentdex
Автор

Hi,

I am able to run the code, and I am getting the graph, but in addition to the curves shown in your graph, I am also seeing straight lines connecting the prices on the starting date of the period and those on the closing date. The code is exactly what you have written

ankitagrawal
Автор

Hi, I love your videos, especially because it doesn't get boring! It's great! Quick question though and I see that this question has been an issue for others as well. When I use the converters part where you use strpdate2num I get of course the comment that this function was deprecated but I cannot figure out an alternative way. I've tried to use datestr2num but also I don't find a way to use it. any hint would be much appreciated!

marcohaefner
Автор

I'm working with 2.7...Well i fixed that one...just had to install dateutil and pyparsing...
Thanks for the reply and you ar edoing a great job mate!!! keep it up ...love your work!!!

And does your stock analysis involve any kind of machine algorithm?

hrishikeshbj
Автор

Azzi Dalas For some reason it is not letting me comment on your post. Annoying! Anyway, what version of python and what version of matplotlib do you have? Sounds like you possibly mixed a 32bit and 64 bit there.

sentdex
Автор

Your videos are awesome. However I think I am having issues because I am using Python (x, y). I am getting a syntax error after this line

fig = .plt.figure()

Will you please help me sort this out?

johnstreety
Автор

what is the cause of this error: i use python 2.7


Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 111, in <module>
    raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil

mimo
Автор

Really like your videos! Wondering if you could please help me out. Anytime I run the program I get a message saying "failed main loop 'module' object has no attribute 'loadtext' ". Not sure why this is happening. Thanks.

SpiralTonic
Автор

How do I modify np.loadtxt() expression in python3.4? it seems that upon loading the file and populating the array, everything gets a data type float, which seems to be the default dtype. But the requires input to be a string. As a result it is giving me the error that "strptime() argument must be str, not <class 'bytes'> . Can you help, please? Thanks.

shlokdave
Автор

Hello Mr.
It's great video and thank you for your tutorial.

I have a question.
I tried write code and build it. But it was not worked.
the code is...

import time
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates

eachStock = 'TSLA', 'AAPL'

def graphData(stock):
try:
stockFile = stock+'.txt'

date, closep, highp, lowp, openp, volume = np.loadtxt(stockFile, delimiter=', ', unpack=True, converters={ 0:

fig = plt.figure()
axl = plt.subplot(1, 1, 1)
ax1.plot(date, openp)
ax1.plot(date, highp)
ax1.plot(date, lowp)
ax1.plot(date, closep)




for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)


plt.show()



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

for stock in eachStock:
graphData(stock)
time.sleep(10)

and result was...

failed main loop unconverted data remains: 645
failed main loop unconverted data remains: 640

AAPL.txt is...
1439213640, 117.3400, 117.3700, 116.5300, 116.5300, 2341800
1439213999, 117.4100, 117.6900, 117.1300, 117.3500, 1940400
1439214240, 117.7740, 117.8300, 117.3300, 117.4100, 1397700


and TSLA.txt is...
1439213645, 238.2700, 240.8400, 237.5000, 238.1600, 368600
1439213942, 239.6050, 240.0000, 238.0000, 238.6200, 110100
1439214240, 240.2000, 241.4800, 239.5100, 239.7300, 108800

Python version is 2.7.5
matplotlib version is 1.4.3
numpy version is 1.9.2

Can you help me ?
Thank you.

akkm
Автор

HI sentdex,
while importing matplotlib got this error
raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil

what do i need to do?

hrishikeshbj
Автор

hye, I got an error which is
failed main loop [Errno 2] No such file or directory: 'A.txt'
my file name is AEOM but it only read the first letter only.

syuhaidasafaai
Автор

I suggest the following:
        floatDate, closep, highp, lowp, openp, volume = np.loadtxt(stockFile, delimiter=', ', unpack=True)
        intDate = [int(eachDate) for eachDate in floatDate]
        date = for eachDate in intDate]

NicolajTopp
Автор

Hi. love the videos.  I am getting an annoying error and not sure what to do or how to move forward" from six import advance_iterator, integer_types
ImportError: No module named six"  I have downloaded six and copied it to my project folder, but still getting the error.  I have un-installed everything and re-installed making sure I am using 32bit.... Any ideas? 

ltreloar
Автор

Im getting the below error.  Can you please advise?  Thanks
    for stock in eachStock():
TypeError: 'tuple' object is not callable

BriDo
Автор

I use Python 3.3. I keep getting the error: 
main loop strptime() argument 0 must be str, not <class 'bytes'>
I think that there's an issue with np.loadtxt() and Python 3.X using bytes...
- Is there a simple solution or a way around this problem?

rafaelkasina
Автор

hello all   I keep getting could not convert string to   but  my dates at the beginning are already in the %Y/%m/%d format in the txt file   how can i correct this  i tried multiple things (fooling around ) with no luck any suggestions greatly appreciated

mcmalach
Автор

mdates.strpdate2num has been deprecated it's mdates.datestr2num. But mine issue is different I have milliseconds too. %Y-%M-%D %H:%M:%S.%? I don't know what to put for millisecond.

rahultiwari
Автор

Hi...when I am trying to import matplotlib...I am getting the following error..ImportError: matplotlib requires dateutil...can you please help me out with this

idontseemymails