Hello Mike,

my reply follows below

Markus

  ----- Original Message ----- 
  From: Mike 
  To: [email protected] 
  Sent: Monday, November 23, 2009 8:18 PM
  Subject: [amibroker] Re: Computing and plotting historical portfolio metrics 
in CBT


    
  Markus,

  What you are wanting to do is actually very involved and difficult to get 
right. Especially if you plan to handle things like margin, commisions, 
interest, apply stops, etc. I would suggest trying a smaller project first.

  <<<<<<<< I need to follow along with a project, so I have to get this done 
somehow. Believe me, it´s been a headache for me for quite some time.>>>>>>>>>>

  That being said, your current code makes little sense;

  You are iterating through the list of open positions such that at each 
iteration you hold an open position in the 'trade' variable. Yet, you then 
ignore the trade and instead are asking for an open position for the symbol of 
'sig'.

  1. What is sig?

  >>>> I thought I´d need to use sig to be able to use findopenpos command 
thereby making sure, that the price for every symbol in open position list is 
being associated with its proper position size. I infer from what you´re saying 
this was wrong or at least redundant<<<<<


  2. Why iterate through open trades if you're just going to ignore them?

  >> I thought I did but using the loop? Well, apparently another mental flaw 
>>>>>>>

  I suspect that you actually want to use the 'trade' value that you are given 
from your looping of open positions, in which case you do not need to call 
FindOpenPos since you already have it.

  <<< Yes, I wanted to find all open positions, i.e. their sharesize and their 
(closing prices). Then, by multiplying their closing with their position size, 
I thought I´d get the open possition value total... I also tried  

  value_of_all_open_os = value_of_all_open_pos + trade.GetPositionValue()  

  Is that the way to go?  From what you say, I don´t need 

  trade = findopenpos(sig.symbol). 

  Thus, I´ll get rid of it in my code>>>>

  Also, if you are allowing margin, you will need to take that into 
consideration. If you use 50% margin, then AmiBroker will take half from cash 
and half from margin. Thus, you will need to deduct the original margin portion 
from the value of your open positions.


  >> Yes, I plan to use margin but this may be not the biggest issue at this 
point. I´ll address this once I get the main problems solved. Thanks though for 
pointing that out, I wasn´t aware of that!!!!!<<<<<

  I´m really grateful for your guidance thru the jungle, called CBT. I wish 
there were an even more detailed documentation on it. CBT really is not as easy 
as regular AFL.

  Markus




  Mike

  --- In [email protected], "Markus Witzler" <funny...@...> wrote:
  >
  > Hi Mike,
  > 
  > do you have a clue for me?
  > 
  > Thanks
  > 
  > Markus
  > ----- Original Message ----- 
  > From: Markus Witzler 
  > To: [email protected] 
  > Sent: Sunday, November 22, 2009 12:16 PM
  > Subject: Re: [amibroker] Re: Computing and plotting historical portfolio 
metrics in CBT
  > 
  > 
  > Hello again, Mike!
  > 
  > Nope, I wanted to code my_equity to get a grasp of how CBT actually works.
  > 
  > I´m aware that my_equity is the same as ~~~Equity. I later want to modify 
my code to test my systems with different versions of my_equity, for instance 
  > 
  > my_equity = cash position plus profit of all open positions (locked up by a 
stop).
  > 
  > I gues Van Tharp calls this "reduced total equity". I want to explore how 
testing results change if I change the definition of my_equity.
  > 
  > But again, I first need to know where the flaw in my code is. Otherwhise, I 
have no chance to proceed any further.
  > 
  > Thanks
  > 
  > Markus
  > 
  > 
  > 
  > 
  > ----- Original Message ----- 
  > From: Mike 
  > To: [email protected] 
  > Sent: Sunday, November 22, 2009 6:52 AM
  > Subject: [amibroker] Re: Computing and plotting historical portfolio 
metrics in CBT
  > 
  > 
  > 
  > 
  > Markus,
  > 
  > If all you want is a copy of the ~~~Equity that AmiBroker already 
calculates for you, then there is no need to do any specialized signal/trade 
handling.
  > 
  > Just do the following:
  > 
  > SetCustombacktestProc(""); 
  > 
  > if (Status("action") == actionPortfolio) { 
  > bo = GetBacktesterObject(); 
  > bo.Backtest(); 
  > AddToComposite(Foreign("~~~Equity", "C"), "~my_equity", "X", 
atcFlagDefaults | atcFlagEnableInPortfolio); 
  > } 
  > 
  > Plot(Foreign("~my_equity", "C"), "My Equity", colorBlue, styleLine); 
  > 
  > Mike
  > 
  > 
  > --- In [email protected], "Markus Witzler" <funnybiz@> wrote:
  > >
  > > Hello,
  > > 
  > > I want to compute and plot my own equity (labeled my_equity). 
  > > 
  > > In the code below (I skkipped the signal part with buy and sell signal), 
I wonder why my_equity
  > > 
  > > - is not being shown in backtester report
  > > 
  > > - can´t be plotted
  > > 
  > > - doesn´t show up in exploration
  > > 
  > > Why is that? If you reauire the rest of the code, please let me know
  > > 
  > > Thanks
  > > 
  > > Markus
  > > 
  > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - 
  > > 
  > > ...<snip >...
  > > 
  > > for (trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos())
  > > 
  > > {
  > > 
  > > trade = bo.findopenpos (sig.symbol);
  > > 
  > > if (trade)
  > > 
  > > {
  > > 
  > > value_all_open_pos=value_all_open_pos + trade.GetPrice(i, "C") * 
trade.shares; 
  > > 
  > > }
  > > 
  > > 
  > > 
  > > }
  > > 
  > > bo.HandleStops(i); // Process programmed stops or applystop at this bar
  > > 
  > > my_equity [i] = bo.cash + value_all_open_pos;
  > > 
  > > } // End of for loop over signals at this bar
  > > 
  > > 
  > > bo.UpdateStats(i, 1); // Update MAE/MFE stats for bar
  > > 
  > > bo.UpdateStats(i, 2); // Update stats at bar's end
  > > 
  > > } // End of for loop over bars
  > > 
  > > bo.PostProcess(); // Do post-processing
  > > 
  > > AddToComposite(my_equity, "~~~my_equity","x", atcFlagEnableInPortfolio | 
atcFlagDefaults); 
  > > 
  > > }
  > > 
  > > PlotForeign("~~~my_equity", "my_equity", colorRed, styleHistogram );
  > >
  > 
  > 
  > 
  > 
  > 
  > __________ Information from ESET Smart Security, version of virus signature 
database 4627 (20091121) __________
  > 
  > The message was checked by ESET Smart Security.
  > 
  > http://www.eset.com
  > 
  > 
  > 
  > __________ Information from ESET Smart Security, version of virus signature 
database 4627 (20091121) __________
  > 
  > The message was checked by ESET Smart Security.
  > 
  > http://www.eset.com
  >



  

  __________ Information from ESET Smart Security, version of virus signature 
database 4631 (20091123) __________

  The message was checked by ESET Smart Security.

  http://www.eset.com

Reply via email to