[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>NOTE:  THE CODE BELOW IS NOT WORKING 
CORRECTLY!!!
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>Ack Nigel!
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>I completely overlooked that comment.  
Forest & Trees.
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>Any idea on how to implement the number of shares?  
I've been puttzing around with
<FONT face=Arial 
color=#0000ff size=2>the positionsize and that doesn't work.  I think I'm 
stuck right now.
<FONT face=Arial 
color=#0000ff size=2> 
<FONT face=Arial 
color=#0000ff size=2>I added the number of shares to the end of the table 
(element 6).
Here's 
the code so far:
<FONT face=Arial color=#0000ff 
size=2> 
// 
Inspired by a request for a 'playback' feature from Don Upton//// 
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//      6.      Nbr 
Shares
 
<FONT face=Arial color=#0000ff 
size=2>SetOption("InitialEquity", 100000 );
 
Buy = 
False;Sell = False;BuyPrice = Close;SellPrice = Close;Short = 
False;Cover = False;ShortPrice = Close;CoverPrice = 
Close;
 
<FONT face=Arial color=#0000ff 
size=2>function DateToDateNum(sMMDDYYYY) // date in format 
mm/dd/yyyy{
 
<FONT face=Arial color=#0000ff 
size=2>/*-------------------------------------------------------------  
This function will accept a string in the MM/DD/YYY format  and convert 
it into Amibroker's datenum.
 
  
nDateNum = 10000 * (year - 1900) + 100 * month + day
 
  
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.-------------------------------------------------------------*/
 
<FONT face=Arial color=#0000ff 
size=2>    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;}
 <FONT face=Arial color=#0000ff 
size=2>
function DateToBar(dn){    return 
LastValue(ValueWhen(DateNum()==dn, BarIndex()));}
 
Filter = 1;
 
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);        shrs = 
StrExtract(Line,6);        bar = 
DateToBar(endt);        PositionSize = 
StrToNum(shrs) * StrToNum(enPr);        
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);                
}           
}        }    
}}
 
if(f) fclose(f);
 
 
<FONT 
color=#0000ff>Here's a modified 
table: ( I added a setoption for intial equity of 
100,000)
<SPAN 
class=906500502-25012004> 
<SPAN 
class=906500502-25012004>AUY,L,1/12/2001,3.54,1/17/2001,5.29,28200AUY,L,1/25/2001,4.88,1/29/2001,5.57,30600AUY,L,2/2/2001,5.57,2/21/2001,4.32,30600AUY,S,3/6/2001,3.76,3/7/2001,3.76,35100AUY,S,3/13/2001,5.35,3/14/2001,4.18,24700AUY,S,4/2/2001,3.2,4/10/2001,3.62,50300AUY,S,4/11/2001,3.06,5/3/2001,2.93,45700AUY,L,5/16/2001,3.06,5/18/2001,4.46,47600AUY,L,5/24/2001,4.46,5/25/2001,5.29,47600AUY,L,6/1/2001,4.6,6/5/2001,3.48,54700AUY,S,6/13/2001,3.62,6/21/2001,3.2,52700AUY,S,6/26/2001,3.68,7/12/2001,2.9,57800AUY,S,7/18/2001,3.49,7/19/2001,3.0363,73900AUY,S,7/30/2001,3.34,8/7/2001,2.51,87200AUY,L,8/14/2001,3.34,8/15/2001,2.9058,108900AUY,L,8/17/2001,2.79,8/21/2001,3.1527,113400AUY,S,9/5/2001,3.06,9/7/2001,1.39,116900AUY,S,9/28/2001,2.23,10/2/2001,2.79,247900AUY,L,10/11/2001,3.06,10/12/2001,2.65,135300AUY,L,10/16/2001,2.79,10/19/2001,1.77,128500AUY,L,10/22/2001,2.02,10/30/2001,2.93,112600AUY,L,11/8/2001,2.23,11/14/2001,2.73,148000AUY,L,11/23/2001,1.81,11/29/2001,2.0453,223200AUY,S,12/4/2001,1,12/5/2001,1.62,456600AUY,S,12/26/2001,1.67,12/27/2001,0.98,103900
<FONT face=Arial color=#0000ff 
size=2>d


From: Nigel Rowe [mailto:rho@xxxxxxxxxxxxxxx] 
Sent: Saturday, January 24, 2004 8:49 PMTo: 
amibroker@xxxxxxxxxxxxxxxSubject: Re: [amibroker] Enhancement Request 
- "Playback" Function
-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1Thanks, 
Dingo.The DateToDateNum is a great addition.  (Even if the date 
format is inside out, bloody americans :-)However, for any that use 
the code, please remove the comment  // Simplified example, long only 
and the file format is spec'd for ease of   // implimentation.since 
dingo (btw. what is your name?) has removed the restriction, and I HATE 
COMMENTS THAT LIE!!!Ok, I shouldn't shout, but from a maintenance or 
understanding point of view, having some comments that don't match the code 
mean you can't trust *ANY* of them.      
NigelOn Sun, 25 Jan 2004 12:27, dingo wrote:> Thanks for the 
start Nigel!  Nice piece of code.>> 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:>> // Inspired by a request for a 'playback' feature from 
Don Upton and> initial code by Nigel Rowe> //    
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>> Buy = False;> Sell = False;> BuyPrice = 
Close;> SellPrice = Close;> Short = False;> Cover = 
False;> ShortPrice = Close;> CoverPrice = Close;>> 
function DateToDateNum(sMMDDYYYY) // date in format mm/dd/yyyy> 
{>> 
/*------------------------------------------------------------->   
This function will accept a string in the MM/DD/YYY format>   
and convert it into Amibroker's datenum.>>   nDateNum = 
10000 * (year - 1900) + 100 * month + day>>   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.> 
-------------------------------------------------------------*/>>     
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;> }>>> function DateToBar(dn)> 
{>     return LastValue(ValueWhen(DateNum()==dn, 
BarIndex()));> }>> Filter = 1;>> 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);>                 
}>            
}>         
}>     }> }>> if(f) 
fclose(f);>> I've run the formula on the following list and it 
seems to be working very> nicely:>> 
AUY,L,1/12/2001,3.54,1/17/2001,5.29> 
AUY,L,1/25/2001,4.88,1/29/2001,5.57> 
AUY,L,2/2/2001,5.57,2/21/2001,4.32> 
AUY,S,3/6/2001,3.76,3/7/2001,3.76> 
AUY,S,3/13/2001,5.35,3/14/2001,4.18> 
AUY,S,4/2/2001,3.2,4/10/2001,3.62> 
AUY,S,4/11/2001,3.06,5/3/2001,2.93> 
AUY,L,5/16/2001,3.06,5/18/2001,4.46> 
AUY,L,5/24/2001,4.46,5/25/2001,5.29> 
AUY,L,6/1/2001,4.6,6/5/2001,3.48> 
AUY,S,6/13/2001,3.62,6/21/2001,3.2> 
AUY,S,6/26/2001,3.68,7/12/2001,2.9> 
AUY,S,7/18/2001,3.49,7/19/2001,3.0363> 
AUY,S,7/30/2001,3.34,8/7/2001,2.51> 
AUY,L,8/14/2001,3.34,8/15/2001,2.9058> 
AUY,L,8/17/2001,2.79,8/21/2001,3.1527> 
AUY,S,9/5/2001,3.06,9/7/2001,1.39> 
AUY,S,9/28/2001,2.23,10/2/2001,2.79> 
AUY,L,10/11/2001,3.06,10/12/2001,2.65> 
AUY,L,10/16/2001,2.79,10/19/2001,1.77> 
AUY,L,10/22/2001,2.02,10/30/2001,2.93> 
AUY,L,11/8/2001,2.23,11/14/2001,2.73> 
AUY,L,11/23/2001,1.81,11/29/2001,2.0453> 
AUY,S,12/4/2001,1,12/5/2001,1.62> 
AUY,S,12/26/2001,1.67,12/27/2001,0.98>> To run a test using the 
above data:>> Take the trade list above and save it as 
"playback.txt" in your Amibroker> folder.>> Load the 
formula in to your AA window.>> Make sure your settings are for 
long and short> set your  From To dates in AA to 1/1/2001 thru 
12/31/2001.>> 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).>> Set your Apply To to "Current Stock">> 
Click the Backtest button.  Click the report button to see how you're 
doing> with your portfolio!>> There you have 
it.>> d>-----BEGIN PGP SIGNATURE-----Version: GnuPG 
v1.2.2 
(GNU/Linux)iD8DBQFAEyCnBbmcM2pfckkRAkQaAJ9kDcAbO7DmPFlliQu3599rEAYGxQCgvimz2VY0QhEgpnqZ6vqpObmeSD4==I31v-----END 
PGP SIGNATURE-----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 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.