ó ù)°Uc @s—dZddlZddlZddlmZyddlmZWn!ek reddlmZnXddlZddl Z ddl m Z m Z ddlmZddlmZddlmZmZdd lmZdd lmZmZmZdd lmZdd lmZe ƒZej j!ed ƒZ"e j#de$fde j%fde j&fde j&fde j'fde j'fde j'fde j'fde j'fde j'fde j'fg ƒZ(e)e*d„Z+dd„Z-e*e)dd„Z.dddd„Z/d ddd!d"„Z0d#ddd$„Z1d#ddd%d&„Z2ddd#d!d'„Z3ddd#d!d(„Z4ddd#d!d)„Z5d*d+d#d!d,„Z6dS(-so A collection of modules for collecting, analyzing and plotting financial data. User contributions welcome! iÿÿÿÿN(turlopen(tmd5(tverboset get_configdir(tdate2num(titerable(tLineCollectiontPolyCollection(tcolorConverter(tLine2DtTICKLEFTt TICKRIGHT(t Rectangle(tAffine2Ds finance.cachetdatetyeartmonthtdaytdtopentclosethightlowtvolumetaclosec Cs·|jƒ}g}d}x |dD]ý}|jdƒ}t|ƒdkrPq#n|d}tjg|jdƒD]} t| ƒ^qpŒ} t| ƒ} g|dd!D]} t| ƒ^q¥\} } }}t|dƒ}t|dƒ}|j| | j | j | j | | || |||f ƒq#W|j ƒt j|d tƒ}|r´|d |d }t j|t j|ƒ<|d c|9<|d c|9<|d c|9<|dc|9= open colordown : the color of the lines where close < open return value is a list of lines added itxdatatydatatcolort antialiasedtmarkert markersize(R tFalseR R textendtadd_linetautoscale_view(taxtquotestticksizetcolorupt colordownR1tqttRRRRR`tvlinetolinetcline((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytplot_day_summaryæs8        gš™™™™™É?gð?c Cs4|d}g}g}x|D]ÿ} | d \} } } } }| | kra|}| }| | }n|}| }| | }td| | fd|| fddddd tƒ}td | ||fd |d |d |d|ƒ}|j|ƒ|j|ƒ|j|ƒ|j|ƒ|j|ƒqW|jƒ||fS(sƒ quotes is a sequence of (time, open, close, high, low, ...) sequences. As long as the first 5 elements are these values, the record can be as long as you want (eg it may store volume). time must be in float days format - see date2num Plot the time, open, close, high, low as a vertical line ranging from low to high. Use a rectangular bar to represent the open-close span. If close >= open, use colorup to color the bar, otherwise use colordown ax : an Axes instance to plot to width : fraction of a day for the rectangle width colorup : the color of the rectangle where close >= open colordown : the color of the rectangle where close < open alpha : the rectangle alpha level return value is lines, patches where lines is a list of lines added and patches is a list of the rectangle patches added g@iR^R_R`R]t linewidthgà?Ratxytwidththeightt facecolort edgecolor(R tTrueR t set_alphaR"Rft add_patchRg(RhRiRuRkRltalphatOFFSETR1tpatchesRmRnRRRRR`tlowerRvRotrect((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pyt candlestick!s<            ic# CsTgttt|ƒƒ||ƒD]3\}} } | dkr|| f|| ff^q} | dfd fg} d |dffg} gttt|ƒƒ|ƒD]$\}}|dkrŸ||f^qŸ}gttt|ƒƒ|ƒD]$\}}|dkrå||f^qå}|jjdd}tƒj|dƒ}tj|ƒ\}}}|||df}tj|ƒ\}}}|||df}i|t 6|t 6}gt||ƒD]4\}}|dkr°|dkr°|||k^q°}d}d}t | d|d|d |ƒ}t | d|d |d|d |d |j ƒ}|j |ƒt | d|d |d|d |d |j ƒ}|j |ƒdt| ƒ}}tg|D]} | dkr¥| ^q¥ƒ} tg|D]} | dkrÐ| ^qЃ}!|| f||!ff}"|j|"ƒ|jƒ|j|ƒ|j|ƒ|j|ƒ|||fS(s³ Represent the time, open, close, high, low as a vertical line ranging from low to high. The left tick is the open and the right tick is the close. ax : an Axes instance to plot to ticksize : size of open and close ticks in points colorup : the color of the lines where close >= open colordown : the color of the lines where close < open return value is a list of lines added iÿÿÿÿigð?gR@gitcolorst linewidthst antialiasedstoffsetst transOffset(ii(ii(i(i(tziptxrangeRtfiguretdpiR R:Rtto_rgbRyRdRt transDatat set_transformtmintmaxtupdate_datalimRgtadd_collection(#RhtopenstclosesthighstlowsRjRkRltiRRt rangeSegmentst openSegmentst closeSegmentsRt offsetsOpenRt offsetsCloseR:t tickTransformR?tgtbtcolordR‚tuseAAtlwtrangeCollectiontopenCollectiontcloseCollectiontminpytmaxxtminytmaxytcorners((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytplot_day_summary2fsXXFF  J        ++     gè?c  Cs¤|d} gttt|ƒƒ||ƒD]a\} } } | dkr)| dkr)| | | f| | | f| | | f| | | ff^q)} gttt|ƒƒ||ƒD]3\} }}|dkr¯| |f| |ff^q¯}tj|ƒ\}}}||||f}tj|ƒ\}}}||||f}i|t6|t6}gt||ƒD]4\} } | dkr`| dkr`|| | k^q`}d }d }t|ddd|d|ƒ}t| d |d dd|d|ƒ}dt|ƒ}}t g|D]}|dkr|^qƒ}t g|D]}|dkr0|^q0ƒ}||f||ff}|j |ƒ|j ƒ|j |ƒ|j |ƒ||fS(s‡ Represent the open, close as a bar line and high low range as a vertical line. ax : an Axes instance to plot to width : the bar width in points colorup : the color of the lines where close >= open colordown : the color of the lines where close < open alpha : bar transparency return value is lineCollection, barCollection g@iÿÿÿÿigà?R‚iRƒR„t facecolorst edgecolors(i(gà?(iiii((iiii(iiii((iiii(R‡RˆRRR‹RyRdRRRŽRRRgR‘(RhR’R“R”R•RuRkRlR|tdeltaR–RRtbarVertsRRR—R?RRžRŸR‚R R¡R¢t barCollectiontminxR¦R§R¨R©((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pyt candlestick2Ãs< †X  J    ++    c Cs~tj|ƒ\}} } || | |f}tj|ƒ\}} } || | |f}i|t6|t6} gt||ƒD]4\} } | dkrx| dkrx| | | k^qx}|d}gt|ƒD]R\}}|dkrÉ||df|||f|||f||dff^qÉ}t|d|dd dd dd ƒ}dt|ƒt|ƒff}|j |ƒ|j ƒ|S(s½ Add a volume overlay to the current axes. The opens and closes are used to determine the color of the bar. -1 is missing. If a value is missing on one it must be missing on all ax : an Axes instance to plot to width : the bar width in points colorup : the color of the lines where close >= open colordown : the color of the lines where close < open alpha : bar transparency iÿÿÿÿg@iR«R¬iR„Rƒgà?(iiii((iiii(i(gà?(ii( RR‹RyRdR‡t enumerateRRRRRg(RhR’R“tvolumesRkRlRuR|R?RRžRŸRRR‚R­R–tvtbarsR¯R©((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytvolume_overlay s$  J e    c Cs+t||d |d|d||||ƒS(s  Add a volume overlay to the current axes. The closes are used to determine the color of the bar. -1 is missing. If a value is missing on one it must be missing on all ax : an Axes instance to plot to width : the bar width in points colorup : the color of the lines where close >= open colordown : the color of the lines where close < open alpha : bar transparency nb: first point is not displayed - it is used only for choosing the right color iÿÿÿÿi(R¶(RhR“R³RkRlRuR|((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytvolume_overlay25sc(CsÃtj|ƒ\}}}||||f}tj|ƒ\}}}||||f}i|t6|t6} t|Œ\} } } } }}gt| d | dƒD]4\}}|dkrž|dkrž| ||k^qž}|jd| | d| dkƒ|d}| d}g|D]B\}}}}}}|df||f||f|dff^q}|jjdd}|jj |j j }t ƒj ||ƒ}g|D]\}}}}}}|^q¤} g| D]}|df^qÏ}d} d}!t |d|d dd | d |!d |d |jƒ}"|"j|ƒt| ƒt| ƒ}#}$d}%tg|D]\}}}}}}|^q\ƒ}&|#|%f|$|&ff}'|j|'ƒ|j|"ƒ|jƒ|"S(s‡ Add a volume overlay to the current axes. quotes is a list of (d, open, close, high, low, volume) and close-open is used to determine the color of the bar kwarg width : the bar width in points colorup : the color of the lines where close1 >= close0 colordown : the color of the lines where close1 < close0 alpha : bar transparency iÿÿÿÿiig@gð?gR@gà?R«R¬R„RƒR…R†(i(gà?(iiii((iiii(RR‹RyRdR‡tinsertR‰RŠtbboxRvtviewLimR R:RRŒRRŽRRR‘Rg((RhRiRkRlRuR|R?RRžRŸtdatesR’R“R”R•R³tclose0tclose1R‚trighttleftRRRRRRRµtsxtsyt barTransformt offsetsBarsR R¡R¯R¥R¦R§R¨R©((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytvolume_overlay3KsF  R"  O+   1   RžtlcCsÂtj||ƒf}tj||ƒf}|d}| d} g|D]<} | dkrF| df| | f|| f|dff^qF} |jjdd} |jj|jj} tƒj| | ƒ}gt |ƒD]$\}} | dkrÔ|df^qÔ}t | d|d|dd d dd |d |j ƒ}|j |ƒdt |ƒ}}d}tg|D]} | dkra| ^qaƒ}||f||ff}|j|ƒ|jƒ|j|ƒ|S(sÄ Add a bar collection graph with height vals (-1 is missing). ax : an Axes instance to plot to width : the bar width in points alpha : bar transparency g@iÿÿÿÿigð?gR@R«R¬R„Rƒgà?R…R†(i(gà?(Rtto_rgbaR‰RŠR¹RvRºR R:R²RRŒRRRRRgR‘(RhR5RwRxRuR|R«R¬R¾R¿R´RµRÀRÁRÂR–RÃR¯R¥R¦R§R¨R©((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pyt index_bar”s2   I7   +   (7t__doc__RARXturllib2RthashlibRt ImportErrorRtnumpyR$t matplotlibRRtmatplotlib.datesRtmatplotlib.cbookRtmatplotlib.collectionsRRtmatplotlib.colorsRtmatplotlib.linesR R R tmatplotlib.patchesR tmatplotlib.transformsR t configdirRBRCRDRtobjecttint16tint8R!R&RyRdR=R*RVR\RrRRªR±R¶R·RÄRÇ(((sE/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/finance.pytsd             Z 6(:  D\ E+H