PureBytes Links
Trading Reference Links
|
This code takes about 30 seconds to run through a database of about
2000 stocks with about 60 days history of intraday 15-minute data on a
Pentium D 930 (it's a dual core, but only one core is utilized by
AmiBroker) overclocked to 4.2 GHz with 2 GB RAM. If you can fit your
whole database inside RAM it shouldn't take TOO long even with a
slower processor.
--- In amibroker@xxxxxxxxxxxxxxx, "J. Biran" <jbiran@xxx> wrote:
>
>
> THANKS. This is a great starting point for me.
>
> Before I spend a lot of time to develop this
> only to find out at the end that it eats up
> too much CPU time, can you estimate how much
> time this routine uses? (maybe by "Display chart
> timing (Advanced)" with and without).
>
>
>
> Joseph Biran
> ____________________________________________
>
>
> -----Original Message-----
> From: amibroker@xxxxxxxxxxxxxxx On Behalf Of tycanadian2003
> Sent: Tuesday, August 08, 2006 10:42 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: Reading in trades from a CSV file
>
> Hi all,
>
> I have solved my problem...not sure if it's the most efficient
> solution but here's some code that does what I want it to do (sorry if
> the formatting for posting in a forum is lousy, but it's late and I
> don't feel like going through it all to make it pretty :) ):
>
> SetOption("PriceBoundChecking",False);
> PositionSize = 10000;
>
> trades = fopen( "C:\\Documents and
> Settings\\Administrator\\Desktop\\IEC\\TestTradesAmi.csv", "r" );
>
> Buy = 0;
> Short = 0;
>
> if ( trades )
> {
> count = 0;
> while ( ! feof( trades ) )
> {
> string = fgets( trades );
> if ( count != 0 )
> {
> symbol = StrExtract(string, 0);
> symdate = StrExtract(string, 2);
> firstslashindex = StrFind(symdate, "/");
> symmonth = StrToNum(StrLeft(symdate,firstslashindex - 1));
> secondslashindex = StrFind(StrRight(symdate,StrLen(symdate) -
> firstslashindex),"/") + firstslashindex;
> symyear = StrToNum(StrRight(symdate,4));
> symday =
> StrToNum(StrMid(symdate,firstslashindex,secondslashindex -
> firstslashindex - 1));
> symlongshort = StrExtract(string,1);
> symentryprice = StrToNum(StrExtract(string,3));
> if(symbol == Name())
> {
> m = Month();
> y = Year();
> d = Day();
> dt = DateTime();
> for(i=0; i < BarCount; i++)
> {
> Buy[i] = 0;
> Short[i] = 0;
> if(m[i] == symmonth AND d[i] == symday AND y[i] ==
> symyear)
> {
> if ( StrFind(DateTimeToStr(dt[i]),"9:30") )
> {
> if (StrFind(symlongshort,"Long"))
> {
> Buy[i] = 1;
> BuyPrice[i + 1] = symentryprice;
> }
> if (StrFind(symlongshort,"Short"))
> {
> Short[i] = 1;
> ShortPrice[i + 1] = symentryprice;
> }
> }
> }
> else
> {
> Buy[i] = 0;
> Short[i] = 0;
> }
> }
> }
> }
> count++;
> }
> fclose(trades);
> fclose(symout);
> }
>
> timetohold = Optimize("Bars_To_Hold",1,1,25,1);
>
> Sell = BarsSince(Buy) == timetohold;
> Cover = BarsSince(Short) == timetohold;
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "J. Biran" <jbiran@> wrote:
> >
> >
> > It seems other people already solved similar problems with which
> > I am still struggling with.
> >
> > How would I go about a simpler problem (just one symbol):
> > reading an external CSV file with trade(s) information (i.e
> > date/buy(sell) entry time/buy(sell)price/exit time /exit price
> > 1 line per trade) and plotting arrows on the proper price bar
> > at the given price?
> >
> >
> >
> > Joseph Biran
> > ____________________________________________
> >
> >
> > -----Original Message-----
> > From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
> On
> > Behalf Of dingo
> > Sent: Tuesday, August 08, 2006 4:05 PM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: RE: [amibroker] Re: Reading in trades from a CSV file
> >
> > This may give you some ideas.
> >
> > http://finance.groups.yahoo.com/group/amibroker/message/65181
> >
> > d
> >
> >> -----Original Message-----
> >> From: amibroker@xxxxxxxxxxxxxxx
> >> [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of tycanadian2003
> >> Sent: Tuesday, August 08, 2006 5:10 PM
> >> To: amibroker@xxxxxxxxxxxxxxx
> >> Subject: [amibroker] Re: Reading in trades from a CSV file
> >>
> >> Hi there,
> >>
> >> Thanks for the reply, it does provide some insight for me. I
> >> am familiar with the Buy/Sell/Short/Cover and
> >> BuyPrice/Shortprice...arrays, and you were correct in that
> >> the hard part seems to be making it remotely efficient :).
> >> Ideally I'd like to read every ticker, trade type
> >> (long/short), date, and entryprice into arrays within
> >> AmiBroker and then as the backtester iterates over each
> >> symbol, it would check these arrays for any occurrence of the
> >> symbol, and for each occurrence it finds it will look at the
> >> corresponding dates and append a "1" in the "Buy" array for
> >> that date as well as the proper BuyPrice.
> >>
> >> Any further suggestions on how to accomplish this or make it
> >> faster are most welcome!
> >>
> >> Thanks again for the reply.
> >>
> >> --- In amibroker@xxxxxxxxxxxxxxx, "Metasan" <amibroker@> wrote:
> >>>
> >>> That can be implemented by writing code to modify
> >> Buy/Sell/Short/Cover
> >>> and BuyPrice/SellPrice/ShortPrice/CoverPrice
> >>> arrays.
> >>>
> >>> The difficult part is converting date to bar index number.
> >>> The code below will be very very slow since you have to
> >> loop through
> >>> all bars for all trades in your file for all symbols, but may give
> >
> >>> your some ideas:
> >>>
> >>> // loop through every line of the file:
> >>> // assume that ticker, month1, day1, year1, buyprice1 are
> >> the fields
> >>> from the file
> >>>
> >>> if(ticker == Name())
> >>> {
> >>> m = month();
> >>> y = year();
> >>> d = day();
> >>> for(i=0; i<BarCount; i++)
> >>> {
> >>> if(m[i] == month1 and d[i] == days and y[i] == year1)
> >>> { Buy[i] = 1; BuyPrice[i] = buyprice1; }
> >>> }
> >>> }
> >>>
> >>> --- In amibroker@xxxxxxxxxxxxxxx, "tycanadian2003" <tyrules@>
> >>> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> I'm trying to read in trades from a CSV file, whose format is :
> >>>>
> >>>> TICKER,(LONG OR SHORT),DATE,ENTRY PRICE,EXIT PRICE
> >>>>
> >>>> This part I can kind of do (I know how to read and write to
> files).
> >>>> However, I'd like to use this data in backtests for a few
> thousand
> >>>> symbols with intraday data. My confusion comes when I'm trying
> to
> >>>> figure out how to read in all the data from the CSV file and then
> >>>> use it to generate buy and sort signals in the backtester. i.e.
> >>>> if a line in my CSV file is:
> >>>>
> >>>> INTC,Long,08/08/2006,17.40,17.45
> >>>>
> >>>> I want to be able to extract that information in my AFL code,
> >>>> and as I'm backtesting through many symbols, when the backtester
> >>>> gets to INTC, I want it to have a BUY signal for INTC on
> >>>> 08/08/2006 with a buy price of 17.40.
> >>>> In case you're interested, I'm backtesting to try to
> >>>> optimize the best time of day to exit my trades since
> >>>> I recently subscribed to an intraday data service.
> >>>>
> >>>> Efficiency may also be an issue, but for now I'd just love
> >>>> for it to work. Can anyone help me get started?
> >>>> I know how to open the file and grab the strings,
> >>>> but that's about it.
> >>>>
> >>>> Thank you very much!
> >>>>
> >>>> Tyler
>
|