Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
PnL calculation #423483
05/30/13 15:31
05/30/13 15:31
Joined: May 2013
Posts: 15
P
Purri Offline OP
Newbie
Purri  Offline OP
Newbie
P

Joined: May 2013
Posts: 15
Hello,

i am just trying out Zorro and writing a few simple scripts to get familiar with it. I wrote a script that trades only on a single day, that goes long at 12:00PM and exits the trade at 16:00. I have tested this with EUR/USD data from the Zorro-website.

Code:
function run()
{
	set(LOGFILE);
	vars Price = series(price());

	if(NumOpenLong == 0 && hour(0) >= 12 && lhour(0) < 16)
		enterLong();

	if(NumOpenLong != 0 && hour(0) >= 16)
		exitLong();

	StartDate = 20120921;
	EndDate = 20120921;

	PlotWidth = 1024;
	PlotHeight1 = 768;
}



Now Zorro produces a performance report, a trade log and a CSV-file with the trades. The log says i entered at 1.2978 and exited at 1.2992 for a PnL of $1 (+14 pips).

The CSV says i entered at 1.29781 and exited at 1.29896 for a PnL of $0.84 (+11.5 pips).

The performance report says i made +10.4 pips or $0.84.

Why are there such differences, and how do you calculate the $0.84 ? A gain of 10 pips (the minimum of the three) should be $1 straight.


I also did the same on USD/JPY. Again the exit-prices from the csv and the log are differing by ~3 pips. And the PnL calculation is off: according to the csv-file i lost 3.1 pips or $0.32. This cannot be correct with usd/jpy exchange-rate at 78.xx.


Maybe i have to adjust some flags or something?

One last question: can Zorro correctly calculate the PnL in USD of, for example, a EUR/CHF trade?

Regards,
Purri

Re: PnL calculation [Re: Purri] #423484
05/30/13 15:47
05/30/13 15:47
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The trade entry, exit, and profit values are recorded in the CSV file.

The log does not record trades. It just records the events during the simulation. It lists the asset price at the moment of entry and exit. The price at which you really bought and sold the asset is recorded in the CSV, and it's normally different due to Spread, Slippage, and Rollover. Look here for details: http://manual.zorro-trader.com/spread.htm.

The EUR 0.84 in your above example is the profit of that trade. Where values are rounded, 84 cents are displayed as $1 and 10.4 pips are displayed as 10p.

The "$" sign in the message window has nothing to do with US-Dollars, it just means money. What currency it is depends on the simulated broker account. The default account is a micro lot EUR account.

Re: PnL calculation [Re: jcl] #423485
05/30/13 16:24
05/30/13 16:24
Joined: May 2013
Posts: 15
P
Purri Offline OP
Newbie
Purri  Offline OP
Newbie
P

Joined: May 2013
Posts: 15
Thanks, i see. So the $0.84 from the CSV file are in this case actually Euros. But shouldn't it then be 0.88 ? ( $1.15/1.29896 = 0.884 ) The $0.84 would imply an eur/usd exchange-rate of around 1.37.

I understand its very difficult to calculate correct fx pnl during backtests, especially if you trade a portfolio of many different pairs, some of which might not even include the account base currency. Even more so if you want to account for historical roll rates. Im not entirely convinced static exchange and roll rates are 'good enough'. Some pairs are +-50% compared to 10 years ago, or even 5.

Re: PnL calculation [Re: Purri] #423486
05/30/13 16:33
05/30/13 16:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
No, the $0.84 are correct, but your objection is justified. PnL calculation is not really difficult, but there are many factors involved.

For spread, rollover, and conversion from price differences to profit, the current broker's parameters are used, not the historic rates. The reason behind that is that you want to use a developed system today, at current rates, and not in the past. So the simulation does not really simulate history, it simulates the present, but with a history price curve. For the conversion from asset price differences to account money, the broker publishes a value named "PipCost" or similar on his website. This value is used for the conversion. It changes from time to time when the counter currency and the account currency are different.

You can find details about the account simulation in the manual under "Data import/export". There are about 10 parameters per asset that determine how PnL is calculated. You can set up different parameters for emulating different accounts, also in US-$, so you then won't have the conversion issue.

Re: PnL calculation [Re: jcl] #423490
05/30/13 23:13
05/30/13 23:13
Joined: May 2013
Posts: 15
P
Purri Offline OP
Newbie
Purri  Offline OP
Newbie
P

Joined: May 2013
Posts: 15
jcl: how are the 0.84 correct? +11.5 pips on a microlot would be $1.15 in profit which converts to €0.88 with the then prevailing exchange-rate.

Re: PnL calculation [Re: Purri] #423499
05/31/13 07:23
05/31/13 07:23
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
A trade profit has not much to do with the prevailing exchange rate. Brokers use their published pip costs for converting price differences to profits. They do not use the dollar exchange rate for obvious reasons. The exchange rate is different any day and traders would not appreciate when it affected all their trade results.

The profit of your trade is about 10.44 pips. The difference to 11.5 is the slippage, which is not rounded because it's a statistical value. When you multiply 10.44 pips with 0.0800 EUR pip cost, you'll get 0.8352 EUR. That's your 84 cents - the exact profit of your trade when you had entered it today with a real FXCM EUR account. I think that's the result you're normally interested in when testing a system.

Entry and exit prices in the CSV contain the spread, but they do not contain the other trade costs - rollover, commission, and simulated slippage. The costs affect the profit, but not the entry and exit price, although for slippage this could maybe make sense. But slippage is simulated separately at the moment.

I hope this helps understanding trade profit. For your experiments you can set Slippage to 0 - then you should really get 11.5 pips profit.

Re: PnL calculation [Re: jcl] #423513
05/31/13 12:51
05/31/13 12:51
Joined: May 2013
Posts: 15
P
Purri Offline OP
Newbie
Purri  Offline OP
Newbie
P

Joined: May 2013
Posts: 15
jcl: actually they do use the exchange rates for pnl - im sure traders would appreciate it even less if FXCM came up 4% short in their account like in this example. I certainly wouldnt.

I did never trade with fxcm, but Oanda, IB and lmax do it like that (and everyone else i suppose). What happens behind the scenes is that you pnl will stay in USD for 2 days and then settles in your account currency. You can google "tomorrow-next" for settlement conventions in fx.

If you do a 10 year backtest, the exchange-rate in eur/usd varies by 60%, its anywhere between 1 and 1.60. You cannot just assume a static eur to usd conversion factor, the pnl of the simulation will invariably be off significantly.

I have tried quite a few of the more well knowen affordable backtesting platforms (ninja, neoticker, multicharts and so on) and none can really do multi-currency backtests. Let alone account for rolls, so one could simulate carry-trade strategies. It would be nice if Zorro could somehow come up with a wholistic solution to this.

Re: PnL calculation [Re: Purri] #423514
05/31/13 13:37
05/31/13 13:37
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Hmm, the Fx brokers that I know all calculate profits in the same way as FXCM.

For EUR/USD, the current Pip-EUR conversion rate is 0.0800. You can normally see the conversion rate when you start your broker's platform, f.i. the FXCM trading station, and look into the currency detail view. The rate is named like "PipCost" or "PipValue" dependent on the broker.

The rate does indeed change, but infrequently. It does not follow the daily dollar price. The current value, 0.0800, was the same in 2012. So your trade had earned exactly the same 84 cents profit when you had executed it back then on a real EUR account. In 2011 the rate was lower, like 0.078.

A change of the rate does however not affect the PnL in the simulation. The simulation only uses the current pip cost, not the USD exchange rate and also not the broker's historic pip costs. Otherwise the equity curve would not reflect the performance of your strategy, but also the USD price or the broker's conversion rates.

Anyway: if you want to convert the profits of your trade to another currency at the real exchange rate, you can do that in the script. You can set PipCost to a different value, so you can use the price of an asset, f.i. EUR/USD, for calculating an artificial PipCost that changes daily.

Re: PnL calculation [Re: jcl] #423521
05/31/13 16:43
05/31/13 16:43
Joined: May 2013
Posts: 15
P
Purri Offline OP
Newbie
Purri  Offline OP
Newbie
P

Joined: May 2013
Posts: 15
jcl: i can only recommend to think this through one more time.. its just not how it works.

And obviously PnL of a simulation should reflect what the PnL would have been at that time - not what it would be with a future exchange-rate..

Re: PnL calculation [Re: Purri] #423523
05/31/13 16:55
05/31/13 16:55
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Ok. At least I can say that I did my best in this thread, although with no final success wink.

Page 1 of 3 1 2 3

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1