PureBytes Links
Trading Reference Links
|
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.
May I ask what this analysis will tell me
(I have not tried it yet), when there are no “Shares” 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 “Current Stock”,
so we are not analyzing one’s past portfolio but just the stocks or funds
one may have bought in the past, and those one at a time. Correct?
What does it take to expand this to
include many stocks/funds and their positions sizes?
Ken
-----Original Message-----
From: dingo [mailto:dingo@xxxxxxxxxxxx]
Sent: Saturday, January 24, 2004
8:28 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker]
Enhancement Request - "Playback" Function
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
<font size=3
face="Times New Roman">
<span
>From:<font
size=2 face=Tahoma> Nigel
Rowe [mailto:rho@xxxxxxxxxxxxxxx]
Sent: Friday, January 23, 2004
9:26 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker]
Enhancement Request - "Playback" Function
<font size=2
face="Courier New">-----BEGIN PGP SIGNED
MESSAGE-----<span
>
Hash: SHA1
Greetings 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 Price
Buy = 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.
Nigel
On 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+998JuzXYJIITljQCg721n
n1qdRu7Alu4RXOzsbeY2Vqo=
=GaYd
-----END PGP SIGNATURE-----
Send BUG
REPORTS to bugs@xxxxxxxxxxxxx<span
>
Send 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
<font size=2
face="Courier New">
<span
>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.
<font size=3
face="Times New Roman">
Send
BUG REPORTS to bugs@xxxxxxxxxxxxx<font size=2
face="Courier New">
Send 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
<font size=2
face="Courier New">
<span
>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.
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.
|