Gamestudio Links
Zorro Links
Newest Posts
file_write var array ?
by laz. 10/22/19 16:00
SAV_STATS
by MatPed. 10/22/19 13:57
Instrument Price Zorro Chart
by jcl. 10/22/19 10:39
Accessing All Historical Price Data
by jcl. 10/22/19 10:37
Calculating with price series
by AndrewAMD. 10/21/19 14:31
Error E355: Startup failure
by Dooley. 10/21/19 06:47
Today real live account blown - my experience
by Clifford_B. 10/19/19 17:09
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
14 registered members (JamesHH, AndrewAMD, alibaba, jenGs, FLD, jyd, MatPed, Dalla, 3 invisible), 672 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
VillageTalkies, line7, Shutch, Clifford_B, Paulius
18310 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Random walk vs Real price statistic #471074
02/18/18 18:13
02/18/18 18:13
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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!

Re: Random walk vs Real price statistic [Re: kujo] #471075
02/18/18 18:28
02/18/18 18:28
Joined: Sep 2017
Posts: 235
H
Hredot Offline
Member
Hredot  Offline
Member
H

Joined: Sep 2017
Posts: 235
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.

Last edited by Hredot; 02/18/18 18:31.
Re: Random walk vs Real price statistic [Re: Hredot] #471076
02/18/18 20:02
02/18/18 20:02
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
It makes sense! Thank you, Hredot!

Re: Random walk vs Real price statistic [Re: kujo] #471078
02/18/18 20:40
02/18/18 20:40
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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!

Last edited by kujo; 02/18/18 22:22.
Re: Random walk vs Real price statistic [Re: kujo] #471140
02/20/18 14:41
02/20/18 14:41
Joined: Jul 2000
Posts: 27,033
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,033
Frankfurt
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.

Re: Random walk vs Real price statistic [Re: jcl] #471142
02/20/18 15:08
02/20/18 15:08
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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%.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1