---
title: '用Python量化100个K线形态(2):反转形态锤子线【量化投资邢不行啊】'
source: 'https://www.youtube.com/watch?v=NA7h1DpYrbM'
video_id: 'NA7h1DpYrbM'
date: 2026-09-12
duration_sec: 137
channel: '量化投资邢不行啊'
---

# 用Python量化100个K线形态(2):反转形态锤子线【量化投资邢不行啊】

> Source: [用Python量化100个K线形态(2):反转形态锤子线【量化投资邢不行啊】](https://www.youtube.com/watch?v=NA7h1DpYrbM)

## Summary

This video tests the effectiveness of the hammer candlestick pattern in the Chinese A-share market using historical data and Python. The creator quantifies the pattern's conditions, runs a full backtest from 2007 to the present, and finds that the hammer pattern does not predict price increases, contrary to popular belief.

### Key Points

- **Introduction to candlestick pattern testing** [00:00] — The video begins a series testing classic candlestick patterns in A-shares using Python and full historical data.
- **Hammer pattern definition** [00:24] — The hammer is a reversal pattern appearing in a downtrend, with a long lower shadow (at least twice the body), almost no upper shadow, and the close below the next day's close.
- **Common belief vs. reality** [01:03] — Common belief says the hammer signals a downtrend end and a buy signal, but the video aims to verify this with data.
- **Quantification and testing method** [01:16] — The creator converts the pattern's vague description into precise, quantifiable conditions, then runs Python code on all A-share historical data.
- **Backtest results** [01:29] — Over 100,000 hammer patterns found since 2007. After the pattern, prices are more likely to fall, average returns are negative, and the profit/loss ratio is near 1.
- **Detailed performance metrics** [01:56] — For 1 to 20 days after the pattern, both the probability of price increase and average returns are poor, confirming the hammer is not a bottom-fishing signal in A-shares.
- **Data and code sharing** [02:08] — The creator offers to share the data and code via WeChat for viewers interested in replicating the analysis.

### Conclusion

The hammer candlestick pattern, despite popular belief, does not predict price increases in the A-share market. This data-driven approach provides a scientific reference for traders, showing that the pattern is not a reliable buy signal.

## Transcript

很多人炒股喜欢研究K线 他们认为不同K线形态暗含着未来股价的涨跌信息 比如认为起明星形态出现后股价会上涨 高位出现三只乌鸦形态预示着价格即将下跌等等等等
那么这些K线形态在A股到底真的有效吗? 我会用一系列的视频 逐一研究各个经典的K线形态 编写相应的Python代码 并用全量的历史数据来验证它们的效果 感兴趣的朋友可以点击关注,以防迷路
大家好,我是专注于量化投资的行不行 今天我们要介绍的K线形态是锤子线 它属于反转形态 这里的锤子不是大锤80,小锤40的那个锤子 更不是骂人的话哦 而是一个K线形态 我们结合这张图来介绍一下这个形态
大家看这一天的K线 形状上确实很像一个锤子 这也是它名字的由来 它有几个显著的特征 首先它必须出现在下跌区域当中 然后它的下影线是非常的长 一般来说得是本身柱体长度的两倍以上
然后上影线却几乎为零 收盘价必须低于第二天的收盘价 也就是说第二天必须上涨 满足以上条件呢 那么这根K线就是很典型的垂直线形态了 一般大家认为出现这种形态
就预示着下跌趋势的结束我们应该买入相应的股票这是一个买入信号那么这个信号到底是否有效呢为了验证我们就准备找出A股历史上所有的垂直线形态 再去看一下它之后的股价涨跌
这样最有说服力 那么为了达到我们的目的 我们需要尝试着把它模糊的描述语言 转化为精确的可量化的语言 然后使用Python把这些条件实现 找来所有股票的历史数据 运行一下代码 我们就可以看到统计结果
我们可以看到 A股历史上从2007年至今 总共出现10万多次垂直线的形态 这个数据量很大 足以说明问题 我们尝试统计它未来几天股价的涨跌 但是与预想不同的是 这个形态出现之后
股价大概率不会出现明显的上涨 反而出现了下跌 未来的平均收益也是负的 盈亏比也接近于1 大家感兴趣可以暂停看一下这个结果 我就不多加赘述了 我这里还列出了垂直线出现之后 未来1到20天的股价上涨概率和平均收益
表现也都是不佳 这也进一步说明了 垂直线这种形态在A股并不是超底信号 出现它之后还会继续大概率的下跌 大家下次再遇到的话就有科学的参考依据了 本期视频中用到的数据和代码
都是可以分享给大家的 可以加评论右下角或者这里面请取我的微信 都是可以直接发给你的 希望大家多多点赞和关注 后续我们还会分享更多的K线形态的验证结果
