cufflinks-绘制K线图

bash 复制代码
pip install cufflinks

绘制K线图

python 复制代码
import yfinance as yf
import cufflinks as cf

cf.set_config_file(offline=True, world_readable=True)

data = yf.download('QQQ', '2022-01-01', '2023-05-06')

qf = cf.QuantFig(data, title='QQQ', legend='top', name='QQQ')
qf.add_volume()
qf.add_ema(periods=20, column='Close', color='gray')

qf.add_trendline('2023-01-06','2023-03-13',on='low')
qf.add_resistance('2022-08-16',on='high',mode='toend')
qf.add_support('2022-10-13',on='low',mode='toend')

qf.iplot(up_color='green',down_color='red')

剔除周六周日

python 复制代码
fig = qf.figure(up_color='green',down_color='red')
fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])])
fig.show()

剔除所有非交易日

python 复制代码
import datetime

def date_range(begin, end):
    range_list = []
    d = begin
    delta = datetime.timedelta(days=1)
    while d <= end:
        range_list.append(d)
        d += delta
    return range_list

begin = datetime.date(2022,1,1)
end = datetime.datetime.now().date()
# 获取所有日期
dr = date_range(begin, end)


dr_str = list(map(lambda x: x.strftime("%Y-%m-%d"), dr))
# 获取所有交易日
data_str = list(map(lambda x: x.strftime("%Y-%m-%d"), data.index.tolist()))
# 获取所有非交易日
s = list(filter(lambda x: x not in data_str,dr_str))

fig = qf.figure(up_color='green',down_color='red')
fig.update_xaxes(
    rangebreaks=[
        dict(values=s)  # 剔除所有非交易日
    ]
)
fig.show()
相关推荐
TF男孩10 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在14 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP17 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户8356290780511 天前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i1 天前
python中类的基本结构、特殊属性于MRO理解
python
liwulin05061 天前
【ESP32-CAM】HELLO WORLD
python
Doris_20231 天前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_20231 天前
Python 模式匹配match case
前端·后端·python
这里有鱼汤1 天前
Python量化实盘踩坑指南:分钟K线没处理好,小心直接亏钱!
后端·python·程序员
大模型真好玩1 天前
深入浅出LangGraph AI Agent智能体开发教程(五)—LangGraph 数据分析助手智能体项目实战
人工智能·python·mcp