balipour

Variance Ratio Test [pig]

In Finance, people usually assume the price follows a random walk or more precisely geometric Brownian motion. In 1988, Lo and MacKinlay came up with the variance ratio test to refute the random walk hypothesis and efficient market hypothesis. The variance ratio test is a simple test for market efficiency, autocorrelation, and whether price follows a random walk.

In random walks, variables should be iid (independently and identically distributed). Therefore, the variance should be constantly scaled throughout the samples. For example, variance sampled in four-bar should be close to four times the variance sampled in one bar. The variance ratio test tests if the variances are scaled constantly.

First, we calculate one period sampled variance as the basis variance of the test. Then we compute variance sampled by 2 bar, 4 bar, 8 bar, 16 bar and 32 bar. We use power of 2 as the sample period here, but any multiple periods are fine as the variance scaling all applies.

After we calculated all the sample variance, we scale the higher sampled period variance in terms of basis variance (one-period sampled variance). We can't actually divide K from the K period sampled variance directly here to scale the variance because it's biased. The following chart shows unbiased scaling variances. After we finished scaling, the higher period and lower period variance should have pretty close values. The closer price is to random walk, the smaller difference they will have.

The variance ratio is just the higher period sampled scaled variance / lower period sampled variance. Because their values are close, the ratio should be around 1. And the variance ratio test will test how different the ratio is from 1. Lo and Mackinley suggest (variance ratio - 1) follows a standard normal distribution with mean 0 and standard deviation σ.
We can get σ from sample size t and period K. σ^2 = 2*(2k-1)* ( k-1 )/3k*T(The formula we use here doesn't take into account heteroscedasticity). Once we know the standard deviation. We can get the z score from dividing σ from vr -1.

We can apply the standard normal test statistics on the z scores. The user can choose the critical value based on the significance. Default is 5% and critical value 1.96. This means when the z score is above 1.96 or below -1.96, the variance ratio is significantly different from 1 and we can reject the random walk hypothesis. And if the z score is between 1.96 and -1.96. We are 95% confident that the price follows a random walk.

As we have different scaled period, some periods might have a significant a z score some might not. Generally if one of the z score is significant we reject the RWH. When all the period is displayed, you can see the different behavior of short term and long term variance. Shorter period like 2 period sample is likely to trend, longer period is likely to show mean reversion. This is very clear when it's applied in a long lookback period. We also recommend users to use lookback period longer than 2*K. Eg: 4-period VRT requires 8 bars of lookback.
When it's applied to 1000 lookback, price(log returns) shows mean reversion behaviour in the long run. (All sample periods show red)

When "Show Multiple Variance Ratio" is ticked off. The indicator shows only one line of variance ratio. And the sampling period can be adjusted in "Period Multiplier". Flash in the background suggests when price doesn't follow a random walk.

In order to test how useful is the variance ratio test, I used the VRT on the random walk data I simulated based on geometric Brownian motion. The data I simulated has a 0.001 drift and constant volatility . It's not a true random walk because I used a pseudo-random number generator in the script, not true random numbers. But It's pretty close. The result shows VRT is between the critical value most of the time which suggests it follows a random walk.

For people that are too lazy to read math. Here is how to use this indicator:

Red means possible negative autocorrelation, mean reversion.
Blue means possible positive autocorrelation, trend.
(2 Period Variance ratio is the 1st order autocorrelation)
(We suggest users open indicator name labels and values on the side so they can see which period variance ratio is significant. )

Above or below critical levels means price does not follow a random walk. Between critical levels means price follows a random walk.
(Main purpose of this test)
版本注释: Added vrt1 to vrt5 sampling period manual enter input function.
从常用脚本中删除 添加到指标收藏
Our Website🅱🅰🐷: https://bapigindicator.com

Sign up on our website to get access to our indicators.

Join Our Discord for further discussions: https://discord.gg/pe5M6kt

评论

Life after BAPIG:

( •_•)>⌐■-■

(⌐■_■)
+8 回复
Impressive! your skills kill!
+7 回复
balipour ricmos
@ricmos, thanks
回复
The description on its own is amazing, not to mention the indicator.

Awesome work bapig team! Thank you!
+6 回复
balipour SemiQuasi
@SemiQuasi, it's great when a great coder gets it. Thank you.
+1 回复
BAPIG offering free material that equates to quant firms. Thank you both!
+5 回复
balipour LolzerTheMaster
@LolzerTheMaster, thank you. Any time.
回复
"Lazy" a bit harsh I'd say. People also have lives bruh lol. We do the math, so you don't have to (or need too). But, Also these things will allow you to still get down and dirty with the math if you're anything like us.
Good luck trading , your tools couldn't be any better. This is a movement, Thank you all.
+5 回复
@balipour, one hurdle I face when reading an exhaustive text is floundering for definitions, wikipedia is great because they offer links to words that are liable to trip you up. Most people just glaze over and ask are we there yet (you know what I mean), but I love learning and understanding it +this is the stuff I live for.
+1 回复
balipour UnknownUnicorn6941191
@UnknownUnicorn6941191, no worries bro. we get it.
回复
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 如何运作 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 私人消息 在线聊天 退出