Skip to content

Commit ebf653e

Browse files
committed
finance charts trailing slashes
1 parent b6c6e22 commit ebf653e

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

_posts/python/finance/2015-06-30-candlestick-charts.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
permalink: python/candlestick-charts
2+
permalink: python/candlestick-charts/
33
description: How to make interactive candlestick charts in Python with Plotly. Six examples of candlestick charts with Pandas, time series, and yahoo finance data.
44
name: Candlestick Charts
55
has_thumbnail: true
@@ -182,7 +182,7 @@ <h5 id="Custom-Candlestick-Colors">Custom Candlestick Colors<a class="anchor-lin
182182
<span class="c"># Make increasing ohlc sticks and customize their color and name</span>
183183
<span class="n">fig_increasing</span> <span class="o">=</span> <span class="n">FF</span><span class="o">.</span><span class="n">create_candlestick</span><span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">Open</span><span class="p">,</span> <span class="n">df</span><span class="o">.</span><span class="n">High</span><span class="p">,</span> <span class="n">df</span><span class="o">.</span><span class="n">Low</span><span class="p">,</span> <span class="n">df</span><span class="o">.</span><span class="n">Close</span><span class="p">,</span> <span class="n">dates</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="p">,</span>
184184
<span class="n">direction</span><span class="o">=</span><span class="s">&#39;increasing&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;AAPL&#39;</span><span class="p">,</span>
185-
<span class="n">marker</span><span class="o">=</span><span class="n">Marker</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;rgb(150, 200, 250)&#39;</span><span class="p">),</span>
185+
<span class="n">marker</span><span class="o">=</span><span class="n">Marker</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;rgb(150, 200, 250)&#39;</span><span class="p">),</span>
186186
<span class="n">line</span><span class="o">=</span><span class="n">Line</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;rgb(150, 200, 250)&#39;</span><span class="p">))</span>
187187

188188
<span class="c"># Make decreasing ohlc sticks and customize their color and name</span>
@@ -305,9 +305,9 @@ <h5 id="Simple-Example-Adding-a-Trace-to-a-Candlestick-Chart">Simple Example Add
305305

306306
<span class="c"># Create Line of open values</span>
307307
<span class="n">add_line</span> <span class="o">=</span> <span class="n">Scatter</span><span class="p">(</span>
308-
<span class="n">x</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="p">,</span>
309-
<span class="n">y</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">Open</span><span class="p">,</span>
310-
<span class="n">name</span><span class="o">=</span> <span class="s">&#39;Open Vals&#39;</span><span class="p">,</span>
308+
<span class="n">x</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="p">,</span>
309+
<span class="n">y</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">Open</span><span class="p">,</span>
310+
<span class="n">name</span><span class="o">=</span> <span class="s">&#39;Open Vals&#39;</span><span class="p">,</span>
311311
<span class="n">line</span><span class="o">=</span><span class="n">Line</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">)</span>
312312
<span class="p">)</span>
313313

@@ -366,7 +366,7 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
366366

367367
create_candlestick(open, high, low, close, dates=None, direction=&apos;both&apos;, **kwargs)
368368
BETA function that creates a candlestick chart
369-
369+
370370
:param (list) open: opening values
371371
:param (list) high: high values
372372
:param (list) low: low values
@@ -384,22 +384,22 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
384384
These kwargs describe other attributes about the ohlc Scatter trace
385385
such as the color or the legend name. For more information on valid
386386
kwargs call help(plotly.graph_objs.Scatter)
387-
387+
388388
:rtype (dict): returns a representation of candlestick chart figure.
389-
389+
390390
Example 1: Simple candlestick chart from a Pandas DataFrame
391391
&#96;&#96;&#96;
392392
import plotly.plotly as py
393393
from plotly.tools import FigureFactory as FF
394394
from datetime import datetime
395-
395+
396396
import pandas.io.data as web
397-
397+
398398
df = web.DataReader(&quot;aapl&quot;, &apos;yahoo&apos;, datetime(2007, 10, 1), datetime(2009, 4, 1))
399399
fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
400400
py.plot(fig, filename=&apos;finance/aapl-candlestick&apos;, validate=False)
401401
&#96;&#96;&#96;
402-
402+
403403
Example 2: Add text and annotations to the candlestick chart
404404
&#96;&#96;&#96;
405405
fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
@@ -420,46 +420,46 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
420420
})
421421
py.plot(fig, filename=&apos;finance/aapl-recession-candlestick&apos;, validate=False)
422422
&#96;&#96;&#96;
423-
423+
424424
Example 3: Customize the candlestick colors
425425
&#96;&#96;&#96;
426426
import plotly.plotly as py
427427
from plotly.tools import FigureFactory as FF
428428
from plotly.graph_objs import Line, Marker
429429
from datetime import datetime
430-
430+
431431
import pandas.io.data as web
432-
432+
433433
df = web.DataReader(&quot;aapl&quot;, &apos;yahoo&apos;, datetime(2008, 1, 1), datetime(2009, 4, 1))
434-
434+
435435
# Make increasing candlesticks and customize their color and name
436436
fig_increasing = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index,
437437
direction=&apos;increasing&apos;, name=&apos;AAPL&apos;,
438438
marker=Marker(color=&apos;rgb(150, 200, 250)&apos;),
439439
line=Line(color=&apos;rgb(150, 200, 250)&apos;))
440-
440+
441441
# Make decreasing candlesticks and customize their color and name
442442
fig_decreasing = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index,
443443
direction=&apos;decreasing&apos;,
444444
marker=Marker(color=&apos;rgb(128, 128, 128)&apos;),
445445
line=Line(color=&apos;rgb(128, 128, 128)&apos;))
446-
446+
447447
# Initialize the figure
448448
fig = fig_increasing
449-
449+
450450
# Add decreasing data with .extend()
451451
fig[&apos;data&apos;].extend(fig_decreasing[&apos;data&apos;])
452-
452+
453453
py.iplot(fig, filename=&apos;finance/aapl-candlestick-custom&apos;, validate=False)
454454
&#96;&#96;&#96;
455-
455+
456456
Example 4: Candlestick chart with datetime objects
457457
&#96;&#96;&#96;
458458
import plotly.plotly as py
459459
from plotly.tools import FigureFactory as FF
460-
460+
461461
from datetime import datetime
462-
462+
463463
# Add data
464464
open_data = [33.0, 33.3, 33.5, 33.0, 34.1]
465465
high_data = [33.1, 33.3, 33.6, 33.2, 34.8]
@@ -470,11 +470,11 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
470470
datetime(year=2013, month=12, day=10),
471471
datetime(year=2014, month=1, day=10),
472472
datetime(year=2014, month=2, day=10)]
473-
473+
474474
# Create ohlc
475475
fig = FF.create_candlestick(open_data, high_data,
476476
low_data, close_data, dates=dates)
477-
477+
478478
py.iplot(fig, filename=&apos;finance/simple-candlestick&apos;, validate=False)
479479
&#96;&#96;&#96;
480480

_posts/python/finance/2015-06-30-ohlc-charts.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
permalink: python/ohlc-charts
2+
permalink: python/ohlc-charts/
33
description: How to make interactive OHLC charts in Python with Plotly. Six examples of OHLC charts with Pandas, time series, and yahoo finance data.
44
title: Python OHLC Charts | plotly
55
has_thumbnail: true
@@ -310,7 +310,7 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
310310

311311
create_ohlc(open, high, low, close, dates=None, direction=&apos;both&apos;, **kwargs)
312312
BETA function that creates an ohlc chart
313-
313+
314314
:param (list) open: opening values
315315
:param (list) high: high values
316316
:param (list) low: low values
@@ -328,32 +328,32 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
328328
These kwargs describe other attributes about the ohlc Scatter trace
329329
such as the color or the legend name. For more information on valid
330330
kwargs call help(plotly.graph_objs.Scatter)
331-
331+
332332
:rtype (dict): returns a representation of an ohlc chart figure.
333-
333+
334334
Example 1: Simple OHLC chart from a Pandas DataFrame
335335
&#96;&#96;&#96;
336336
import plotly.plotly as py
337337
from plotly.tools import FigureFactory as FF
338-
338+
339339
import pandas.io.data as web
340-
340+
341341
df = web.DataReader(&quot;aapl&quot;, &apos;yahoo&apos;, datetime(2008, 8, 15), datetime(2008, 10, 15))
342342
fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index)
343-
343+
344344
py.plot(fig, filename=&apos;finance/aapl-ohlc&apos;)
345345
&#96;&#96;&#96;
346-
346+
347347
Example 2: Add text and annotations to the OHLC chart
348348
&#96;&#96;&#96;
349349
import plotly.plotly as py
350350
from plotly.tools import FigureFactory as FF
351-
351+
352352
import pandas.io.data as web
353-
353+
354354
df = web.DataReader(&quot;aapl&quot;, &apos;yahoo&apos;, datetime(2008, 8, 15), datetime(2008, 10, 15))
355355
fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index)
356-
356+
357357
# Update the fig - all options here: https://plot.ly/python/reference/#Layout
358358
fig[&apos;layout&apos;].update({
359359
&apos;title&apos;: &apos;The Great Recession&apos;,
@@ -370,47 +370,47 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
370370
&apos;showarrow&apos;: False, &apos;xanchor&apos;: &apos;left&apos;
371371
}]
372372
})
373-
373+
374374
py.plot(fig, filename=&apos;finance/aapl-recession-ohlc&apos;, validate=False)
375375
&#96;&#96;&#96;
376-
376+
377377
Example 3: Customize the OHLC colors
378378
&#96;&#96;&#96;
379379
import plotly.plotly as py
380380
from plotly.tools import FigureFactory as FF
381381
from plotly.graph_objs import Line, Marker
382382
from datetime import datetime
383-
383+
384384
import pandas.io.data as web
385-
385+
386386
df = web.DataReader(&quot;aapl&quot;, &apos;yahoo&apos;, datetime(2008, 1, 1), datetime(2009, 4, 1))
387-
387+
388388
# Make increasing ohlc sticks and customize their color and name
389389
fig_increasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index,
390390
direction=&apos;increasing&apos;, name=&apos;AAPL&apos;,
391391
line=Line(color=&apos;rgb(150, 200, 250)&apos;))
392-
392+
393393
# Make decreasing ohlc sticks and customize their color and name
394394
fig_decreasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index,
395395
direction=&apos;decreasing&apos;,
396396
line=Line(color=&apos;rgb(128, 128, 128)&apos;))
397-
397+
398398
# Initialize the figure
399399
fig = fig_increasing
400-
400+
401401
# Add decreasing data with .extend()
402402
fig[&apos;data&apos;].extend(fig_decreasing[&apos;data&apos;])
403-
403+
404404
py.iplot(fig, filename=&apos;finance/aapl-ohlc-colors&apos;, validate=False)
405405
&#96;&#96;&#96;
406-
406+
407407
Example 4: OHLC chart with datetime objects
408408
&#96;&#96;&#96;
409409
import plotly.plotly as py
410410
from plotly.tools import FigureFactory as FF
411-
411+
412412
from datetime import datetime
413-
413+
414414
# Add data
415415
open_data = [33.0, 33.3, 33.5, 33.0, 34.1]
416416
high_data = [33.1, 33.3, 33.6, 33.2, 34.8]
@@ -421,11 +421,11 @@ <h3 id="Reference">Reference<a class="anchor-link" href="#Reference">&#182;</a><
421421
datetime(year=2013, month=12, day=10),
422422
datetime(year=2014, month=1, day=10),
423423
datetime(year=2014, month=2, day=10)]
424-
424+
425425
# Create ohlc
426426
fig = FF.create_ohlc(open_data, high_data,
427427
low_data, close_data, dates=dates)
428-
428+
429429
py.iplot(fig, filename=&apos;finance/simple-ohlc&apos;, validate=False)
430430
&#96;&#96;&#96;
431431

0 commit comments

Comments
 (0)