100天精通Python(可视化篇)——第99天:Pyecharts绘制多种炫酷K线图参数说明+代码实战

文章目录

  • 专栏导读
  • 一、K线图介绍
    • 1. 说明
    • 2. 应用场景
  • 二、配置说明
  • 三、K线图实战
    • 1. 普通k线图
    • 2. 添加辅助线
    • 3. k线图鼠标缩放
    • 4. 添加数据缩放滑块
    • 5. K线周期图表
  • 书籍推荐

专栏导读

🔥🔥本文已收录于《100天精通Python从入门到就业》:本专栏专门针对零基础和需要进阶提升的同学所准备的一套完整教学,从0到100的不断进阶深入,后续还有实战项目,轻松应对面试,专栏订阅地址:https://blog.csdn.net/yuan2019035055/category_11466020.html

  • 优点订阅限时9.9付费专栏进入千人全栈VIP答疑群,作者优先解答机会(代码指导、远程服务),群里大佬众多可以抱团取暖(大厂内推机会)
  • 专栏福利简历指导、招聘内推、每周送实体书、80G全栈学习视频、300本IT电子书:Python、Java、前端、大数据、数据库、算法、爬虫、数据分析、机器学习、面试题库等等

一、K线图介绍

1. 说明

K线图是一种常用的金融图表,用于展示股票、期货、外汇等金融市场的价格走势。它由四个关键价格组成,分别是开盘价(Open)、最高价(High)、最低价(Low)和收盘价(Close)。K线图通过绘制矩形或蜡烛形状的图形来表示每个交易周期(如一天、一周或一个月)的价格波动情况。

K线图的主要特点是能够直观地显示价格的波动情况和交易行为,包括价格的涨跌、高低点、趋势等。它提供了丰富的信息,可以帮助分析师和投资者进行技术分析和决策。

2. 应用场景

  1. 技术分析:K线图是技术分析的重要工具,通过观察K线图的形态和走势,可以判断市场的趋势,识别价格的支撑和阻力位,预测价格的变化趋势。
  2. 交易决策:基于K线图的技术分析,可以制定交易策略,如买入或卖出的时机、止损和止盈的设置等,帮助投资者做出更明智的决策。
  3. 风险管理:K线图可以帮助投资者识别市场的风险和机会,及时调整仓位和风险控制措施,降低投资风险。
  4. 市场监测:K线图可以用于监测市场的整体情况和行业走势,帮助投资者了解市场的热点和趋势,进行市场分析和预测。

总之,K线图是金融市场分析和决策的重要工具,广泛应用于股票、期货、外汇等金融市场,帮助投资者更好地理解市场走势和价格波动,做出明智的投资决策。

二、配置说明

在Pyecharts中,绘制K线图时可以使用以下配置类来自定义图表的样式和交互效果:

  1. Kline:K线图类,用于创建K线图对象。
  2. opts.AxisOpts:坐标轴配置类,用于设置横坐标轴和纵坐标轴的样式和属性。
  3. opts.DataZoomOpts:数据缩放配置类,用于设置数据缩放的样式和属性。
  4. opts.SplitAreaOpts:分割区域配置类,用于设置分割区域的样式和属性。
  5. opts.AreaStyleOpts:区域样式配置类,用于设置区域的填充颜色和透明度。
  6. opts.ItemStyleOpts:图表元素样式配置类,用于设置图表元素的颜色、边框颜色等属性。
  7. opts.MarkLineOpts:标线配置类,用于设置标线的样式和属性。
  8. opts.MarkLineItem:标线项类,用于设置标线的类型和数值。
  9. opts.MarkPointOpts:标点配置类,用于设置标点的样式和属性。
  10. opts.TooltipOpts:提示框配置类,用于设置提示框的样式和属性。
  11. opts.TitleOpts:标题配置类,用于设置图表的标题样式和属性。
  12. opts.InitOpts:初始化配置类,用于设置图表的初始化属性。
  13. opts.RenderOpts:渲染初始化配置类,用于设置图表的渲染初始化属性。

以上是一些常用的配置类,可以通过实例化这些类并设置相应的属性来自定义K线图的样式和交互效果。根据具体需求,可以灵活使用这些配置类来定制自己想要的K线图。

三、K线图实战

1. 普通k线图

下面我们绘制一个最简单的K线图:

from pyecharts import options as opts
from pyecharts.charts import Kline

# 准备K线图的数据
x_data = ["2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04", "2023-01-05"]
y_data = [
    [100, 120, 80, 110],  # 第一天的K线数据:开盘价、最高价、最低价、收盘价
    [110, 130, 100, 120],  # 第二天的K线数据
    [120, 140, 90, 110],  # 第三天的K线数据
    [110, 130, 100, 120],  # 第四天的K线数据
    [120, 140, 90, 110],  # 第五天的K线数据
]

# 创建K线图对象
c = (
    Kline()
    .add_xaxis(xaxis_data=x_data)  # 设置x轴数据
    .add_yaxis(
        series_name="K线图",  # 设置数据系列的名称
        y_axis=y_data,  # 设置y轴数据
        itemstyle_opts=opts.ItemStyleOpts(color="#ec0000", color0="#00da3c"),  # 设置K线图的颜色
    )
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(is_scale=True),  # 设置x轴选项,使其自适应
        yaxis_opts=opts.AxisOpts(is_scale=True),  # 设置y轴选项,使其自适应
        title_opts=opts.TitleOpts(title="普通K线图"),  # 设置标题选项
    )
)

# 渲染图表
c.render("kline.html")

c.render_notebook()

运行结果:

2. 添加辅助线

这里我们可以添加辅助线:

import random
from pyecharts import options as opts
from pyecharts.charts import Kline

# 随机数据
data = []
# 使用嵌套的循环结构生成双层随机嵌套列表
for _ in range(30):
    inner_list = []
    # 内层列表个数
    for _ in range(4):
        random_num = random.randint(2000, 2500)
        inner_list.append(random_num)
    data.append(inner_list)

# 创建K线图对象
c = (
    Kline()
    # 添加横坐标数据
    .add_xaxis(["2023/7/{}".format(i + 1) for i in range(31)])
    # 添加纵坐标数据
    .add_yaxis(
        "kline",
        data,
        # 设置标线配置项,标记最大值
        markline_opts=opts.MarkLineOpts(
            data=[opts.MarkLineItem(type_="max", value_dim="close")]
        ),
    )
    # 设置全局配置项
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(is_scale=True),  # 设置横坐标��配置项,is_scale=True表示自适应刻度
        yaxis_opts=opts.AxisOpts(
            is_scale=True,  # 设置纵坐标轴配置项,is_scale=True表示自适应刻度
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True,  # 设置分割区域配置项,is_show=True表示显示分割区域
                areastyle_opts=opts.AreaStyleOpts(opacity=1)  # 设置分割区域样式配置项,opacity=1表示不透明
            ),
        ),
        title_opts=opts.TitleOpts(title="K线图添加辅助线"),  # 设置标题配置项
    )
)


# 渲染为HTML文件
c.render("K线图添加辅助线.html")

# 在Jupyter Notebook中显示图表
c.render_notebook()

运行结果:

3. k线图鼠标缩放

当数据量很大的时候,我们可以不全部展示,可以通过鼠标缩放:

import random
from pyecharts import options as opts
from pyecharts.charts import Kline

# 随机数据
data = []
# 使用嵌套的循环结构生成双层随机嵌套列表
for _ in range(30):
    inner_list = []
    # 内层列表个数
    for _ in range(4):
        random_num = random.randint(2000, 2500)
        inner_list.append(random_num)
    data.append(inner_list)

# 创建K线图对象
c = (
    Kline()
    # 添加横坐标数据
    .add_xaxis(["2023/7/{}".format(i + 1) for i in range(31)])
    # 添加纵坐标数据
    .add_yaxis(
        "kline",
        data,
        # 设置图表元素样式
        itemstyle_opts=opts.ItemStyleOpts(
            color="#ec0000",
            color0="#00da3c",
            border_color="#8A0000",
            border_color0="#008F28",
        ),
    )
    # 设置全局配置项
    .set_global_opts(
        # 设置横坐标轴配置项,is_scale=True表示自适应刻度
        xaxis_opts=opts.AxisOpts(is_scale=True),
        # 设置纵坐标轴配置项,is_scale=True表示自适应刻度
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            # 设置分割区域配置项,is_show=True表示显示分割区域
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True,
                # 设置分割区域样式配置项,opacity=1表示不透明
                areastyle_opts=opts.AreaStyleOpts(opacity=1)
            ),
        ),
        # 设置数据缩放配置项,type_="inside"表示内置缩放
        datazoom_opts=[opts.DataZoomOpts(type_="inside")],
        # 设置标题配置项,title="K线图鼠标缩放"为标题内容
        title_opts=opts.TitleOpts(title="K线图鼠标缩放"),
    )
)

# 渲染为HTML文件
c.render("K线图鼠标缩放.html")

# 在Jupyter Notebook中显示图表
c.render_notebook()

运行结果:

4. 添加数据缩放滑块

可以在K线图底部添加数据缩放滑块用于缩放数据:

import random
from pyecharts import options as opts
from pyecharts.charts import Kline

# 随机数据
data = []
# 使用嵌套的循环结构生成双层随机嵌套列表
for _ in range(30):
    inner_list = []
    # 内层列表个数
    for _ in range(4):
        random_num = random.randint(2000, 2500)
        inner_list.append(random_num)
    data.append(inner_list)

# 创建K线图对象
c = (
    Kline()
    # 添加横坐标数据
    .add_xaxis(["2023/7/{}".format(i + 1) for i in range(31)])
    # 添加纵坐标数据
    .add_yaxis("kline", data)
    # 设置全局配置项
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(is_scale=True),  # 设置横坐标轴配置项,is_scale=True表示自适应刻度
        yaxis_opts=opts.AxisOpts(
            is_scale=True,  # 设置纵坐标轴配置项,is_scale=True表示自适应刻度
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True,  # 设置分割区域配置项,is_show=True表示显示分割区域
                areastyle_opts=opts.AreaStyleOpts(opacity=1)  # 设置分割区域样式配置项,opacity=1表示不透明
            ),
        ),
        datazoom_opts=[opts.DataZoomOpts()],  # 设置数据缩放配置项位置在底部偏下
        title_opts=opts.TitleOpts(title="K线图数据缩放滑块"),  # 设置标题配置项
    )
)

# 渲染为HTML文件
c.render("K线图数据缩放滑块.html")

# 在Jupyter Notebook中显示图表
c.render_notebook()

运行结果:

5. K线周期图表

下面我们绘制一个K线周期图表(开源):

from typing import List, Sequence, Union
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Kline, Line, Bar, Grid

# 数据
echarts_data = [
    ["2022-10-16", 18.4, 18.58, 18.33, 18.79, 67.00, 1, 0.04, 0.11, 0.09],
    ["2022-10-19", 18.56, 18.25, 18.19, 18.56, 55.00, 0, -0.00, 0.08, 0.09],
    ["2022-10-20", 18.3, 18.22, 18.05, 18.41, 37.00, 0, 0.01, 0.09, 0.09],
    ["2022-10-21", 18.18, 18.69, 18.02, 18.98, 89.00, 0, 0.03, 0.10, 0.08],
    ["2022-10-22", 18.42, 18.29, 18.22, 18.48, 43.00, 0, -0.06, 0.05, 0.08],
    ["2022-10-23", 18.26, 18.19, 18.08, 18.36, 46.00, 0, -0.10, 0.03, 0.09],
    ["2022-10-26", 18.33, 18.07, 17.98, 18.35, 65.00, 0, -0.15, 0.03, 0.10],
    ["2022-10-27", 18.08, 18.04, 17.88, 18.13, 37.00, 0, -0.19, 0.03, 0.12],
    ["2022-10-28", 17.96, 17.86, 17.82, 17.99, 35.00, 0, -0.24, 0.03, 0.15],
    ["2022-10-29", 17.85, 17.81, 17.8, 17.93, 27.00, 0, -0.24, 0.06, 0.18],
    ["2022-10-30", 17.79, 17.93, 17.78, 18.08, 43.00, 0, -0.22, 0.11, 0.22],
    ["2022-11-02", 17.78, 17.83, 17.78, 18.04, 27.00, 0, -0.20, 0.15, 0.25],
    ["2022-11-03", 17.84, 17.9, 17.84, 18.06, 34.00, 0, -0.12, 0.22, 0.28],
    ["2022-11-04", 17.97, 18.36, 17.85, 18.39, 62.00, 0, -0.00, 0.30, 0.30],
    ["2022-11-05", 18.3, 18.57, 18.18, 19.08, 177.00, 0, 0.07, 0.33, 0.30],
    ["2022-11-06", 18.53, 18.68, 18.3, 18.71, 95.00, 0, 0.12, 0.35, 0.29],
    ["2022-11-09", 18.75, 19.08, 18.75, 19.98, 202.00, 1, 0.16, 0.35, 0.27],
    ["2022-11-10", 18.85, 18.64, 18.56, 18.99, 85.00, 0, 0.09, 0.29, 0.25],
    ["2022-11-11", 18.64, 18.44, 18.31, 18.64, 50.00, 0, 0.06, 0.27, 0.23],
    ["2022-11-12", 18.55, 18.27, 18.17, 18.57, 43.00, 0, 0.05, 0.25, 0.23],
    ["2022-11-13", 18.13, 18.14, 18.09, 18.34, 35.00, 0, 0.05, 0.24, 0.22],
    ["2022-11-16", 18.01, 18.1, 17.93, 18.17, 34.00, 0, 0.07, 0.25, 0.21],
    ["2022-11-17", 18.2, 18.14, 18.08, 18.45, 58.00, 0, 0.11, 0.25, 0.20],
    ["2022-11-18", 18.23, 18.16, 18.0, 18.45, 47.00, 0, 0.13, 0.25, 0.19],
    ["2022-11-19", 18.08, 18.2, 18.05, 18.25, 32.00, 0, 0.15, 0.24, 0.17],
    ["2022-11-20", 18.15, 18.15, 18.11, 18.29, 36.00, 0, 0.13, 0.21, 0.15],
    ["2022-11-23", 18.16, 18.19, 18.12, 18.34, 47.00, 0, 0.11, 0.18, 0.13],
    ["2022-11-24", 18.23, 17.88, 17.7, 18.23, 62.00, 0, 0.03, 0.13, 0.11],
    ["2022-11-25", 17.85, 17.73, 17.56, 17.85, 66.00, 0, -0.03, 0.09, 0.11],
    ["2022-11-26", 17.79, 17.53, 17.5, 17.92, 63.00, 0, -0.10, 0.06, 0.11],
    ["2022-11-27", 17.51, 17.04, 16.9, 17.51, 67.00, 0, -0.16, 0.05, 0.13],
    ["2022-11-30", 17.07, 17.2, 16.98, 17.32, 55.00, 0, -0.12, 0.09, 0.15],
    ["2022-12-01", 17.28, 17.11, 16.91, 17.28, 39.00, 0, -0.09, 0.12, 0.16],
    ["2022-12-02", 17.13, 17.91, 17.05, 17.99, 102.00, 0, -0.01, 0.17, 0.18],
    ["2022-12-03", 17.8, 17.78, 17.61, 17.98, 71.00, 0, -0.09, 0.14, 0.18],
    ["2022-12-04", 17.6, 17.25, 17.13, 17.69, 51.00, 0, -0.18, 0.10, 0.19],
    ["2022-12-07", 17.2, 17.39, 17.15, 17.45, 43.00, 0, -0.19, 0.12, 0.22],
    ["2022-12-08", 17.3, 17.42, 17.18, 17.62, 45.00, 0, -0.23, 0.13, 0.24],
    ["2022-12-09", 17.33, 17.39, 17.32, 17.59, 44.00, 0, -0.29, 0.13, 0.28],
    ["2022-12-10", 17.39, 17.26, 17.21, 17.65, 44.00, 0, -0.37, 0.13, 0.32],
    ["2022-12-11", 17.23, 16.92, 16.66, 17.26, 114.00, 1, -0.44, 0.15, 0.37],
    ["2022-12-14", 16.75, 17.06, 16.5, 17.09, 94.00, 0, -0.44, 0.21, 0.44],
    ["2022-12-15", 17.03, 17.03, 16.9, 17.06, 46.00, 0, -0.44, 0.28, 0.50],
    ["2022-12-16", 17.08, 16.96, 16.87, 17.09, 30.00, 0, -0.40, 0.36, 0.56],
    ["2022-12-17", 17.0, 17.1, 16.95, 17.12, 50.00, 0, -0.30, 0.47, 0.62],
    ["2022-12-18", 17.09, 17.52, 17.04, 18.06, 156.00, 0, -0.14, 0.59, 0.66],
    ["2022-12-21", 17.43, 18.23, 17.35, 18.45, 152.00, 1, 0.02, 0.69, 0.68],
    ["2022-12-22", 18.14, 18.27, 18.06, 18.32, 94.00, 0, 0.08, 0.72, 0.68],
    ["2022-12-23", 18.28, 18.19, 18.17, 18.71, 108.00, 0, 0.13, 0.73, 0.67],
    ["2022-12-24", 18.18, 18.14, 18.01, 18.31, 37.00, 0, 0.19, 0.74, 0.65],
    ["2022-12-25", 18.22, 18.33, 18.2, 18.36, 48.00, 0, 0.26, 0.75, 0.62],
    ["2022-12-28", 18.35, 17.84, 17.8, 18.39, 48.00, 0, 0.27, 0.72, 0.59],
    ["2022-12-29", 17.83, 17.94, 17.71, 17.97, 36.00, 0, 0.36, 0.73, 0.55],
    ["2022-12-30", 17.9, 18.26, 17.55, 18.3, 71.00, 1, 0.43, 0.71, 0.50],
    ["2022-12-31", 18.12, 17.99, 17.91, 18.33, 72.00, 0, 0.40, 0.63, 0.43],
    ["2023-01-04", 17.91, 17.28, 17.16, 17.95, 37.00, 1, 0.34, 0.55, 0.38],
    ["2023-01-05", 17.17, 17.23, 17.0, 17.55, 51.00, 0, 0.37, 0.51, 0.33],
    ["2023-01-06", 17.2, 17.31, 17.06, 17.33, 31.00, 0, 0.37, 0.46, 0.28],
    ["2023-01-07", 17.15, 16.67, 16.51, 17.15, 19.00, 0, 0.30, 0.37, 0.22],
    ["2023-01-08", 16.8, 16.81, 16.61, 17.06, 60.00, 0, 0.29, 0.32, 0.18],
    ["2023-01-11", 16.68, 16.04, 16.0, 16.68, 65.00, 0, 0.20, 0.24, 0.14],
    ["2023-01-12", 16.03, 15.98, 15.88, 16.25, 46.00, 0, 0.20, 0.21, 0.11],
    ["2023-01-13", 16.21, 15.87, 15.78, 16.21, 57.00, 0, 0.20, 0.18, 0.08],
    ["2023-01-14", 15.55, 15.89, 15.52, 15.96, 42.00, 0, 0.20, 0.16, 0.05],
    ["2023-01-15", 15.87, 15.48, 15.45, 15.92, 34.00, 1, 0.17, 0.11, 0.02],
    ["2023-01-18", 15.39, 15.42, 15.36, 15.7, 26.00, 0, 0.21, 0.10, -0.00],
    ["2023-01-19", 15.58, 15.71, 15.35, 15.77, 38.00, 0, 0.25, 0.09, -0.03],
    ["2023-01-20", 15.56, 15.52, 15.24, 15.68, 38.00, 0, 0.23, 0.05, -0.07],
    ["2023-01-21", 15.41, 15.3, 15.28, 15.68, 35.00, 0, 0.21, 0.00, -0.10],
    ["2023-01-22", 15.48, 15.28, 15.13, 15.49, 30.00, 0, 0.21, -0.02, -0.13],
    ["2023-01-25", 15.29, 15.48, 15.2, 15.49, 21.00, 0, 0.20, -0.06, -0.16],
    ["2023-01-26", 15.33, 14.86, 14.78, 15.39, 30.00, 0, 0.12, -0.13, -0.19],
    ["2023-01-27", 14.96, 15.0, 14.84, 15.22, 51.00, 0, 0.13, -0.14, -0.20],
    ["2023-01-28", 14.96, 14.72, 14.62, 15.06, 25.00, 0, 0.10, -0.17, -0.22],
    ["2023-01-29", 14.75, 14.99, 14.62, 15.08, 36.00, 0, 0.13, -0.17, -0.24],
    ["2023-02-01", 14.98, 14.72, 14.48, 15.18, 27.00, 0, 0.10, -0.21, -0.26],
    ["2023-02-02", 14.65, 14.85, 14.65, 14.95, 18.00, 0, 0.11, -0.21, -0.27],
    ["2023-02-03", 14.72, 14.67, 14.55, 14.8, 23.00, 0, 0.10, -0.24, -0.29],
    ["2023-02-04", 14.79, 14.88, 14.69, 14.93, 22.00, 0, 0.13, -0.24, -0.30],
    ["2023-02-05", 14.9, 14.86, 14.78, 14.93, 16.00, 0, 0.12, -0.26, -0.32],
    ["2023-02-15", 14.5, 14.66, 14.47, 14.82, 19.00, 0, 0.11, -0.28, -0.34],
    ["2023-02-16", 14.77, 14.94, 14.72, 15.05, 26.00, 0, 0.14, -0.28, -0.35],
    ["2023-02-17", 14.95, 15.03, 14.88, 15.07, 38.00, 0, 0.12, -0.31, -0.37],
    ["2023-02-18", 14.95, 14.9, 14.87, 15.06, 28.00, 0, 0.07, -0.35, -0.39],
    ["2023-02-19", 14.9, 14.75, 14.68, 14.94, 22.00, 0, 0.03, -0.38, -0.40],
    ["2023-02-22", 14.88, 15.01, 14.79, 15.11, 38.00, 1, 0.01, -0.40, -0.40],
    ["2023-02-23", 15.01, 14.83, 14.72, 15.01, 24.00, 0, -0.09, -0.45, -0.40],
    ["2023-02-24", 14.75, 14.81, 14.67, 14.87, 21.00, 0, -0.17, -0.48, -0.39],
    ["2023-02-25", 14.81, 14.25, 14.21, 14.81, 51.00, 1, -0.27, -0.50, -0.37],
    ["2023-02-26", 14.35, 14.45, 14.28, 14.57, 28.00, 0, -0.26, -0.46, -0.33],
    ["2023-02-29", 14.43, 14.56, 14.04, 14.6, 48.00, 0, -0.25, -0.41, -0.29],
    ["2023-03-01", 14.56, 14.65, 14.36, 14.78, 32.00, 0, -0.21, -0.36, -0.25],
    ["2023-03-02", 14.79, 14.96, 14.72, 14.97, 60.00, 0, -0.13, -0.29, -0.22],
    ["2023-03-03", 14.95, 15.15, 14.91, 15.19, 53.00, 1, -0.05, -0.23, -0.21],
    ["2023-03-04", 15.14, 15.97, 15.02, 16.02, 164.00, 1, 0.06, -0.17, -0.20],
    ["2023-03-07", 15.9, 15.78, 15.65, 16.0, 41.00, 0, 0.04, -0.19, -0.21],
    ["2023-03-08", 15.78, 15.96, 15.21, 15.99, 45.00, 0, 0.05, -0.19, -0.21],
    ["2023-03-09", 15.73, 16.05, 15.41, 16.08, 74.00, 0, 0.03, -0.20, -0.22],
    ["2023-03-10", 15.82, 15.66, 15.65, 15.98, 19.00, 0, -0.02, -0.23, -0.22],
    ["2023-03-11", 15.59, 15.76, 15.42, 15.78, 32.00, 0, 0.01, -0.22, -0.22],
    ["2023-03-14", 15.78, 15.72, 15.65, 16.04, 31.00, 0, 0.03, -0.20, -0.22],
    ["2023-03-15", 15.81, 15.86, 15.6, 15.99, 35.00, 0, 0.10, -0.18, -0.23],
    ["2023-03-16", 15.88, 16.42, 15.79, 16.45, 123.00, 0, 0.17, -0.16, -0.24],
    ["2023-03-17", 16.39, 16.23, 16.11, 16.4, 46.00, 0, 0.14, -0.20, -0.26],
    ["2023-03-18", 16.39, 16.17, 16.04, 16.4, 59.00, 0, 0.13, -0.22, -0.28],
    ["2023-03-21", 16.21, 16.22, 16.11, 16.44, 50.00, 0, 0.12, -0.24, -0.30],
    ["2023-03-22", 16.27, 16.19, 16.16, 16.42, 33.00, 0, 0.10, -0.27, -0.32],
    ["2023-03-23", 16.26, 16.18, 16.18, 16.29, 19.00, 0, 0.08, -0.30, -0.33],
    ["2023-03-24", 16.18, 16.11, 16.01, 16.23, 23.00, 0, 0.04, -0.33, -0.35],
    ["2023-03-25", 16.12, 16.13, 16.1, 16.2, 15.00, 0, 0.00, -0.35, -0.35],
    ["2023-03-28", 16.15, 15.85, 15.81, 16.2, 22.00, 0, -0.06, -0.38, -0.35],
    ["2023-03-29", 15.9, 15.79, 15.76, 16.05, 19.00, 0, -0.06, -0.37, -0.34],
    ["2023-03-30", 15.79, 16.24, 15.78, 16.3, 29.00, 0, -0.03, -0.35, -0.33],
    ["2023-03-31", 16.3, 16.09, 16.02, 16.35, 25.00, 0, -0.07, -0.37, -0.33],
    ["2023-04-01", 16.18, 16.27, 15.98, 16.3, 38.00, 0, -0.08, -0.36, -0.32],
    ["2023-04-05", 16.13, 16.34, 16.07, 16.37, 39.00, 0, -0.13, -0.37, -0.31],
    ["2023-04-06", 16.21, 16.26, 16.19, 16.35, 30.00, 0, -0.20, -0.39, -0.29],
    ["2023-04-07", 16.32, 16.1, 16.05, 16.35, 29.00, 1, -0.26, -0.39, -0.26],
    ["2023-04-08", 16.0, 16.16, 15.98, 16.21, 22.00, 0, -0.28, -0.37, -0.23],
    ["2023-04-11", 16.16, 16.31, 16.15, 16.57, 31.00, 0, -0.30, -0.33, -0.19],
    ["2023-04-12", 16.41, 16.29, 16.12, 16.41, 17.00, 0, -0.31, -0.30, -0.14],
    ["2023-04-13", 16.39, 16.48, 16.0, 16.68, 40.00, 0, -0.30, -0.25, -0.10],
    ["2023-04-14", 16.5, 16.46, 16.37, 16.68, 22.00, 0, -0.27, -0.19, -0.06],
    ["2023-04-15", 16.56, 16.93, 16.46, 17.04, 58.00, 0, -0.20, -0.12, -0.02],
    ["2023-04-18", 16.76, 17.06, 16.72, 17.27, 50.00, 0, -0.16, -0.07, 0.01],
    ["2023-04-19", 17.21, 17.11, 17.02, 17.23, 30.00, 0, -0.12, -0.02, 0.03],
    ["2023-04-20", 17.11, 17.33, 16.8, 17.36, 78.00, 0, -0.04, 0.03, 0.05],
    ["2023-04-21", 17.27, 17.69, 17.17, 17.93, 79.00, 0, 0.05, 0.08, 0.06],
    ["2023-04-22", 17.6, 17.87, 17.56, 18.02, 55.00, 0, 0.09, 0.10, 0.05],
    ["2023-04-25", 17.75, 17.9, 17.41, 17.96, 39.00, 1, 0.11, 0.09, 0.04],
    ["2023-04-26", 17.81, 17.91, 17.6, 17.95, 39.00, 0, 0.12, 0.08, 0.02],
    ["2023-04-27", 17.9, 17.88, 17.81, 17.95, 25.00, 0, 0.12, 0.06, 0.00],
    ["2023-04-28", 17.93, 17.88, 17.67, 17.93, 28.00, 0, 0.11, 0.04, -0.01],
    ["2023-04-29", 17.87, 17.75, 17.73, 17.92, 19.00, 0, 0.08, 0.01, -0.03],
    ["2023-05-03", 17.79, 17.7, 17.56, 17.85, 35.00, 0, 0.05, -0.01, -0.04],
    ["2023-05-04", 17.7, 17.65, 17.59, 17.71, 24.00, 0, 0.02, -0.04, -0.05],
    ["2023-05-05", 17.65, 17.62, 17.46, 17.7, 20.00, 0, -0.03, -0.06, -0.05],
    ["2023-05-06", 17.62, 17.32, 17.3, 17.65, 29.00, 0, -0.10, -0.09, -0.05],
    ["2023-05-09", 17.33, 17.3, 17.21, 17.45, 23.00, 0, -0.13, -0.10, -0.03],
    ["2023-05-10", 17.11, 17.04, 16.98, 17.41, 28.00, 0, -0.15, -0.09, -0.01],
    ["2023-05-11", 17.06, 17.15, 17.06, 17.32, 20.00, 0, -0.12, -0.05, 0.01],
    ["2023-05-12", 17.02, 17.46, 17.02, 17.58, 26.00, 0, -0.07, -0.01, 0.03],
    ["2023-05-13", 17.41, 17.57, 17.34, 17.62, 23.00, 0, -0.06, 0.01, 0.03],
    ["2023-05-16", 17.55, 17.5, 17.48, 17.64, 37.00, 0, -0.06, 0.01, 0.04],
    ["2023-05-17", 17.49, 17.48, 17.39, 17.53, 13.00, 0, -0.03, 0.03, 0.05],
    ["2023-05-18", 17.41, 17.82, 17.39, 17.87, 46.00, 0, 0.01, 0.06, 0.06],
    ["2023-05-19", 17.74, 17.81, 17.67, 17.86, 17.00, 0, -0.01, 0.05, 0.05],
    ["2023-05-20", 17.76, 17.88, 17.7, 17.93, 14.00, 0, -0.03, 0.04, 0.06],
    ["2023-05-23", 17.88, 17.52, 17.48, 17.97, 16.00, 0, -0.09, 0.02, 0.06],
    ["2023-05-24", 17.51, 17.33, 17.32, 17.51, 8.00, 0, -0.09, 0.03, 0.07],
    ["2023-05-25", 17.59, 17.55, 17.44, 17.59, 10.00, 0, -0.03, 0.07, 0.08],
    ["2023-05-26", 17.5, 17.69, 17.5, 17.8, 12.00, 0, 0.00, 0.09, 0.09],
    ["2023-05-27", 17.77, 17.66, 17.62, 17.77, 7.00, 0, 0.03, 0.10, 0.09],
    ["2023-05-30", 17.75, 17.84, 17.62, 17.87, 20.00, 0, 0.08, 0.12, 0.08],
    ["2023-05-31", 17.88, 18.0, 17.81, 18.03, 41.00, 0, 0.10, 0.12, 0.07],
    ["2023-06-01", 18.09, 17.83, 17.73, 18.09, 22.00, 0, 0.08, 0.10, 0.06],
    ["2023-06-02", 17.82, 17.73, 17.66, 17.88, 10.00, 0, 0.07, 0.08, 0.05],
    ["2023-06-03", 17.8, 17.78, 17.71, 17.83, 9.00, 0, 0.08, 0.08, 0.04],
    ["2023-06-06", 17.73, 17.64, 17.56, 17.83, 12.00, 0, 0.07, 0.06, 0.03],
    ["2023-06-07", 17.76, 17.8, 17.59, 17.87, 11.00, 0, 0.08, 0.06, 0.02],
    ["2023-06-08", 17.75, 17.77, 17.65, 17.84, 9.00, 0, 0.04, 0.03, 0.01],
    ["2023-06-13", 17.58, 17.32, 17.29, 17.79, 16.00, 0, -0.02, -0.01, 0.00],
    ["2023-06-14", 17.33, 17.38, 17.29, 17.5, 10.00, 0, -0.01, 0.00, 0.00],
    ["2023-06-15", 17.25, 17.39, 17.25, 17.46, 18.00, 0, 0.00, 0.01, 0.00],
    ["2023-06-16", 17.26, 17.4, 17.26, 17.46, 22.00, 0, 0.01, 0.01, 0.00],
    ["2023-06-17", 17.38, 17.5, 17.37, 17.67, 13.00, 0, 0.03, 0.02, 0.00],
    ["2023-06-20", 17.62, 17.51, 17.42, 17.63, 15.00, 0, 0.03, 0.01, -0.00],
    ["2023-06-21", 17.53, 17.54, 17.5, 17.7, 11.00, 0, 0.02, 0.00, -0.01],
    ["2023-06-22", 17.5, 17.5, 17.46, 17.6, 10.00, 0, -0.01, -0.01, -0.01],
    ["2023-06-23", 17.52, 17.26, 17.24, 17.53, 16.00, 0, -0.04, -0.03, -0.01],
    ["2023-06-24", 17.26, 17.25, 17.18, 17.38, 60.00, 0, -0.03, -0.02, -0.00],
    ["2023-06-27", 17.25, 17.28, 17.18, 17.33, 19.00, 0, -0.01, -0.00, 0.00],
    ["2023-06-28", 17.25, 17.29, 17.21, 17.32, 13.00, 0, 0.02, 0.01, 0.00],
    ["2023-06-29", 17.31, 17.45, 17.27, 17.49, 21.00, 0, 0.07, 0.04, 0.00],
    ["2023-06-30", 17.47, 17.5, 17.39, 17.55, 17.00, 0, 0.11, 0.04, -0.01],
    ["2023-07-01", 17.5, 17.63, 17.49, 17.66, 10.00, 0, 0.14, 0.05, -0.03],
    ["2023-07-04", 17.63, 17.72, 17.63, 17.92, 17.00, 0, 0.16, 0.03, -0.05],
    ["2023-07-05", 17.79, 17.56, 17.45, 17.79, 18.00, 0, 0.14, 0.00, -0.07],
    ["2023-07-06", 17.53, 17.42, 17.31, 17.54, 20.00, 0, 0.14, -0.02, -0.09],
    ["2023-07-07", 17.41, 17.51, 17.35, 17.52, 15.00, 0, 0.16, -0.03, -0.11],
    ["2023-07-08", 17.5, 17.39, 17.35, 17.51, 15.00, 0, 0.16, -0.05, -0.13],
    ["2023-07-11", 17.49, 17.48, 17.4, 17.55, 16.00, 0, 0.17, -0.07, -0.15],
    ["2023-07-12", 17.48, 17.71, 17.46, 17.75, 25.00, 0, 0.16, -0.10, -0.18],
    ["2023-07-13", 17.13, 17.05, 17.02, 17.39, 28.00, 0, 0.07, -0.17, -0.20],
    ["2023-07-14", 17.07, 17.09, 17.0, 17.16, 12.00, 0, 0.08, -0.17, -0.21],
    ["2023-07-15", 17.08, 17.14, 17.08, 17.17, 11.00, 0, 0.09, -0.18, -0.22],
    ["2023-07-18", 17.15, 17.26, 17.13, 17.49, 24.00, 0, 0.10, -0.19, -0.23],
    ["2023-07-19", 17.26, 17.12, 17.09, 17.33, 13.00, 0, 0.07, -0.21, -0.25],
    ["2023-07-20", 17.1, 17.07, 17.02, 17.14, 11.00, 0, 0.06, -0.23, -0.26],
    ["2023-07-21", 17.07, 17.24, 17.07, 17.27, 14.00, 0, 0.07, -0.23, -0.27],
    ["2023-07-22", 17.25, 17.08, 17.03, 17.25, 10.00, 0, 0.04, -0.26, -0.28],
    ["2023-07-25", 17.09, 17.12, 17.01, 17.18, 8.00, 0, 0.04, -0.26, -0.28],
    ["2023-07-26", 17.05, 17.17, 17.05, 17.2, 11.00, 0, 0.04, -0.27, -0.29],
    ["2023-07-27", 17.2, 17.37, 16.89, 17.38, 32.00, 0, 0.02, -0.28, -0.29],
    ["2023-07-28", 17.19, 17.14, 17.09, 17.29, 19.00, 0, -0.04, -0.32, -0.30],
    ["2023-07-29", 17.15, 17.16, 17.04, 17.23, 12.00, 0, -0.08, -0.33, -0.29],
    ["2023-08-01", 17.15, 17.18, 17.1, 17.24, 19.00, 0, -0.13, -0.34, -0.28],
    ["2023-08-02", 17.21, 17.15, 17.12, 17.25, 9.00, 0, -0.19, -0.36, -0.26],
    ["2023-08-03", 17.08, 17.07, 17.01, 17.16, 9.00, 0, -0.25, -0.36, -0.24],
    ["2023-08-04", 17.11, 17.06, 16.98, 17.12, 11.00, 1, -0.29, -0.35, -0.20],
    ["2023-08-05", 17.06, 17.1, 17.05, 17.15, 16.00, 0, -0.33, -0.32, -0.16],
    ["2023-08-08", 17.14, 17.13, 17.07, 17.15, 13.00, 0, -0.35, -0.29, -0.11],
    ["2023-08-09", 17.13, 17.17, 17.1, 17.2, 25.00, 0, -0.35, -0.24, -0.06],
    ["2023-08-10", 17.17, 17.28, 17.15, 17.29, 18.00, 0, -0.31, -0.17, -0.01],
    ["2023-08-11", 17.3, 17.45, 17.26, 17.87, 31.00, 0, -0.24, -0.09, 0.03],
    ["2023-08-12", 17.51, 17.99, 17.47, 18.0, 44.00, 0, -0.14, -0.00, 0.07],
    ["2023-08-15", 18.1, 18.42, 18.02, 18.99, 81.00, 0, -0.09, 0.04, 0.09],
    ["2023-08-16", 18.64, 18.31, 18.12, 18.87, 60.00, 0, -0.10, 0.05, 0.10],
    ["2023-08-17", 18.43, 18.4, 18.31, 18.68, 21.00, 0, -0.08, 0.08, 0.11],
    ["2023-08-18", 18.33, 18.23, 18.13, 18.65, 32.00, 0, -0.07, 0.09, 0.13],
    ["2023-08-19", 18.34, 18.62, 18.31, 18.75, 39.00, 0, 0.00, 0.14, 0.14],
    ["2023-08-22", 18.62, 18.69, 18.51, 18.8, 20.00, 0, 0.01, 0.14, 0.13],
    ["2023-08-23", 18.61, 18.66, 18.52, 19.0, 28.00, 0, 0.01, 0.14, 0.13],
    ["2023-08-24", 18.66, 18.62, 18.43, 18.7, 19.00, 0, 0.00, 0.13, 0.13],
    ["2023-08-25", 18.57, 18.51, 18.19, 18.64, 19.00, 0, -0.00, 0.13, 0.13],
    ["2023-08-26", 18.49, 18.55, 18.44, 18.6, 16.00, 0, 0.01, 0.13, 0.13],
    ["2023-08-29", 18.46, 18.27, 18.03, 18.48, 20.00, 0, 0.01, 0.13, 0.13],
    ["2023-08-30", 18.24, 18.44, 18.23, 18.52, 19.00, 0, 0.07, 0.17, 0.13],
    ["2023-08-31", 18.36, 18.63, 18.36, 18.76, 15.00, 0, 0.13, 0.18, 0.12],
    ["2023-09-01", 18.6, 18.62, 18.55, 18.78, 15.00, 0, 0.16, 0.18, 0.10],
    ["2023-09-02", 18.52, 18.68, 18.48, 18.72, 17.00, 0, 0.19, 0.17, 0.08],
    ["2023-09-05", 18.68, 18.75, 18.57, 18.82, 19.00, 0, 0.20, 0.15, 0.05],
    ["2023-09-06", 18.75, 18.51, 18.43, 18.78, 17.00, 0, 0.18, 0.11, 0.02],
    ["2023-09-07", 18.51, 18.56, 18.4, 18.62, 17.00, 0, 0.17, 0.08, -0.00],
    ["2023-09-08", 18.58, 18.53, 18.48, 18.63, 8.00, 0, 0.13, 0.04, -0.03],
    ["2023-09-09", 18.52, 18.33, 18.31, 18.57, 8.00, 0, 0.06, -0.02, -0.05],
    ["2023-09-12", 18.16, 17.9, 17.81, 18.18, 28.00, 0, -0.02, -0.07, -0.06],
    ["2023-09-13", 17.91, 17.91, 17.9, 18.08, 13.00, 0, -0.05, -0.08, -0.05],
    ["2023-09-14", 17.99, 17.54, 17.48, 17.99, 22.00, 0, -0.09, -0.09, -0.05],
    ["2023-09-19", 17.55, 17.81, 17.55, 17.88, 16.00, 0, -0.06, -0.06, -0.03],
    ["2023-09-20", 17.8, 17.74, 17.67, 17.85, 10.00, 0, -0.06, -0.05, -0.02],
    ["2023-09-21", 17.75, 17.88, 17.75, 17.95, 7.00, 0, -0.03, -0.03, -0.02],
    ["2023-09-22", 17.99, 17.97, 17.88, 18.17, 12.00, 0, -0.02, -0.02, -0.01],
    ["2023-09-23", 17.99, 17.98, 17.93, 18.09, 13.00, 0, -0.01, -0.01, -0.01],
    ["2023-09-26", 17.91, 18.0, 17.85, 18.09, 14.00, 0, -0.00, -0.01, -0.01],
    ["2023-09-27", 17.97, 18.07, 17.94, 18.1, 10.00, 0, 0.00, -0.01, -0.01],
    ["2023-09-28", 18.06, 17.89, 17.83, 18.06, 10.00, 0, -0.00, -0.01, -0.01],
    ["2023-09-29", 17.96, 18.0, 17.92, 18.07, 10.00, 0, 0.03, 0.01, -0.01],
    ["2023-09-30", 17.96, 18.0, 17.95, 18.1, 8.00, 0, 0.06, 0.02, -0.01],
    ["2023-10-10", 18.03, 18.3, 18.03, 18.38, 19.00, 0, 0.11, 0.04, -0.02],
    ["2023-10-11", 18.33, 18.33, 18.26, 18.49, 12.00, 0, 0.10, 0.02, -0.04],
    ["2023-10-12", 18.28, 18.15, 18.1, 18.31, 10.00, 0, 0.07, -0.02, -0.05],
    ["2023-10-13", 18.15, 18.09, 18.05, 18.21, 10.00, 0, 0.06, -0.03, -0.06],
    ["2023-10-14", 18.1, 18.1, 18.0, 18.15, 12.00, 0, 0.04, -0.05, -0.07],
    ["2023-10-17", 18.07, 17.86, 17.83, 18.1, 12.00, 0, 0.01, -0.07, -0.08],
    ["2023-10-18", 17.86, 17.93, 17.84, 17.99, 14.00, 0, 0.03, -0.07, -0.08],
    ["2023-10-19", 17.93, 17.88, 17.83, 18.05, 11.00, 0, 0.03, -0.07, -0.08],
    ["2023-10-20", 17.9, 17.89, 17.83, 17.98, 12.00, 0, 0.05, -0.06, -0.09],
    ["2023-10-21", 17.91, 17.91, 17.82, 17.93, 12.00, 0, 0.07, -0.06, -0.09],
    ["2023-10-24", 17.93, 18.31, 17.86, 18.42, 29.00, 0, 0.11, -0.05, -0.10],
    ["2023-10-25", 18.31, 18.13, 18.09, 18.46, 19.00, 0, 0.06, -0.09, -0.12],
    ["2023-10-26", 18.12, 17.97, 17.95, 18.15, 14.00, 0, 0.02, -0.12, -0.13],
    ["2023-10-27", 18.06, 17.81, 17.77, 18.06, 21.00, 0, -0.01, -0.13, -0.13],
    ["2023-10-28", 17.8, 17.9, 17.8, 18.05, 20.00, 0, -0.01, -0.13, -0.13],
    ["2023-10-31", 17.87, 17.86, 17.72, 17.96, 12.00, 0, -0.02, -0.14, -0.13],
    ["2023-11-01", 17.87, 17.98, 17.79, 17.99, 18.00, 0, -0.03, -0.14, -0.12],
    ["2023-11-02", 17.86, 17.84, 17.76, 17.94, 30.00, 0, -0.06, -0.15, -0.12],
    ["2023-11-03", 17.83, 17.93, 17.79, 17.97, 27.00, 0, -0.07, -0.14, -0.11],
    ["2023-11-04", 17.9, 17.91, 17.87, 18.0, 26.00, 0, -0.09, -0.15, -0.10],
    ["2023-11-07", 17.91, 17.89, 17.85, 17.93, 20.00, 0, -0.11, -0.14, -0.09],
    ["2023-11-08", 17.92, 17.99, 17.89, 18.06, 26.00, 0, -0.12, -0.13, -0.07],
    ["2023-11-09", 18.0, 17.89, 17.77, 18.08, 34.00, 0, -0.15, -0.13, -0.06],
    ["2023-11-10", 17.95, 18.0, 17.94, 18.11, 27.00, 0, -0.15, -0.11, -0.03],
    ["2023-11-11", 17.95, 18.02, 17.93, 18.08, 27.00, 0, -0.17, -0.10, -0.01],
    ["2023-11-14", 18.0, 18.04, 17.95, 18.25, 35.00, 0, -0.18, -0.08, 0.01],
    ["2023-11-15", 18.1, 18.18, 18.03, 18.24, 25.00, 0, -0.18, -0.06, 0.04],
    ["2023-11-16", 18.23, 18.12, 18.05, 18.29, 23.00, 0, -0.21, -0.04, 0.06],
    ["2023-11-17", 18.11, 18.12, 18.01, 18.14, 27.00, 0, -0.21, -0.01, 0.09],
    ["2023-11-18", 18.12, 18.1, 18.03, 18.16, 18.00, 0, -0.19, 0.03, 0.12],
    ["2023-11-21", 18.08, 18.34, 18.08, 18.68, 41.00, 0, -0.13, 0.08, 0.15],
    ["2023-11-22", 18.37, 18.37, 18.28, 18.49, 52.00, 0, -0.09, 0.12, 0.17],
    ["2023-11-23", 18.4, 18.84, 18.37, 18.9, 66.00, 0, -0.02, 0.17, 0.18],
    ["2023-11-24", 18.77, 18.74, 18.61, 18.97, 26.00, 0, -0.02, 0.17, 0.18],
    ["2023-11-25", 18.8, 18.99, 18.66, 19.02, 40.00, 0, -0.01, 0.18, 0.19],
    ["2023-11-28", 19.1, 18.65, 18.52, 19.2, 85.00, 0, -0.06, 0.16, 0.19],
    ["2023-11-29", 18.65, 18.75, 18.51, 18.76, 49.00, 0, -0.06, 0.17, 0.20],
    ["2023-11-30", 18.76, 18.55, 18.47, 18.82, 39.00, 0, -0.08, 0.17, 0.21],
    ["2023-12-01", 18.55, 18.49, 18.41, 18.64, 53.00, 0, -0.06, 0.19, 0.22],
    ["2023-12-02", 18.53, 18.49, 18.24, 18.54, 48.00, 0, -0.02, 0.21, 0.23],
    ["2023-12-05", 18.39, 18.66, 18.34, 18.67, 50.00, 0, 0.03, 0.25, 0.23],
    ["2023-12-06", 18.66, 18.6, 18.57, 18.78, 31.00, 0, 0.08, 0.26, 0.23],
    ["2023-12-07", 18.65, 18.62, 18.58, 18.71, 12.00, 0, 0.15, 0.29, 0.21],
    ["2023-12-08", 18.67, 18.76, 18.62, 18.88, 26.00, 0, 0.25, 0.32, 0.19],
    ["2023-12-09", 18.76, 19.2, 18.75, 19.34, 62.00, 0, 0.34, 0.33, 0.16],
    ["2023-12-12", 19.16, 19.25, 18.9, 19.65, 79.00, 1, 0.34, 0.28, 0.11],
    ["2023-12-13", 19.09, 18.88, 18.81, 19.2, 24.00, 0, 0.27, 0.20, 0.06],
    ["2023-12-14", 18.8, 18.82, 18.8, 19.14, 32.00, 0, 0.23, 0.13, 0.02],
    ["2023-12-15", 18.73, 18.24, 18.2, 18.73, 36.00, 0, 0.13, 0.05, -0.01],
    ["2023-12-16", 18.24, 18.18, 18.12, 18.4, 24.00, 0, 0.10, 0.02, -0.03],
    ["2023-12-19", 18.15, 18.01, 17.93, 18.18, 24.00, 0, 0.06, -0.02, -0.05],
    ["2023-12-20", 17.99, 17.79, 17.7, 17.99, 29.00, 1, 0.02, -0.05, -0.05],
    ["2023-12-21", 17.83, 17.81, 17.77, 17.98, 30.00, 0, 0.00, -0.05, -0.06],
    ["2023-12-22", 17.85, 17.72, 17.65, 17.85, 21.00, 0, -0.03, -0.07, -0.06],
    ["2023-12-23", 17.77, 17.6, 17.54, 17.77, 18.00, 0, -0.04, -0.08, -0.05],
    ["2023-12-26", 17.56, 17.75, 17.39, 17.77, 16.00, 0, -0.04, -0.07, -0.05],
    ["2023-12-27", 17.73, 17.71, 17.65, 17.82, 10.00, 0, -0.06, -0.07, -0.04],
    ["2023-12-28", 17.72, 17.62, 17.49, 17.77, 26.00, 0, -0.09, -0.07, -0.03],
    ["2023-12-29", 17.6, 17.49, 17.43, 17.62, 28.00, 0, -0.09, -0.06, -0.02],
    ["2023-12-30", 17.53, 17.6, 17.47, 17.61, 22.00, 0, -0.05, -0.03, -0.01],
    ["2017-01-03", 17.6, 17.92, 17.57, 17.98, 28.00, 1, 0.00, 0.00, 0.00],
]


def split_data(origin_data) -> dict:
    datas = []
    times = []
    vols = []
    macds = []
    difs = []
    deas = []

    for i in range(len(origin_data)):
        datas.append(origin_data[i][1:])
        times.append(origin_data[i][0:1][0])
        vols.append(origin_data[i][5])
        macds.append(origin_data[i][7])
        difs.append(origin_data[i][8])
        deas.append(origin_data[i][9])
    vols = [int(v) for v in vols]

    return {
        "datas": datas,
        "times": times,
        "vols": vols,
        "macds": macds,
        "difs": difs,
        "deas": deas,
    }


def split_data_part() -> Sequence:
    mark_line_data = []
    idx = 0
    tag = 0
    vols = 0
    for i in range(len(data["times"])):
        if data["datas"][i][5] != 0 and tag == 0:
            idx = i
            vols = data["datas"][i][4]
            tag = 1
        if tag == 1:
            vols += data["datas"][i][4]
        if data["datas"][i][5] != 0 or tag == 1:
            mark_line_data.append(
                [
                    {
                        "xAxis": idx,
                        "yAxis": float("%.2f" % data["datas"][idx][3])
                        if data["datas"][idx][1] > data["datas"][idx][0]
                        else float("%.2f" % data["datas"][idx][2]),
                        "value": vols,
                    },
                    {
                        "xAxis": i,
                        "yAxis": float("%.2f" % data["datas"][i][3])
                        if data["datas"][i][1] > data["datas"][i][0]
                        else float("%.2f" % data["datas"][i][2]),
                    },
                ]
            )
            idx = i
            vols = data["datas"][i][4]
            tag = 2
        if tag == 2:
            vols += data["datas"][i][4]
        if data["datas"][i][5] != 0 and tag == 2:
            mark_line_data.append(
                [
                    {
                        "xAxis": idx,
                        "yAxis": float("%.2f" % data["datas"][idx][3])
                        if data["datas"][i][1] > data["datas"][i][0]
                        else float("%.2f" % data["datas"][i][2]),
                        "value": str(float("%.2f" % (vols / (i - idx + 1)))) + " M",
                    },
                    {
                        "xAxis": i,
                        "yAxis": float("%.2f" % data["datas"][i][3])
                        if data["datas"][i][1] > data["datas"][i][0]
                        else float("%.2f" % data["datas"][i][2]),
                    },
                ]
            )
            idx = i
            vols = data["datas"][i][4]
    return mark_line_data


def calculate_ma(day_count: int):
    result: List[Union[float, str]] = []

    for i in range(len(data["times"])):
        if i < day_count:
            result.append("-")
            continue
        sum_total = 0.0
        for j in range(day_count):
            sum_total += float(data["datas"][i - j][1])
        result.append(abs(float("%.2f" % (sum_total / day_count))))
    return result


def draw_chart():
    kline = (
        Kline()
        .add_xaxis(xaxis_data=data["times"])
        .add_yaxis(
            series_name="",
            y_axis=data["datas"],
            itemstyle_opts=opts.ItemStyleOpts(
                color="#ef232a",
                color0="#14b143",
                border_color="#ef232a",
                border_color0="#14b143",
            ),
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkPointItem(type_="min", name="最小值"),
                ]
            ),
            markline_opts=opts.MarkLineOpts(
                label_opts=opts.LabelOpts(
                    position="middle", color="blue", font_size=15
                ),
                data=split_data_part(),
                symbol=["circle", "none"],
            ),
        )
        .set_series_opts(
            markarea_opts=opts.MarkAreaOpts(is_silent=True, data=split_data_part())
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="K线周期图表", pos_left="0"),
            xaxis_opts=opts.AxisOpts(
                type_="category",
                is_scale=True,
                boundary_gap=False,
                axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
                split_number=20,
                min_="dataMin",
                max_="dataMax",
            ),
            yaxis_opts=opts.AxisOpts(
                is_scale=True, splitline_opts=opts.SplitLineOpts(is_show=True)
            ),
            tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line"),
            datazoom_opts=[
                opts.DataZoomOpts(
                    is_show=False, type_="inside", xaxis_index=[0, 0], range_end=100
                ),
                opts.DataZoomOpts(
                   # is_show=True, xaxis_index=[0, 1], pos_top="100%", range_end=100
                ),
                opts.DataZoomOpts(is_show=False, xaxis_index=[0, 2], range_end=100),
            ],
            # 三个图的 axis 连在一块
            # axispointer_opts=opts.AxisPointerOpts(
            #     is_show=True,
            #     link=[{"xAxisIndex": "all"}],
            #     label=opts.LabelOpts(background_color="#777"),
            # ),
        )
    )

    kline_line = (
        Line()
        .add_xaxis(xaxis_data=data["times"])
        .add_yaxis(
            series_name="MA5",
            y_axis=calculate_ma(day_count=5),
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=1,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=1,
                split_number=3,
                axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=True),
            ),
        )
    )
    # Overlap Kline + Line
    overlap_kline_line = kline.overlap(kline_line)

    # Bar-1
    bar_1 = (
        Bar()
        .add_xaxis(xaxis_data=data["times"])
        .add_yaxis(
            series_name="Volumn",
            y_axis=data["vols"],
            xaxis_index=1,
            yaxis_index=1,
            label_opts=opts.LabelOpts(is_show=False),
            # 根据 echarts demo 的原版是这么写的
            # itemstyle_opts=opts.ItemStyleOpts(
            #     color=JsCode("""
            #     function(params) {
            #         var colorList;
            #         if (data.datas[params.dataIndex][1]>data.datas[params.dataIndex][0]) {
            #           colorList = '#ef232a';
            #         } else {
            #           colorList = '#14b143';
            #         }
            #         return colorList;
            #     }
            #     """)
            # )
            # 改进后在 grid 中 add_js_funcs 后变成如下
            itemstyle_opts=opts.ItemStyleOpts(
                color=JsCode(
                    """
                function(params) {
                    var colorList;
                    if (barData[params.dataIndex][1] > barData[params.dataIndex][0]) {
                        colorList = '#ef232a';
                    } else {
                        colorList = '#14b143';
                    }
                    return colorList;
                }
                """
                )
            ),
        )
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=1,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        )
    )

    # Bar-2 (Overlap Bar + Line)
    bar_2 = (
        Bar()
        .add_xaxis(xaxis_data=data["times"])
        .add_yaxis(
            series_name="MACD",
            y_axis=data["macds"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
            itemstyle_opts=opts.ItemStyleOpts(
                color=JsCode(
                    """
                        function(params) {
                            var colorList;
                            if (params.data >= 0) {
                              colorList = '#ef232a';
                            } else {
                              colorList = '#14b143';
                            }
                            return colorList;
                        }
                        """
                )
            ),
        )
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=2,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=2,
                split_number=4,
                axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=True),
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        )
    )

    line_2 = (
        Line()
        .add_xaxis(xaxis_data=data["times"])
        .add_yaxis(
            series_name="DIF",
            y_axis=data["difs"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="DIF",
            y_axis=data["deas"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(legend_opts=opts.LegendOpts(is_show=False))
    )
    # 最下面的柱状图和折线图
    overlap_bar_line = bar_2.overlap(line_2)

    # 最后的 Grid
    grid_chart = Grid()

    # 这个是为了把 data.datas 这个数据写入到 html 中,还没想到怎么跨 series 传值
    # demo 中的代码也是用全局变量传的
    grid_chart.add_js_funcs("var barData = {}".format(data["datas"]))

    # K线图和 MA5 的折线图
    grid_chart.add(
        overlap_kline_line,
        grid_opts=opts.GridOpts(pos_left="3%", pos_right="1%", height="60%"),
    )
    # Volumn 柱状图
    grid_chart.add(
        bar_1,
        grid_opts=opts.GridOpts(
            pos_left="3%", pos_right="1%", pos_top="71%", height="10%"
        ),
    )
    # MACD DIFS DEAS
    grid_chart.add(
        overlap_bar_line,
        grid_opts=opts.GridOpts(
            pos_left="3%", pos_right="1%", pos_top="82%", height="14%"
        ),
    )
    grid_chart.render("professional_kline_chart.html")


if __name__ == "__main__":
    data = split_data(origin_data=echarts_data)
    draw_chart()

运行结果:

书籍推荐

  • 购书链接京东:https://item.jd.com/14055900.html

抽奖送书老规矩(不点赞收藏中奖无效):注意记得关注博主不然中奖了还不知道!!!

  • 1. 点赞收藏文章
  • 2. 评论区留言:人生苦短,我用Python!!!(留言才能进入奖池,每人最多留言三条)
  • 3. 周六八点爬虫抽奖5人

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年9月6日
下一篇 2023年9月6日

相关推荐