[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Enhancement Request - "Playback" Function



PureBytes Links

Trading Reference Links




<FONT face=Arial 
color=#0000ff size=2>I know you asked for it a while back - a number of people 
have asked for it over the last several years. I just saw what Nigel had done 
and it piqued my curiosity.
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>The position size is left as and exercise for the 
student.  (Until I or someone else can figure out how to implement 
it.  I strongly suspect that's why Nigel decided not to finish it.  
8-)  ).
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>As to just the "current stock" that was to make it easy to 
run the example. 
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>It "should" be able to work on multple tickers, etc.  

<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>Looking for suggestions from 
anyone!!!
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>d


From: Ken Close [mailto:closeks@xxxxxxxx] 
Sent: Saturday, January 24, 2004 9:01 PMTo: 
amibroker@xxxxxxxxxxxxxxxSubject: RE: [amibroker] Enhancement Request 
- "Playback" Function


<SPAN 
>Dale:  this code 
looks like something I want as the idea of analyzing ones real life portfolio 
trades was something I asked about a short while back.
<SPAN 
> 
<SPAN 
>May I ask what this 
analysis will tell me (I have not tried it yet), when there are no &#8220;Shares&#8221; 
entered anywhere.  It seems to bring in the symbols and the dates but no 
position sizes.  Ooops, I also see that it applied just to the &#8220;Current 
Stock&#8221;, so we are not analyzing one&#8217;s past portfolio but just the stocks or 
funds one may have bought in the past, and those one at a time.   
 Correct?
<SPAN 
> 
<SPAN 
>What does it take to 
expand this to include many stocks/funds and their positions 
sizes?
<SPAN 
> 
<SPAN 
>Ken
<SPAN 
> 
<SPAN 
>-----Original 
Message-----From: dingo 
[mailto:dingo@xxxxxxxxxxxx] <SPAN 
>Sent: Saturday, January 24, 2004 8:28 
PMTo: 
amibroker@xxxxxxxxxxxxxxx<SPAN 
>Subject: RE: [amibroker] Enhancement 
Request - "Playback" Function
<SPAN 
> 
<SPAN 
>Thanks for the start 
Nigel!  Nice piece of code.  
<SPAN 
> 
<SPAN 
>I've taken the liberty 
to incorporate the date routine I submitted earlier and also added a short 
routine in addition to the long you already had.  Here is the 
result:
<SPAN 
> 
<SPAN 
>// Inspired by a 
request for a 'playback' feature from Don Upton and initial code by Nigel Rowe 

<SPAN 
>//    
with enhancements by Ruddy Turnstone Trading, LLC  (dingo)//// 
Simplified example, long only and the file format is spec'd for ease of// 
implimentation.//// Input file is comma seperated text.// Fields 
are://      0.      
Symbol        -- without 
quotes//      1.      Long 
Or Short --  "L" or "S"//      
2.      Entry date    -- in mm/dd/yyyy 
format.  ie xmas day 2003 is 12/25/2003//      
3.      Entry price//      
4.      Exit date     -- 
mm/dd/yyyy  format, or blank for no 
exit//      5.      Exit 
Price

<SPAN 
> 
<SPAN 
>Buy = False;Sell = 
False;BuyPrice = Close;SellPrice = Close;Short = False;Cover = 
False;ShortPrice = Close;CoverPrice = Close;

<SPAN 
> 
<SPAN 
>function 
DateToDateNum(sMMDDYYYY) // date in format mm/dd/yyyy{

<SPAN 
> 
<SPAN 
>/*-------------------------------------------------------------  
This function will accept a string in the MM/DD/YYY format  and convert 
it into Amibroker's datenum.

<SPAN 
> 
<SPAN 
>  nDateNum = 10000 
* (year - 1900) + 100 * month + day

<SPAN 
> 
<SPAN 
>  It assumes that 
mm dd and yyyy are reasonable. It does check  for the presence of 2 "/" 
characters and if not there  will return a 
0.-------------------------------------------------------------*/

<SPAN 
> 
<SPAN 
>    
nDateNum = 0;    sWrk = sMMDDYYYY;    
nPosn = StrFind(sWrk, "/");    if (nPosn > 0) 
{        nMth = StrToNum(StrLeft(sWrk, 
nPosn-1));        sWrk = StrRight(sWrk, 
StrLen(sWrk) - nPosn);        nPosn = 
StrFind(sWrk, "/");        if (nPosn > 
0) {            nDay 
= StrToNum(StrLeft(sWrk, 
nPosn-1));            
sWrk = StrRight(sWrk, StrLen(sWrk) - 
nPosn);            
nYr = 
StrToNum(sWrk);            
nDateNum = 10000 * (nYr - 1900) + (100 * nMth) + 
nDay;        }    
}    return nDateNum;}

<SPAN 
> 
<SPAN 
>function 
DateToBar(dn){    return 
LastValue(ValueWhen(DateNum()==dn, BarIndex()));}

<SPAN 
> 
<SPAN 
>Filter = 
1;

<SPAN 
> 
<SPAN 
>f = 
fopen("playback.txt", "r");while( f && (! 
feof(f))){    Line = fgets(f);    sym 
= StrExtract(Line, 0);    if( sym == Name() ) 
{        LorS = StrExtract(Line, 
1);        sendt = 
StrExtract(Line,2);        endt = 
DateToDateNum(sendt);        enpr = 
StrExtract(Line,3);        sexdt = 
StrExtract(Line,4);        exdt = 
DateToDateNum(sexdt);        expr = 
StrExtract(Line,5);        bar = 
DateToBar(endt);        if( bar ) 
{            if (LorS 
== "L") 
{                
Buy[bar] = 
True;                
BuyPrice[bar] = 
StrToNum(enpr);                
if( exdt != 0 ) 
{                    
bar = 
DateToBar(exdt);                    
Sell[bar] = 
True;                    
SellPrice[bar] = 
StrToNum(expr);                
}            
}            else 
{                
Short[bar] = 
True;                
ShortPrice[bar] = 
StrToNum(enpr);                
if( exdt != 0 ) 
{                    
bar = 
DateToBar(exdt);                    
Cover[bar] = 
True;                    
CoverPrice[bar] = 
StrToNum(expr);                
}           
}        }    
}}

<SPAN 
> 
<SPAN 
>if(f) 
fclose(f);

<SPAN 
>I've run the formula on the following list and it seems to be working very nicely:

<SPAN 
> 

<SPAN 
>AUY,L,1/12/2001,3.54,1/17/2001,5.29AUY,L,1/25/2001,4.88,1/29/2001,5.57AUY,L,2/2/2001,5.57,2/21/2001,4.32AUY,S,3/6/2001,3.76,3/7/2001,3.76AUY,S,3/13/2001,5.35,3/14/2001,4.18AUY,S,4/2/2001,3.2,4/10/2001,3.62AUY,S,4/11/2001,3.06,5/3/2001,2.93AUY,L,5/16/2001,3.06,5/18/2001,4.46AUY,L,5/24/2001,4.46,5/25/2001,5.29AUY,L,6/1/2001,4.6,6/5/2001,3.48AUY,S,6/13/2001,3.62,6/21/2001,3.2AUY,S,6/26/2001,3.68,7/12/2001,2.9AUY,S,7/18/2001,3.49,7/19/2001,3.0363AUY,S,7/30/2001,3.34,8/7/2001,2.51AUY,L,8/14/2001,3.34,8/15/2001,2.9058AUY,L,8/17/2001,2.79,8/21/2001,3.1527AUY,S,9/5/2001,3.06,9/7/2001,1.39AUY,S,9/28/2001,2.23,10/2/2001,2.79AUY,L,10/11/2001,3.06,10/12/2001,2.65AUY,L,10/16/2001,2.79,10/19/2001,1.77AUY,L,10/22/2001,2.02,10/30/2001,2.93AUY,L,11/8/2001,2.23,11/14/2001,2.73AUY,L,11/23/2001,1.81,11/29/2001,2.0453AUY,S,12/4/2001,1,12/5/2001,1.62AUY,S,12/26/2001,1.67,12/27/2001,0.98

<SPAN 
>To run a test using the 
above data:

<SPAN 
> 

<SPAN 
>Take the trade list 
above and save it as "playback.txt" in your Amibroker 
folder.

<SPAN 
> 

<SPAN 
>Load the formula in to 
your AA window.  

<SPAN 
> 

<SPAN 
>Make sure your settings 
are for long and short

<SPAN 
>set your  From To 
dates in AA to 1/1/2001 thru 12/31/2001.

<SPAN 
> 

<SPAN 
>Find the ticker AUY in 
your and make it the current chart. (If you don't have an AUY then you can 
change all instances of it in the above trade list to something you do have just 
for illustration purposes).

<SPAN 
> 

<SPAN 
>Set your Apply To to 
"Current Stock"

<SPAN 
> 

<SPAN 
>Click the Backtest 
button.  Click the report button to see how you're doing with 
your portfolio! 

<SPAN 
> 

<SPAN 
>There you have 
it.

<SPAN 
> 

<SPAN 
>d

<SPAN 
> 
<FONT 
face="Times New Roman" size=3>


<SPAN 
>From:<FONT 
face=Tahoma size=2> Nigel 
Rowe [mailto:rho@xxxxxxxxxxxxxxx] <SPAN 
>Sent: Friday, January 23, 2004 9:26 
PMTo: 
amibroker@xxxxxxxxxxxxxxx<SPAN 
>Subject: Re: [amibroker] Enhancement 
Request - "Playback" Function
<FONT face="Courier New" 
size=2>-----BEGIN PGP SIGNED 
MESSAGE-----<SPAN 
><FONT 
face="Courier New">Hash: SHA1<FONT 
face="Courier New">Greetings Don,<FONT 
face="Courier New">      I was in the mood for a bit of 
a challenge, so....// Inspired 
by a request for a 'playback' feature from Don Upton<FONT 
face="Courier New">// // Simplified 
example, long only and the file format is spec'd for ease of 
// 
implimentation.<FONT 
face="Courier New">//// Input file 
is comma seperated text. // Fields 
are:<FONT 
face="Courier New">//      
0.      Symbol      
      -- without quotes<FONT 
face="Courier New">//      
1.      Entry date      -- in 
datenum() format.  ie xmas day 2003 is 1031225<FONT 
face="Courier New">//      
2.      Entry price <FONT 
face="Courier New">//      
3.      Exit date      -- 
datenum() format, or blank for no exit<FONT 
face="Courier New">//      
4.      Exit Price<FONT 
face="Courier New">Buy = False;Sell 
= False;BuyPrice = 
Close;SellPrice = 
Close;function 
DateToBar(dn)<FONT 
face="Courier New">{<FONT 
face="Courier New">      return 
LastValue(ValueWhen(DateNum()==dn, BarIndex()));<FONT 
face="Courier New">}f = 
fopen("playback.txt", "r");while( f 
&& (! feof(f)) ) {<FONT 
face="Courier New">      Line = 
fgets(f);<FONT 
face="Courier New">      sym = StrExtract(Line, 
0);      
if( sym == Name() ) {<FONT 
face="Courier New">            
endt = StrExtract(Line,1);<FONT 
face="Courier New">            
enpr = StrExtract(Line,2);<FONT 
face="Courier New">            
exdt = StrExtract(Line,3);<FONT 
face="Courier New">            
expr = StrExtract(Line,4);<FONT 
face="Courier New">            
bar = DateToBar(StrToNum(endt));<FONT 
face="Courier New">            
if( bar ) {<FONT 
face="Courier New">            
      Buy[bar] = True;<FONT 
face="Courier New">            
      BuyPrice[bar] = 
StrToNum(enpr);<FONT 
face="Courier New">            
      if( exdt != "" ) {<FONT 
face="Courier New">            
            bar = 
DateToBar(StrToNum(exdt));<FONT 
face="Courier New">            
            Sell[bar] = 
True;      
            
      SellPrice[bar] = 
StrToNum(expr);<FONT 
face="Courier New">            
      }<FONT 
face="Courier New">            
}      
}}<FONT 
face="Courier New">if(f) fclose(f);<FONT 
face="Courier New">I'll leave you to modify it to get exactly what you 
want.<FONT 
face="Courier New">      
NigelOn Fri, 23 Jan 2004 
22:51, Don Upton wrote:> I'd 
like to suggest an enhancement to Amibroker.  Judging from 
recent> messages, I believe 
others might be interested, too.  If so, maybe we 
can> get Tomasz in the 
discussion.<FONT 
face="Courier New">>> I would 
like to see another function (like Scan and Backtest) in AA.  
I'll> call it Playback for 
now.  Playback would essentially be a Backtest, 
but> instead of invoking an AFL 
script, it would prompt for the name of a<FONT 
face="Courier New">> comma-delimited file in which each record would 
represent a trade.  Each> 
record might have the following fields:<FONT 
face="Courier New">>> 1) 
Ticker Symbol> 2) Type Trade 
(Long or Short)> 3) Entry 
Date> 4) Exit Date - null if 
trade still open> 5) 
Shares> 6) Position Entry Price 
(Buy or Short price, depending on type trade) -<FONT 
face="Courier New">> Optional<FONT 
face="Courier New">> 7) Position Exit Price (Sell or Cover price, depending 
on type trade; null> if trade 
still open) - Optional> 8) 
Commission on Entry - Optional> 
9) Commission on Exit - Optional<FONT 
face="Courier New">>> The 
optional fields above would default to the values in AA/Settings if 
not> specified.  The date 
range used for report statistics could be calculated<FONT 
face="Courier New">> based on the earliest trade open and last trade close 
(or current date if> there are 
open trades).  (Or should the date range be based on the 
setting> in the AA window, as 
Backtest currently works ?)<FONT 
face="Courier New">>> A 
Playback function would make it much easier to do "manual" 
-type> backtesting, as well as 
track actual trades...<FONT 
face="Courier New">>> ...Don 
Upton><FONT 
face="Courier New">-----BEGIN PGP SIGNATURE-----<FONT 
face="Courier New">Version: GnuPG v1.2.2 
(GNU/Linux)<FONT 
face="Courier New">iD8DBQFAEdfYBbmcM2pfckkRAh1DAJ0SP/ONsODgnQ+998JuzXYJIITljQCg721n<FONT 
face="Courier New">n1qdRu7Alu4RXOzsbeY2Vqo=<FONT 
face="Courier New">=GaYd-----END 
PGP SIGNATURE-----<FONT 
face="Courier New" size=2>Send BUG REPORTS to 
bugs@xxxxxxxxxxxxx<SPAN 
><FONT 
face="Courier New">Send SUGGESTIONS to 
suggest@xxxxxxxxxxxxx<FONT 
face="Courier New">-----------------------------------------<FONT 
face="Courier New">Post AmiQuote-related messages ONLY to: 
amiquote@xxxxxxxxxxxxxxx (Web page: 
<A 
href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
face="Courier New">--------------------------------------------<FONT 
face="Courier New">Check group FAQ at: <A 
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

<FONT 
face="Courier New" size=2>


<SPAN 
>Yahoo! Groups 
Links

  <SPAN 
  >To visit your group on the 
  web, go to:<A 
  href="">http://groups.yahoo.com/group/amibroker/  
  
  <SPAN 
  >To unsubscribe from this 
  group, send an email to:<A 
  href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  
  
  <SPAN 
  >Your use of Yahoo! Groups 
  is subject to the Yahoo! Terms of 
  Service. 
<FONT face="Times New Roman" 
size=3><FONT 
face="Courier New" size=2>Send BUG REPORTS to 
bugs@xxxxxxxxxxxxx<SPAN 
><FONT 
face="Courier New">Send SUGGESTIONS to 
suggest@xxxxxxxxxxxxx<FONT 
face="Courier New">-----------------------------------------<FONT 
face="Courier New">Post AmiQuote-related messages ONLY to: 
amiquote@xxxxxxxxxxxxxxx (Web page: 
<A 
href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
face="Courier New">--------------------------------------------<FONT 
face="Courier New">Check group FAQ at: <A 
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

<FONT 
face="Courier New" size=2>


<SPAN 
>Yahoo! Groups 
Links

  <SPAN 
  >To visit your group on the 
  web, go to:<A 
  href="">http://groups.yahoo.com/group/amibroker/  
  
  <SPAN 
  >To unsubscribe from this 
  group, send an email to:<A 
  href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  
  
  <SPAN 
  >Your use of Yahoo! Groups 
  is subject to the Yahoo! Terms of 
  Service. Send BUG REPORTS to 
bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
suggest@xxxxxxxxxxxxx-----------------------------------------Post 
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
group FAQ at: <A 
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 


Yahoo! Groups Links
  To visit your group on the web, go to:<A 
  href="">http://groups.yahoo.com/group/amibroker/  

  To unsubscribe from this group, send an email to:<A 
  href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  

  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 



Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 









Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.