PureBytes Links
Trading Reference Links
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks, 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.
Nigel
On 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)
iD8DBQFAEyCnBbmcM2pfckkRAkQaAJ9kDcAbO7DmPFlliQu3599rEAYGxQCgvimz
2VY0QhEgpnqZ6vqpObmeSD4=
=I31v
-----END PGP SIGNATURE-----
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:
http://docs.yahoo.com/info/terms/
|