有關futures position size 一問
initial equity=1000000margin=60000
position size=-100(100%)
position size set 了-100, 意思應該是每次都把所有total equity (100%) 去buy/short futures contract. 所以第一個transection share(round to integer)=16, (首幾個backtest後 number of shares 都是把total equity/60000)但不知道為什麼往後的number of shares 很奇怪, 不是把total equity/60000. 很random的, 明明total equity 有1300000 但 buy 的number of shares 只有8, 有時只有2
有高手知道為什麼嗎? 應該很直接的, 但就是不知道為什麼, 望高手指點
Hi,
你是想做到 fixed-dollar amount 的 position sizing 嗎?
ex. 每 20萬做 1口,或 margin 的幾倍做 1口
當 equity 持續增加到 40萬時,可以做 2口,依此類推
而 equity 減少時,縮減部位,反之亦然
是想做這樣的回測嗎?
不, 我是想把全部current total equity(money)用以買/賣 futures contract. 所以我set position size =-100, 但為什麼backtest後不是這樣, number of shares 很奇怪
例如附件, cum profit 有900多萬的, 但為什麼shares 那麼少?
本帖最後由 kilroy 於 14-7-19 00:51 編輯
orangelam 發表於 14-7-19 00:06 static/image/common/back.gif
不, 我是想把全部current total equity(money)用以買/賣 futures contract. 所以我set position size =-100 ...
這邊給個範例參考
SetOption("InitialEquity", 1000000);
SetPositionSize(1, spsShares);
Equity = Ref(Equity(1), -1);
FixDollar= 100000;
...
買賣條件
...
PZ = ValueWhen(Buy OR Short, ceil(Equity/FixDollar));
SetPositionSize( PZ, spsShares);
SetOption("InitialEquity", 1000000 );
SetPositionSize(100,spsPercentOfEquity);
MarginDeposit=60000;
PointValue=50;
thanks, 但我是這樣的, 但就出現了該圖奇怪的shares, 明顯地不是用100% equity to buy/short futures. cum profit有九百多萬, 但為什麼shares是個位數? kilroy 發表於 14-7-19 00:14 static/image/common/back.gif
這邊給個範例參考
SetOption("InitialEquity", 1000000);
Sorry, but that is absolute nonsense and misuse. Don't use Equity() function in analysis!
orangelam 發表於 14-7-19 00:06 static/image/common/back.gif
不, 我是想把全部current total equity(money)用以買/賣 futures contract. 所以我set position size =-100 ...
Short: 32 Contracts * (23483-23544) * 50 = 97600
本帖最後由 joshsmi 於 14-7-19 01:30 編輯
orangelam 發表於 14-7-19 01:06 static/image/common/back.gif
SetOption("InitialEquity", 1000000 );
SetPositionSize(100,spsPercentOfEquity);
MarginDeposit=60000;
Upload your apx file (project file) and symbol file located in your database and I will explain why this and that happens and gets calculated.
joshsmi 發表於 14-7-19 01:18 static/image/common/back.gif
Short: 32 Contracts * (23483-23544) * 50 = 97600
Short: 32 Contracts * (23483-23544) * 50 = 97600
above is correct but in row 5, initial equity+acc profit=1000000+9085300(in row 4)=10085300
so, number of futures contracts should be 10085300/60000=168, why not 168 contracts? but in row 5, it only 3 contracts... this is weird. any ideas?
my coding setting is very simple as below:
RoundLotSize=1;
TickSize=1;
SetOption("FuturesMode", True );
SetOption("InitialEquity", 1000000 );
SetPositionSize(100,spsPercentOfEquity);
MarginDeposit=60000;
PointValue=50;
.
.
.
buy=
sell=
short=
cover=
that's all... thank you very much!
Again, upload project file (.apx extension) and symbol file located in database. 本帖最後由 joshsmi 於 14-7-19 03:14 編輯
There is nothing weird. You just don't understand your own code as it seems to use some additional variable elsewhere.
That's why I said upload project file.
As you can see in the picture below everything in there is in-line with my code.
If you don't understand your own code then don't blame the software for your own limits in understanding but rather keep on learning and understanding what each code line of your code is doing.
BTW, margindeposit is the deposit required for a single contract.
I have used 50,000/contract for the sake of simplicity.
http://s27.postimg.org/dh3ta9gmb/Untitled.png
joshsmi 發表於 14-7-19 01:13 static/image/common/back.gif
Sorry, but that is absolute nonsense and misuse. Don't use Equity() function in analysis!
Hi,
that is totally okay for discussing "to do better" on AmiBroker, don't be sorry. XD
I don't see why not use "equity()" in analysis or how nonsense it is.
If you please, could be more specific or any suggestions on counting the position size?
(take fixed-dollr amount for example)
It might be good and helpful.
本帖最後由 joshsmi 於 14-7-19 05:13 編輯
"I don't see why not use "equity()" in analysis or how nonsense it is."
Because Equity() function is:
1. "old" single security backtester and left in for backward compatibility
2. in your example code snippet you called it on top of the code which is wrong anyway
3. for positionsizing there is SetPositionSize() function with multiple options
For example van Tharp fixed fractional position sizing:
Risk = 2; // percentage
StopAmount = 2 * ATR( 20 );
Stop = StopAmount / BuyPrice;
SetPositionSize( Risk / Stop, spsPercentOfEquity );
Buy = <your conditions here>;
Sell = 0; // selling only by stop
ApplyStop( 2, 2, StopAmount, 1 );
4. Equity() is rather used in Chart panes, for example to evaluate Applystops or to remove excessive signals or to plot single security equity etc. Other field of application is if you wanna replicate single security backtest in Exploration mode. etc
Again never ever use Equity() function in (Portfolio)Backtest/Optimize!
Tomasz Janeczko will tell you the same or similar.
For further details read AFL function reference of Equity()
kilroy wrote: " thanks but the pic is too small to see."
Just click the picture to maximize or download it. 本帖最後由 jacklcl 於 14-7-19 11:06 編輯
joshsmi 發表於 14-7-19 05:16 static/image/common/back.gif
kilroy wrote: " thanks but the pic is too small to see."
Just click the picture to maximize or down ...
Hi Joshsmi --
Thanks for your nice sharing.
Actually the picture cannot be maximized and even I downloaded it, it will be unreadable once you zoom in.Could you please post again the picture such that we can learn more.
Thank you!!