Random walk vs Real price statistic

Posted By: kujo

Random walk vs Real price statistic - 02/18/18 18:13

Hello,

I've tried RandomWalk script that goes with Zorro (just changed dates a little bit). It compares distribution of price movements of EUR/USD price curve and random price curve:
Quote:
function run()
{
StartDate=2013;
EndDate=2017;
PlotHeight1 = 320;

vars Price = series(price());
int num = NumRiseFall(Price,20);
int x = 3*num;
if(num < 0) x += 3; // eliminate the 0 gap
plotBar("Price",x,num,1,SUM+BARS,RED);

vars Random = series(0);
Random[0] = Random[1] + random();
num = NumRiseFall(Random,20);
x = 3*num+1;
if(num < 0) x += 3;
plotBar("Random",x,0,1,SUM+BARS,BLUE);
}


The following chart is generated:

The Black Book says:
Quote:
In the chart, the height of the bars is equivalent to the number of rising or falling price series. The red bars are from the real EUR/USD price curve above, the blue bars from a curve of random numbers. The numbers on the x axis are the duration of a price movement in hours, at the right side for rising, and at the left side for falling prices. The height of a bar indicates how frequently such a rising or falling series occurs in the curve. For instance, the bar above the 3 at the right shows how often the price was rising for 3 hours in sequence. If prices would move totally random, the red bars had the same heights as the blue bars. We can see that this is not the case: rising/falling series of 3, 4, 5, or more hours occur more often in the real price curve than in the random data. 1-hour series - a price rising in the first and falling in the second hour, or vice versa - occur less often. Real prices tend to keep their direction. This effect causes the famous "fat tails" of price distributions. It exists with most assets and time frames, like minutes or days instead of hours.



However, this effect almost or completely disappears in case of Close prices: if series(priceClose()) is used instead of series(price()).
For example:


I wonder how it could be explained?
Thank you!
Posted By: Hredot

Re: Random walk vs Real price statistic - 02/18/18 18:28

Imagine a curve that goes up by two price units in a second, then goes down by one price unit the next second. Repeat that many times. In this situation NumRiseFall will return a streak of one time step for going up as well as going down, suggesting that they be equal, but clearly overall the price is rising on average.

Considering close prices has more random jitter in it, whereas price is the average over the entire bar. Your observation shows that at one bar time-length the price on average is not really random, while below one bar time-length random noise seems to take over.

Time scale of measurements makes the difference here, I think.

And yes, it is true that Close prices are also equally spaced in time compared to price. Still, the difference is that price takes into account a collection of many measurements within a bar, while close is just a single measurement - which is enough to enlarge noise to signal.
Posted By: kujo

Re: Random walk vs Real price statistic - 02/18/18 20:02

It makes sense! Thank you, Hredot!
Posted By: kujo

Re: Random walk vs Real price statistic - 02/18/18 20:40

Jcl, in your book you write:
Quote:
With a probability slightly above randomness – about 52%, dependent on the observed price curve – the price will also rise during the third bar, allowing us to sell at a profit. Is this already the path to quick riches? Unfortunately not – even if we could eliminate all trading costs. The markets deny too easy profits. The 48% losing trades lose a bit more than the 52% winning trades, this way equalizing profit and loss. You can later test this with simple scripts and different assets.


I wonder how you get 52% win rate. My backtest gives me only 49.4% with Spread = Slippage = Commission = 0. I assume it's because I can't enter a trade with an average price (that was used in distribution of price movements statistics above).

My script:
Quote:
function run()
{
set(LOGFILE);

StartDate = 2013;
EndDate = 2017;
BarPeriod = 60;
Spread = Slippage = RollLong = RollShort = Commission = 0;

vars Price = series(price());
int num = NumRiseFall(Price,20);
if (NumOpenLong > 0)
exitLong();
if ((num==2) and (NumOpenLong == 0))
enterLong();

}


What am I missing?
Thank you!
Posted By: jcl

Re: Random walk vs Real price statistic - 02/20/18 14:41

The histogram is based on mean prices, but the trades are entered at the close price. Since close prices are much more 'random' than mean prices, you will get about 50% win rate, more or less. That's also the reason of the difference of your two histograms. For the mentioned 52%, use the difference of mean prices of bar 1 with the mean prices of bar 3.
Posted By: kujo

Re: Random walk vs Real price statistic - 02/20/18 15:08

I see, thank you. With mean prices I was able to get even 58%. However, with close prices there is no "fat tails" effect, as you explained. I just tried to leverage this effect in a backtest with trades. But trades use close prices. So even with transaction costs = 0, win rate is no more then 50%.
© 2024 lite-C Forums