{ "cells": [ { "cell_type": "markdown", "id": "ec9be3b3", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Interactive Data Visualization\n", "\n", "Feng Li\n", "\n", "School of Statistics and Mathematics\n", "\n", "Central University of Finance and Economics\n", "\n", "[feng.li@cufe.edu.cn](mailto:feng.li@cufe.edu.cn)\n", "\n", "[https://feng.li/python](https://feng.li/python)" ] }, { "cell_type": "markdown", "id": "a24064f7", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Candlestick chart\n", "\n", "- The candlestick chart is a style of financial chart describing open, high, low and close for a given x coordinate (most likely time). \n", "\n", "- The boxes represent the spread between the open and close values and the lines represent the spread between the low and high values. \n", "\n", "- Sample points where the close value is higher (lower) then the open value are called increasing (decreasing). By default, increasing candles are drawn in green whereas decreasing are drawn in red." ] }, { "cell_type": "code", "execution_count": 1, "id": "7d79d1cb", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "## This allows for saving the notebook as interactive html\n", "import plotly.io as pio\n", "pio.renderers.default='notebook'" ] }, { "cell_type": "code", "execution_count": 2, "id": "3e8c4998", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
02015-02-17127.489998128.880005126.919998127.83000263152400122.905254106.741052117.927667129.114281Increasing
12015-02-18127.629997128.779999127.449997128.72000144891700123.760965107.842423118.940333130.038244Increasing
22015-02-19128.479996129.029999128.330002128.44999737362400123.501363108.894245119.889167130.884089Decreasing
32015-02-20128.619995129.500000128.050003129.50000048948400124.510914109.785449120.763500131.741551Increasing
42015-02-23130.020004133.000000129.660004133.00000070974100127.876074110.372516121.720167133.067817Increasing
....................................
5012017-02-10132.460007132.940002132.050003132.11999520065500132.119995114.494004124.498666134.503328Decreasing
5022017-02-13133.080002133.820007132.750000133.28999323035400133.289993114.820798125.205166135.589534Increasing
5032017-02-14133.470001135.089996133.250000135.02000432815500135.020004115.175718125.953499136.731280Increasing
5042017-02-15135.520004136.270004134.619995135.50999535501600135.509995115.545035126.723499137.901963Decreasing
5052017-02-16135.669998135.899994134.839996135.35000622118000135.350006116.203299127.504333138.805366Decreasing
\n", "

506 rows × 11 columns

\n", "
" ], "text/plain": [ " Date AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume \\\n", "0 2015-02-17 127.489998 128.880005 126.919998 127.830002 63152400 \n", "1 2015-02-18 127.629997 128.779999 127.449997 128.720001 44891700 \n", "2 2015-02-19 128.479996 129.029999 128.330002 128.449997 37362400 \n", "3 2015-02-20 128.619995 129.500000 128.050003 129.500000 48948400 \n", "4 2015-02-23 130.020004 133.000000 129.660004 133.000000 70974100 \n", ".. ... ... ... ... ... ... \n", "501 2017-02-10 132.460007 132.940002 132.050003 132.119995 20065500 \n", "502 2017-02-13 133.080002 133.820007 132.750000 133.289993 23035400 \n", "503 2017-02-14 133.470001 135.089996 133.250000 135.020004 32815500 \n", "504 2017-02-15 135.520004 136.270004 134.619995 135.509995 35501600 \n", "505 2017-02-16 135.669998 135.899994 134.839996 135.350006 22118000 \n", "\n", " AAPL.Adjusted dn mavg up direction \n", "0 122.905254 106.741052 117.927667 129.114281 Increasing \n", "1 123.760965 107.842423 118.940333 130.038244 Increasing \n", "2 123.501363 108.894245 119.889167 130.884089 Decreasing \n", "3 124.510914 109.785449 120.763500 131.741551 Increasing \n", "4 127.876074 110.372516 121.720167 133.067817 Increasing \n", ".. ... ... ... ... ... \n", "501 132.119995 114.494004 124.498666 134.503328 Decreasing \n", "502 133.289993 114.820798 125.205166 135.589534 Increasing \n", "503 135.020004 115.175718 125.953499 136.731280 Increasing \n", "504 135.509995 115.545035 126.723499 137.901963 Decreasing \n", "505 135.350006 116.203299 127.504333 138.805366 Decreasing \n", "\n", "[506 rows x 11 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "df = pd.read_csv('data/finance-charts-apple.csv')\n", "df" ] }, { "cell_type": "code", "execution_count": null, "id": "90397b0d", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "