PureBytes Links
Trading Reference Links
|
<FONT face=Arial
color=#0000ff size=2>Thanks for the start Nigel! Nice piece of code.
<FONT face=Arial
color=#0000ff size=2>
<FONT face=Arial
color=#0000ff size=2>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:
<FONT face=Arial
color=#0000ff size=2>
<FONT face=Arial
color=#0000ff size=2>// Inspired by a request for a 'playback' feature from Don
Upton and initial code by Nigel Rowe
<FONT face=Arial
color=#0000ff size=2>// 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
<FONT face=Arial
color=#0000ff size=2>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.
<FONT face=Arial
color=#0000ff size=2> nDateNum = 10000 * (year - 1900) + 100 * month +
day
<FONT face=Arial
color=#0000ff size=2> 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); 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);
<FONT
color=#0000ff><FONT
size=2>I've run the formula on the following list and it seems to be working very nicely:
<FONT
size=2>
<FONT
size=2>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
class=593031401-25012004>
<FONT
color=#0000ff>To run a test using
the above data:
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>Take the trade list above and save it as "playback.txt"
in your Amibroker folder.
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>Load the formula in to your AA window.
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>Make sure your settings are for long and
short
<FONT
color=#0000ff>set your From To
dates in AA to 1/1/2001 thru 12/31/2001.
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>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
class=593031401-25012004>
<SPAN
class=593031401-25012004>Set your Apply To to "Current
Stock"
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>Click the Backtest button. Click the report
button to see how you're doing with
your portfolio!
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>There you have it.
<SPAN
class=593031401-25012004>
<SPAN
class=593031401-25012004>d
From: Nigel Rowe [mailto:rho@xxxxxxxxxxxxxxx]
Sent: Friday, January 23, 2004 9:26 PMTo:
amibroker@xxxxxxxxxxxxxxxSubject: Re: [amibroker] Enhancement Request
- "Playback" Function
-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1Greetings
Don, I was in the mood for a bit of a
challenge, so....// 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.
Entry date -- in datenum() format. ie xmas
day 2003 is 1031225//
2. Entry price
// 3. Exit
date -- datenum() format, or blank for no
exit// 4. Exit
PriceBuy = False;Sell = False;BuyPrice = Close;SellPrice =
Close;function DateToBar(dn){
return LastValue(ValueWhen(DateNum()==dn, BarIndex()));}f =
fopen("playback.txt", "r");while( f && (! feof(f)) )
{ Line =
fgets(f); sym = StrExtract(Line,
0); if( sym == Name() )
{ endt =
StrExtract(Line,1);
enpr =
StrExtract(Line,2);
exdt =
StrExtract(Line,3);
expr =
StrExtract(Line,4);
bar =
DateToBar(StrToNum(endt));
if( bar ) {
Buy[bar] =
True;
BuyPrice[bar] =
StrToNum(enpr);
if( exdt != "" )
{
bar =
DateToBar(StrToNum(exdt));
Sell[bar] =
True;
SellPrice[bar] =
StrToNum(expr);
}
}
}}if(f) fclose(f);I'll leave you to modify it to get exactly
what you want. 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.>> 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> comma-delimited file in which each
record would represent a trade. Each> record might have the
following fields:>> 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) -> Optional> 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>> 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> 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 ?)>> A Playback function would make it much easier
to do "manual" -type> backtesting, as well as track actual
trades...>> ...Don Upton>-----BEGIN PGP
SIGNATURE-----Version: GnuPG v1.2.2
(GNU/Linux)iD8DBQFAEdfYBbmcM2pfckkRAh1DAJ0SP/ONsODgnQ+998JuzXYJIITljQCg721nn1qdRu7Alu4RXOzsbeY2Vqo==GaYd-----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.
|