PureBytes Links
Trading Reference Links
|
Hello Tomasz,
We are mixing up the topic and lead to confusion since we do not clearly confirm what we understand, what we do not understand. I believe that I entirely understand what you mean. I'd like to repeat as follows before elaborating on the topic I'd like to emphasize.
- Normal lot is $100,000. It's OK. For 8 lots, it sums up to $800,000 position size. This is correct. My formulation already includes these numbers. Backtester calculates the P&L according to $800,000 position size, 1% fluctuation leads to $8,000 movement. This is also correct. When we look from this side, considering we have $10,000, our position size is 8,000%. There is nothing wrong with all these.
- When you look from the equity-margin deposit side, we have $10,000 and we use 8 x $1,000 = $8,000 margin. This is 80% of total equity. And this is what I called below the "real position size", referring to the margin usage. Speaking strictly, of course the real position size is $800,000.
- I know that it is illogical to open a 8 lot position with $10,000 cash. I know that I may lose it even within seconds if I open such a large position. I do not intend to trade like this. The given numbers are for illustration purposes only.
- Amibroker performs all P&L calculations correctly, even if the equity level goes below zero. It just takes the price difference, given the point value & shares, calculates P&L. Displayed results are There is nothing wrong with P&L calculations.
- Attached code (eurusd.afl) performs the following trades when we run it starting from 01.01.2008:
Trade |
Date |
Price |
Ex. date |
Ex. Price |
% chg |
Profit |
% Profit |
Shares |
Position value |
Cum. Profit |
Short |
11.08.2008 |
1.50175 |
24.12.2008 |
1.40125 |
-6.69% |
80400 |
1005.00% |
8 |
8000 |
80400 |
Long |
25.12.2008 |
1.4013 |
12.01.2009 |
1.3362 |
-4.65% |
-468720 |
-651.00% |
72 |
72000 |
-388320 |
In fact, I have mentioned the -388320 earlier. All these p&l calculations are also correct.
Well, then, what is the problem I mention insistently?
Initial equity is $10,000. Backtester opens a short position on 11.08.2008, using $8000 margin. It has $2,000 cash. After 12.08.2008, the position value and cash goes on as follows:
[6428]
Date: 12.08.2008 PositionValue: 16680 AND bo.Cash: 2000 |
[6428] Date: 13.08.2008
PositionValue: 15240 AND bo.Cash: 2000 |
[6428] Date: 14.08.2008
PositionValue: 16400 AND bo.Cash: 2000 |
[6428] Date: 15.08.2008
PositionValue: 23372 AND bo.Cash: 2000 |
[6428] Date: 18.08.2008
PositionValue: 34200 AND bo.Cash: 2000 |
[6428] Date: 19.08.2008
PositionValue: 33440 AND bo.Cash: 2000 |
[6428] Date: 20.08.2008
PositionValue: 27120 AND bo.Cash: 2000 |
[6428] Date: 21.08.2008
PositionValue: 29600 AND bo.Cash: 2000 |
[6428] Date: 22.08.2008
PositionValue: 17400 AND bo.Cash: 2000 |
[6428] Date: 25.08.2008
PositionValue: 26320 AND bo.Cash: 2000 |
[6428] Date: 26.08.2008
PositionValue: 29080 AND bo.Cash: 2000 |
[6428] Date: 27.08.2008
PositionValue: 36960 AND bo.Cash: 2000 |
[6428] Date: 28.08.2008
PositionValue: 31320 AND bo.Cash: 2000 |
[6428] Date: 29.08.2008
PositionValue: 32568 AND bo.Cash: 2000 |
[6428] Date: 01.09.2008
PositionValue: 35200 AND bo.Cash: 2000 |
[6428] Date: 02.09.2008
PositionValue: 40040 AND bo.Cash: 2000 |
[6428] Date: 03.09.2008
PositionValue: 47880 AND bo.Cash: 2000 |
[6428] Date: 04.09.2008
PositionValue: 49840 AND bo.Cash: 2000 |
[6428] Date: 05.09.2008
PositionValue: 63480 AND bo.Cash: 2000 |
[6428] Date: 08.09.2008
PositionValue: 68360 AND bo.Cash: 2000 |
[6428] Date: 09.09.2008
PositionValue: 78680 AND bo.Cash: 2000 |
$2000 cash stays constant while the position value changes. After a while consider position value goes to zero. You still have cash. Consider having an additional cash of $8,000 or $80,000. Your position goes to -$100,000 and you still have $80,000 cash.
This is obviously INCORRECT.
The reverse is also possible. You have 8 lot position and your equity goes to $20,000. You still need $8,000 margin deposit to handle 8 lot position, nothing more. Then you should have $12,000 available margin.
However backtester still has $2,000 cash!!! This is also obviously INCORRECT.
To sum up, cash should change in the "futures mode" not the position value (the one we get with GetPositionValue()).
Attached please also find two snapshots of two moments from a demo futures account and the comparison of the moments in terms of equity and available cash. In these sheets, you may plainly observe that as the prices change, cash (available margin) changes and used margin deposit stays constant.
I hope we understand each other better by now. Thank you for reading.
Best regards, Ilhan
2010/2/3 Tomasz Janeczko <groups@xxxxxxxxxxxxx>
Hello,
Normal lot is $100000. So, with 8 lots (each $100000), real position
size is $800000. You should read the documents of your broker
and you will see. In such case, if currency changes as little as 1%
down (such fluctuations are happenning on currencies virtually every
day!) you are LOSING $8000 on that position. That is where your loses
coming from. Your initial equity evaporates that way. When your equity
drops below zero you will receive margin call (and you need
to deposit MORE MONEY to your account to keep it alive) or your broker
will liquidate your position immediatelly and close your account.
Backtester will not pick up the phone and call you, instead it will
show you the same thing using numbers. That is what negative backtest
result tells you - how much money you would need to deposit during
entire period under test (how far underwater you are and how much more
money you would need to have at start not to become bankrupt). For
stocks, it will stop when your account is zero because there is a
built-in -99.8% ruin stop for stocks, but for highly-leveraged (1:100
as in your case) undercapitalised accounts it is possible to wipe
account and go negative in a matter of seconds (for example when you
got 8-lot open position worth nearly $1 million when you got only $10K
account) when Fed is announcing rate decision.
Again: that is what backtest results are telling you: you are way way
undercapitalised.
On 2010-02-03 06:04, İlhan Ketrez wrote:
Thank you for your prompt replies.
Please find below my answer to both Aron and Tomasz:
Negative test results are very late indication of insufficient
funds. Falling of the equity level below total maintenance margin means
I need to deposit extra money. And this level is far above zero.
To inspect this we need to trace these values in backtest. The
mistake in current beacktest procedure is:
You open a position for example 8 lots with $1000 margin
deposit. The real position size is then $8000 and this is constant
until you close the position if the position is a winner. The cash
amount should change in accodance with price change and pointvalue. If
the position is a loser, and if the account is $10000, you first
lose the $2000 cash. Then the $8000 position value goes down until it
reaches to maintenance deposit.
To sum up, in the current backtest procedure PositionSize is
changing instead of the cash (available funds).
Please check it up.
Best regards,
Ilhan
2010/2/3 Tomasz Janeczko <groups@xxxxxxxxxxxxx>
Hello,
In other words negative result tells you how much extra cash you would
need to deposit on your account
to keep trading. This is margin call. Either you deposit extra money or
you say good bye to your account.
On 2010-02-03 01:22, Tomasz Janeczko wrote:
Hello,
Well, certainly with $10000 account then in fact you should not trade
forex at all, because you are undercapitalized and this is straight way
to blow you account, at that is precisely what backtest results tell
you.
Best regards,
Tomasz Janeczko
amibroker.com
On 2010-02-02 21:07, İlhan Ketrez wrote:
[Attachment(s)
from =?UTF-8?Q?=C4=B0lhan_Ketrez?= included below]
Hello,
If I have 10,000 and if the initial margin is 1000, can't
I open 8 lots? Then what does the initial margin mean?
If Amibroker trades far away from margin call everything
works perfectly. For example if I have 100,000 and trade one contract,
there is no problem. Amibroker takes the position value, multiplies it
with the price difference... These are OK. The document you suggest
mainly explains these essential details and some basic concepts ( http://www.amibroker.com/kb/2006/08/09/amibroker-for-forex/) .
In forex & futures, the trick is to be able to trade
near limits without getting caught by the limits. And there is nothing
in Amibroker about these limits as far as I see. Moreover, it seems
that it is impossible to formulate a correct custom backtest procedure
due to improper handling of PositionSize and read-only Equity and Cash
variables in CBI.
I wonder your additional comments on the subject,
especially your answer to my first two questions. The final equity
becomes -378,320 with 10,000 initial equity with the same settings.
Attached you may find the formula file.
Best regards,
Ilhan
2010/2/2 Tomasz Janeczko <groups@xxxxxxxxxxxxx>
Hello,
You are using wrong settings.
> Contract number is 800
That is wrong. No forex broker would allow you to open 800 lots.
You should use SetPositionSize( 1, spsShares ); to ensure you are
trading one lot
(or what every lots you really trade).
You need to read this:
http://www.amibroker.com/kb/2006/08/09/amibroker-for-forex/
Best regards,
Tomasz Janeczko
amibroker.com
On 2010-02-02 18:37, İlhan Ketrez wrote:
Hello,
I am a registered user of Amibroker and have sent this problem to
Amibroker support before sending to the mailgroup.
By now, more than one week has passed and there is no reply.
I still do not want to believe that Amibroker cannot perform a correct
futures/forex bactest and I am afraid of hearing that it can't.
However, to me, my tests clearly indicate that there's something wrong
with the default behaviour of "futures mode" backtesting. Shortly, you
open a position, and as the position be exhausted you still have cash
in your account. Even after the position size goes below zero, you
still have cash and may open a position if you code accordingly.
Ability of the position size to go below zero may just be another
discussion topic. There is no such account in real life. Normally, the
position size does not change if the position is a winner and if the
position is a loser, it consumes the cash first, then consumes itself
down to the maintenance margin where the broker liquidates the position.
All in all, my request from Amibroker stuff is to either invalidate
my comments by writing a few sentences or clearly
accept that Amibroker cannot perform a correct futures backtest
and stop misleading people.
Best regards,
Ilhan
2010/1/28 İlhan Ketrez <ketrezilhan@xxxxxxxxx>
[Attachment(s)
from =?UTF-8?Q?=C4=B0lhan_Ketrez?= included below]
Dear friends
I am trying to test a simple system and understand
the behaviour of Amibroker testing mechanism.
I have set up an AFL file very similar to the one
described here.
Testing period: 01.01.2008 - today
Initial equity: 1,000,000
Final equity: -38,033,810
The position size is -80.
Margin deposit: 1000.
First entry details are as follows:
Contract number is 800
Entry position size: 800,000. Cash: 200,000.
The details I find interesting are:
As the position grows position size also grows and cash continues as
200,000.
Later, position size goes below zero as cash floats constantly above
zero.
The default result in Amibroker is something impossible to encounter in
real life. (To go into a debt of 38 million)
I defined a real cash value and observed the difference via debugview.
Report and debugview log are attached including the
system codes.
I hope to find a way to test correctly using Amibroker with your help.
Thank you very much in advance.
Regards,
Ilhan Ketrez
Attachment(s) from =?UTF-8?Q?=C4=B0lhan_Ketrez?=
1 of 1 File(s)
__._,_.___
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
__,_._,___
Attachment:
eurusd.afl
Description: Binary data
Attachment:
Sample Calculations.xlsx
Description: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|