Announcement

Collapse
No announcement yet.

accessing trade equity value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • accessing trade equity value

    I am trying to introduce a money management process into my backtesting. I want to be able to track the equity balance/value as it changes on a per trade basis. Does anyone have any deas as to how to do this?

    There is not an equity balance data access function.

    any help would be appreciated.

    many thanks

  • #2
    I've done this for a couple of files..

    It is not easy as there is no way to pull the equity balance from the strategy runner. The backtester pulls XML data from a database, then calculates all the values (after the fact).

    The way to do it is to track your entry/exit points (to the best of your ability) and create a running total of "points gained/lossed". Then, using simply calculations, you can create an estimated running equity. That is the only way to do it that I know of.

    I would attach a file to show you, but they are client's files and I can't share them. Sorry.

    here is some code snippets that may help..

    PHP Code:
    // control variables
    var DefEntryContracts 50;
    var 
    runningequity 3000;
    var 
    ContractMargin 2300;


    // at the beginning of every trade, you want to adjust your nEntryPrice
    nEntryPrice = ??;

    //  at the end of every trade, you want to update your equity.
          
    fcalcrunningEQ(nStopPrice,1);
          
    fcalcrunningEQ(nStopPrice,-1);
    //  1 = bullish trade, -1 = bearish trade.

    // this function creates your running equity and updates your entry contracts variable.
    function fcalcrunningEQ(exitpricedirection) {
      if (
    direction == 1) {
       
    runningequity += (((exitprice-nEntryPrice)*DefEntryContracts)-(DefEntryContracts*0.096));
       
    DefEntryContracts = (Math.floor(runningequity/ContractMargin))*50;
      }
      if (
    direction == -1) {
       
    runningequity += (((nEntryPrice-exitprice)*DefEntryContracts)-(DefEntryContracts*0.096));
       
    DefEntryContracts = (Math.floor(runningequity/ContractMargin))*50;
      }
     
    // debugPrintln(runningequity+" "+DefEntryContracts);

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      BTW..

      the 0.096 value is the "Commission per share". So you can adjust that to whatever you need.

      B
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thanks for this Brad,

        I have coded something similar already, the trouble is that this works great when trades exit normally, but how can you track the trade when it is reversed by another entry?

        ie when a long is exited by a new short, and equally when a short is exited by a new long

        Comment


        • #5
          reversal signals..

          TJ,

          The logic is all there. All you have to do is determine an approximate entry price and pass that variable to my function. It should all be taken care of..

          for example, My system is long from $30 (nEntryPrice) and wants to reverse now... I would use...

          fcalcrunningEQ(MyExpectedShortEntryPrice,1);

          This calculation will attempt to estimate (to the best of your ability) the entry price and do the calculations. Just add this code into your reversal triggers.

          BTW, how can you tell if it is reversing?? use the "Strategy.isLong()" and "Strategy.isShort()" functions.. like this..

          if (NewSellSignal) {
          if (Strategy.isLong()) { // this code handles the reversal
          fcalcrunningEQ(MyExpectedShortEntryPrice,1);
          }
          Strategy.doShort(...);
          nEntryPrice = open(1);
          }
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment

          Working...
          X