Loading ...
Sorry, an error occurred while loading the content.

Re: [amibroker-ts] Re: testing STOCK data that has ceased to trade

Expand Messages
  • tom soyer
    Terry, if you use actual prices for backtesting, then how do you deal with stock splits and ex-dividend? CSI data uses inactive flag to indicate extinct
    Message 1 of 7 , Oct 3, 2006
    View Source
    • 0 Attachment
      Terry, if you use actual prices for backtesting, then how do you deal with
      stock splits and ex-dividend?

      CSI data uses "inactive" flag to indicate extinct stocks. In addition, it
      recordes the date that a series ends. Perhaps in the future AB could add a
      property to filter extinct stocks.


      On 10/3/06, Terry <MagicTH@...> wrote:
      >
      > Moztrader,
      >
      > I use CSI Data which has extinct stocks, a "must have" feature IMO. I
      > use the following code to exit / not enter positions if the stock is
      > about to be extinct. Unfortunately this does not work real-time because
      > AB evaluates one stock at a time and the last bar -- even if it's two
      > years old -- is considered to be the "current date". This also means
      > that ALL STOCKS appear to be going extinct on their last bar even if
      > that bar is TODAY! (Yes, I tried comparing dates to NOW(), but that
      > didn't work either and I don't recall why at this point.)
      >
      > Hence, I keep two databases (a trick learned from b519b who also uses
      > CSI Data). The code recognizes which database I am in and uses the
      > "extinct" detection for my backtesting data and does not use it for R/T
      > data.
      >
      > If anyone (like Tomasz) can tell me a way around this, I would be
      > grateful!
      >
      > There is also code below to locate the actual price of the stock, which
      > is another "must have" feature of back-testing stocks.
      >
      > /****************** BASIC NEEDS of CSI DATA ******************/
      >
      > dbName = GetDatabaseName();
      >
      > //>>>>>>>>>>>>>>>>>>>>>>>>>> 1st future reference - looks ahead to find
      > extinct stocks just to terminate those trades
      >
      > ThisIsLastBar = BarIndex() == LastValue( BarIndex() ); //Finds the last
      > bar of data for current Symbol
      >
      > //>>>>>>>>>>>>>>>>>>>>>>>>>> 2nd future reference - Only use for Explore
      > since it looks to tomorrow to find the exit price
      >
      > exitPrice = IIf(ThisIsLastBar, C, Ref(O,1));
      >
      > if (StrLeft(dbName,3) == "CSI") Price = OI/100; else Price = C; //Always
      > use actual price on CSI Databases. Other db use the adjusted Close.
      >
      > if (dbName == "CSI_Research") //Always filter extinct stocks on
      > CSI_Research data
      >
      > {
      >
      > GoingInactiveIn2Bars = (Ref(ThisIsLastBar, 2) AND Ref(DateNum(), 2)
      > != Now(3)) * 16; //Looks ahead 2 bars to see if no more data. Future
      > look will MATCH current DateNum if last bar is actually the current day.
      >
      > }
      >
      > else
      >
      > {
      >
      > GoingInactiveIn2Bars = False;
      >
      > }
      >
      > Active = BarIndex() > 50 AND NOT GoingInactiveIn2Bars; //Wait X days for
      > the first signal AND don't enter if stock is about to go away.
      >
      > Note: You can use the last variable "Active" in your Buy/Sell statements
      > to avoid trading stocks that are not "Active".
      >
      > --
      >
      > Terry
      >
      > -----Original Message-----
      > From: amibroker-ts@yahoogroups.com <amibroker-ts%40yahoogroups.com>[mailto:
      > amibroker-ts@yahoogroups.com <amibroker-ts%40yahoogroups.com>]
      > On Behalf Of intermilan04
      > Sent: Tuesday, October 03, 2006 11:19
      > To: amibroker-ts@yahoogroups.com <amibroker-ts%40yahoogroups.com>
      > Subject: [amibroker-ts] Re: testing STOCK data that has ceased to trade
      >
      > There may be a way to do what you want to do, but I just delete the
      > symbol altogether. Your system should not stop working just because
      > one symbol was removed.
      >
      > intermilan04
      >
      > --- In amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com>
      > yahoogroups.com, "moztrader" <das300@...> wrote:
      > >
      > > HI,
      > > I have stock data in my NASDAQ AB database that has ceased trading (
      > > no more OHCL data after say eg. may 2006 ). When back testing
      > > sometimes my trading systems do not exit these stocks leaving them in
      > > an OPEN POSITION till the end of period.
      > > The problem is that this stock would have been exited in MAY06 and
      > > another trade taken with available equity .
      > >
      > > I can solve this problem by ignoring this stock but it would be better
      > > if i could exit this STOCK if I could detect it has ceased trading .
      > >
      > > Does anyone know how I could code this or ideas ?
      > >
      > > Regards
      > > Moztrader
      > >
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Tomasz Janeczko
      Hello, ... Hmm... I don t quite understand. If given symbol is two years old then LastBar( DateNum() ) will be that of TWO YEARS ago, and definitely not
      Message 2 of 7 , Oct 4, 2006
      View Source
      • 0 Attachment
        Hello,

        >Unfortunately this does not work real-time because
        > AB evaluates one stock at a time and the last bar -- even if it's two
        > years old -- is considered to be the "current date".

        Hmm... I don't quite understand. If given symbol is two years old then
        LastBar( DateNum() ) will be that of TWO YEARS ago, and definitely not "current".

        (unless you use "Pad and align" feature - then "LAST BAR" would be the one of the reference
        symbol, not the "current symbol" one. )

        So to detect inactive symbol for say 10 days you can use:

        lastday = LastValue( DayOfYear() + 365 * Year() );
        nowday = Now( 10 ) + 365 * Now( 8 );

        if( nowday - lastday > 10 )
        {
        // this symbol is not trading for at least 10 calendar days
        }

        Best regards,
        Tomasz Janeczko
        amibroker.com
        ----- Original Message -----
        From: "Terry" <MagicTH@...>
        To: <amibroker-ts@yahoogroups.com>
        Sent: Wednesday, October 04, 2006 12:19 AM
        Subject: RE: [amibroker-ts] Re: testing STOCK data that has ceased to trade


        > Moztrader,
        >
        >
        >
        > I use CSI Data which has extinct stocks, a "must have" feature IMO. I
        > use the following code to exit / not enter positions if the stock is
        > about to be extinct. Unfortunately this does not work real-time because
        > AB evaluates one stock at a time and the last bar -- even if it's two
        > years old -- is considered to be the "current date". This also means
        > that ALL STOCKS appear to be going extinct on their last bar even if
        > that bar is TODAY! (Yes, I tried comparing dates to NOW(), but that
        > didn't work either and I don't recall why at this point.)
        >
        >
        >
        > Hence, I keep two databases (a trick learned from b519b who also uses
        > CSI Data). The code recognizes which database I am in and uses the
        > "extinct" detection for my backtesting data and does not use it for R/T
        > data.
        >
        >
        >
        > If anyone (like Tomasz) can tell me a way around this, I would be
        > grateful!
        >
        >
        >
        > There is also code below to locate the actual price of the stock, which
        > is another "must have" feature of back-testing stocks.
        >
        >
        >
        >
        >
        > /****************** BASIC NEEDS of CSI DATA ******************/
        >
        >
        >
        > dbName = GetDatabaseName();
        >
        > //>>>>>>>>>>>>>>>>>>>>>>>>>> 1st future reference - looks ahead to find
        > extinct stocks just to terminate those trades
        >
        > ThisIsLastBar = BarIndex() == LastValue( BarIndex() ); //Finds the last
        > bar of data for current Symbol
        >
        > //>>>>>>>>>>>>>>>>>>>>>>>>>> 2nd future reference - Only use for Explore
        > since it looks to tomorrow to find the exit price
        >
        > exitPrice = IIf(ThisIsLastBar, C, Ref(O,1));
        >
        > if (StrLeft(dbName,3) == "CSI") Price = OI/100; else Price = C; //Always
        > use actual price on CSI Databases. Other db use the adjusted Close.
        >
        > if (dbName == "CSI_Research") //Always filter extinct stocks on
        > CSI_Research data
        >
        > {
        >
        > GoingInactiveIn2Bars = (Ref(ThisIsLastBar, 2) AND Ref(DateNum(), 2)
        > != Now(3)) * 16; //Looks ahead 2 bars to see if no more data. Future
        > look will MATCH current DateNum if last bar is actually the current day.
        >
        > }
        >
        > else
        >
        > {
        >
        > GoingInactiveIn2Bars = False;
        >
        > }
        >
        >
        >
        >
        >
        > Active = BarIndex() > 50 AND NOT GoingInactiveIn2Bars; //Wait X days for
        > the first signal AND don't enter if stock is about to go away.
        >
        >
        >
        > Note: You can use the last variable "Active" in your Buy/Sell statements
        > to avoid trading stocks that are not "Active".
        >
        > --
        >
        > Terry
        >
        > -----Original Message-----
        > From: amibroker-ts@yahoogroups.com [mailto:amibroker-ts@yahoogroups.com]
        > On Behalf Of intermilan04
        > Sent: Tuesday, October 03, 2006 11:19
        > To: amibroker-ts@yahoogroups.com
        > Subject: [amibroker-ts] Re: testing STOCK data that has ceased to trade
        >
        >
        >
        > There may be a way to do what you want to do, but I just delete the
        > symbol altogether. Your system should not stop working just because
        > one symbol was removed.
        >
        > intermilan04
        >
        > --- In amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com>
        > yahoogroups.com, "moztrader" <das300@...> wrote:
        >>
        >> HI,
        >> I have stock data in my NASDAQ AB database that has ceased trading (
        >> no more OHCL data after say eg. may 2006 ). When back testing
        >> sometimes my trading systems do not exit these stocks leaving them in
        >> an OPEN POSITION till the end of period.
        >> The problem is that this stock would have been exited in MAY06 and
        >> another trade taken with available equity .
        >>
        >> I can solve this problem by ignoring this stock but it would be better
        >> if i could exit this STOCK if I could detect it has ceased trading .
        >>
        >> Does anyone know how I could code this or ideas ?
        >>
        >> Regards
        >> Moztrader
        >>
        >
        >
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
      • Terry
        Tom, The actual prices are only used for selection purposes. In other words, your if Buy filter requires you to buy stocks $1 or your short filter requires
        Message 3 of 7 , Oct 4, 2006
        View Source
        • 0 Attachment
          Tom,



          The actual prices are only used for selection purposes. In other words,
          your if Buy filter requires you to buy stocks > $1 or your short filter
          requires you to only short stocks > $5. The backtests are conducted on
          the proportionately adjusted prices which account for both splits and
          dividends. This is required because of the splits and dividends.
          Example: CSCO in March, 1990 was a $24 stocks, but the split adjusted
          price is $0.08.



          I did not know CSI had this extinct flag (I almost never open UA at
          all), however, I do know that it is NOT exported to the Amibroker
          database since there is no place to put it. Further, there is no such
          thing as "GetExtraData" for CSI Data (it would be very nice if there
          was). It is also difficult to get CSI to change their export software,
          although they have done it in the past. I asked them several times
          recently to include the Information type of data in their export,
          especially with the new features Tomasz has developed in the current
          beta. I have also asked them to allow Futures data to be exported. They
          thought AB could not handle futures. With Tomasz' help we convinced them
          that this was not true (AB does handle futures). That was several months
          ago. So far, no hard info from CSI on whether or not they will do this.
          To their credit I see that UA 2.9.3 is now posted and UA 2.10.0 is in
          the works, which fixes an export problem with Amibroker.
          http://www.csidata.com/custserv/updates/index.html



          A possible work-around is to export to MetaStock format as I "heard"
          that this export is more flexible and includes some of this data. Then
          one could read the MetaStock formatted data with the AB plugin. I have
          not had time to try this to see a) if it works, b) if the time required
          to do so nightly is reasonable.



          Tomasz just posted how to detect extinct stocks so making your own
          function to call will be easy. Thanks Tomasz, I will test it. His post
          follows:



          Hmm... I don't quite understand. If given symbol is two years old then
          LastBar( DateNum() ) will be that of TWO YEARS ago, and definitely not
          "current".

          (unless you use "Pad and align" feature - then "LAST BAR" would be the
          one of the reference
          symbol, not the "current symbol" one. )

          So to detect inactive symbol for say 10 days you can use:

          lastday = LastValue( DayOfYear() + 365 * Year() );
          nowday = Now( 10 ) + 365 * Now( 8 );

          if( nowday - lastday > 10 )
          {
          // this symbol is not trading for at least 10 calendar days
          }

          --

          Terry

          -----Original Message-----
          From: amibroker-ts@yahoogroups.com [mailto:amibroker-ts@yahoogroups.com]
          On Behalf Of tom soyer
          Sent: Tuesday, October 03, 2006 23:20
          To: amibroker-ts@yahoogroups.com
          Subject: Re: [amibroker-ts] Re: testing STOCK data that has ceased to
          trade



          Terry, if you use actual prices for backtesting, then how do you deal
          with
          stock splits and ex-dividend?

          CSI data uses "inactive" flag to indicate extinct stocks. In addition,
          it
          recordes the date that a series ends. Perhaps in the future AB could add
          a
          property to filter extinct stocks.

          On 10/3/06, Terry <MagicTH@comcast. <mailto:MagicTH%40comcast.net> net>
          wrote:
          >
          > Moztrader,
          >
          > I use CSI Data which has extinct stocks, a "must have" feature IMO. I
          > use the following code to exit / not enter positions if the stock is
          > about to be extinct. Unfortunately this does not work real-time
          because
          > AB evaluates one stock at a time and the last bar -- even if it's two
          > years old -- is considered to be the "current date". This also means
          > that ALL STOCKS appear to be going extinct on their last bar even if
          > that bar is TODAY! (Yes, I tried comparing dates to NOW(), but that
          > didn't work either and I don't recall why at this point.)
          >
          > Hence, I keep two databases (a trick learned from b519b who also uses
          > CSI Data). The code recognizes which database I am in and uses the
          > "extinct" detection for my backtesting data and does not use it for
          R/T
          > data.
          >
          > If anyone (like Tomasz) can tell me a way around this, I would be
          > grateful!
          >
          > There is also code below to locate the actual price of the stock,
          which
          > is another "must have" feature of back-testing stocks.
          >
          > /****************** BASIC NEEDS of CSI DATA ******************/
          >
          > dbName = GetDatabaseName();
          >
          > //>>>>>>>>>>>>>>>>>>>>>>>>>> 1st future reference - looks ahead to
          find
          > extinct stocks just to terminate those trades
          >
          > ThisIsLastBar = BarIndex() == LastValue( BarIndex() ); //Finds the
          last
          > bar of data for current Symbol
          >
          > //>>>>>>>>>>>>>>>>>>>>>>>>>> 2nd future reference - Only use for
          Explore
          > since it looks to tomorrow to find the exit price
          >
          > exitPrice = IIf(ThisIsLastBar, C, Ref(O,1));
          >
          > if (StrLeft(dbName,3) == "CSI") Price = OI/100; else Price = C;
          //Always
          > use actual price on CSI Databases. Other db use the adjusted Close.
          >
          > if (dbName == "CSI_Research") //Always filter extinct stocks on
          > CSI_Research data
          >
          > {
          >
          > GoingInactiveIn2Bars = (Ref(ThisIsLastBar, 2) AND Ref(DateNum(), 2)
          > != Now(3)) * 16; //Looks ahead 2 bars to see if no more data. Future
          > look will MATCH current DateNum if last bar is actually the current
          day.
          >
          > }
          >
          > else
          >
          > {
          >
          > GoingInactiveIn2Bars = False;
          >
          > }
          >
          > Active = BarIndex() > 50 AND NOT GoingInactiveIn2Bars; //Wait X days
          for
          > the first signal AND don't enter if stock is about to go away.
          >
          > Note: You can use the last variable "Active" in your Buy/Sell
          statements
          > to avoid trading stocks that are not "Active".
          >
          > --
          >
          > Terry
          >
          > -----Original Message-----
          > From: amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com>
          yahoogroups.com <amibroker-ts%40yahoogroups.com>[mailto:
          > amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com> yahoogroups.com
          <amibroker-ts%40yahoogroups.com>]
          > On Behalf Of intermilan04
          > Sent: Tuesday, October 03, 2006 11:19
          > To: amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com>
          yahoogroups.com <amibroker-ts%40yahoogroups.com>
          > Subject: [amibroker-ts] Re: testing STOCK data that has ceased to
          trade
          >
          > There may be a way to do what you want to do, but I just delete the
          > symbol altogether. Your system should not stop working just because
          > one symbol was removed.
          >
          > intermilan04
          >
          > --- In amibroker-ts@ <mailto:amibroker-ts%40yahoogroups.com>
          > yahoogroups.com, "moztrader" <das300@...> wrote:
          > >
          > > HI,
          > > I have stock data in my NASDAQ AB database that has ceased trading (
          > > no more OHCL data after say eg. may 2006 ). When back testing
          > > sometimes my trading systems do not exit these stocks leaving them
          in
          > > an OPEN POSITION till the end of period.
          > > The problem is that this stock would have been exited in MAY06 and
          > > another trade taken with available equity .
          > >
          > > I can solve this problem by ignoring this stock but it would be
          better
          > > if i could exit this STOCK if I could detect it has ceased trading .
          > >
          > > Does anyone know how I could code this or ideas ?
          > >
          > > Regards
          > > Moztrader
          > >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >

          [Non-text portions of this message have been removed]





          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.