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()
相关推荐
岁月宁静1 天前
五、《从零手撸 Agent》 — 什么是 Agent:从“会聊天”到“会做事”,差的就是一个循环
python·agent
梯度下降者1 天前
Python - 函数
python·高阶函数·可调用对象·functools·嵌套作用域
starzy19901 天前
深入理解Scala隐式参数:上下文流转
开发语言·python·scala
wuyk5551 天前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
kyle~1 天前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享1 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者1 天前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.2 天前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人2 天前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__2 天前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python