amibroker marginDeposit 应该如何计算?

Discussion in 'AmiBroker' started by edwardj, Oct 27, 2012.

  1. AB 测试期货时 marginDeposit 应该如何计算呢?是否应该为
    Code:
    marginDeposit=点值*开仓价格*保证金比率;
    
    比如 IF, 开仓价格为 3222.6,收盘价格为 3222.4,假设为 20% 保证金,单向万一,是否应该为
    Code:
    marginDeposit=300*3222.6*0.2=193356;
    
    即上述条件下,一手 IF00 需要 193356 的保证金。

    而 amibroker 实测为
    Code:
    	Entry signals(score):IF00=Buy(1), 
    	Exit signals:
    	Enter Long, IF00, Price: 3222.6, Shares: 1, Commission: 96.678, Rank: 1, Equity 299807, Margin Loan: 0, Fx rate: 1
    	1 Open Positions: , IF00 (+1), Equity: 299747, Cash: 164783 
    
    即 299807-164783,为 13.5 万左右呢?差不多打了 7 折。
     
  2. 193356和13.5 万之间的差额应该是你目前头寸的盈亏吧
     
  3. 应该不是 开仓3222.6 收盘3222.4 亏损 0.2 个点
     
  4. 呵呵,好久没看这一块的程序了,因为看不到你的代码怎么写的,所以很难从结果看到问题在哪里。不过有个基本概念应该很清楚,marginDeposit不是由AB计算,而必须是你自己设定的。同理,PointValue 也不是由AB计算,也是自己设定。(当然了,更复杂的外汇回测则是margin和pointvalue会因为货币对不同而不断变化,也可以用程序设定的....)

    marginDeposit = 1手合约金额 * 保证金比例
    PointValue = 1手合约移动1个基点的金额


    Margin deposit
    The margin is the amount of money required to open single contract position. You can specify per-symbol margin in the Symbol-Information page (picture above). Positive values describe margin value in dollars, while negative express margin value as percentage of contract price. Margin value of zero is used for stocks (no margin). Margin can be also specified in the formula by using MarginDeposit reserved variable:

    MarginDeposit = 675;

    In the Futures mode margin setting is used to determine how many contacts can be purchased.


    Point value
    Point-value is per-symbol setting (definable in Symbol-Information window - (picture above)) that determines the amount of profit generated by one contract for a one point increase in price.



    下面这个链接里面说得很详细:
    Back-testing systems for futures contracts
    http://www.amibroker.com/guide/h_futbacktest.html
     
  5. 看第二段code

    marginDeposit=300*3222.6*0.2=193356;

    300 是 pointvalue,0.2 是杠杆比率,3222.6 是开仓价格。
     
  6. 试了下固定值,发现计算是对的,比如
    marginDeposit=6750;
    此时 AB 计算出来的可用 cash 是对的。
    Code:
    	Enter Long, IF00, Price: 3222.6, Shares: 1, Commission: 96.678, Rank: 1, Equity 299807, Margin Loan: 0, Fx rate: 1
    	1 Open Positions: , IF00 (+1), Equity: 299747, Cash: 293153 
    2
    
    为啥浮动的 marginDeposit 就不对了呢?
     
  7. ok,marginDeposit 设为负值,AB 算对了。

    marginDeposit=300*-20;


    Code:
    	Enter Long, IF00, Price: 3222.6, Shares: 1, Commission: 193.356, Rank: 1, Equity 299613, Margin Loan: 0, Fx rate: 1
    	1 Open Positions: , IF00 (+1), Equity: 299553, Cash: 106451 
    
    
    PS: 这里偶把手续费提高了一倍,所以是 193.356。


    但还是有个小问题也说下吧,仔细看了上面 LOG 的人也能发现,AB 每次都扣了两次手续费。

    总结:

    1: 期货模式下,浮动的 marginDeposit 尽量用负值。即 while negative express margin value as percentage of contract price
    2: 无论期货股票,AB 手续费应设为实际的一半。另外,期货模式下,AB 手续费计算采用的是保证金金额的百分比计算,而非根据合约价值来计算。因此,手续费也因乘以每点价值。例如对于 IF,点值 300,手续费万一,则应设为 0.0001*300/2=1.5%。此结论尽对 commission table 模式有效。其他模式未测试。
     
  8. One addition,

    to get margin deposit behaving like an array use Custom Backtester Interface of Amibroker. www.amibroker.com/guide/a_custombacktest.html

    default Margin Deposit doesn't behave like an array.

    Here is an example in regards to Forex and USD accounts.

    [​IMG]