[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: How to increment dates in a for loop?



PureBytes Links

Trading Reference Links



Typo correction in the If block: 

YearStr2 =
NumToStr(YearNum2);

But it still does not work.


--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Thanks Steve and Herman. I have been looking at BarIndex wrt your
> suggestions, and don't seem to understand it. Maybe I'm just retarded
> (...very possible. Heh).
>
> So instead, I've gone down the string conversion/parser route. This
> route makes sense to me. The below simplified code should do the trick.
> But of course it doesn't. It's rare that my first crack at coding
> something ever works.
>
> This is a very simple parser to roll over the month-day of "1301" to
> "0101" and increment the Year by one. I output to the interpretation
> window for debugging.
>
> For some reason, I am getting some mysterious decimal places in the
> output, despite my formatting of the string. And I think it is the
> decimals that are screwing up the parser.
>
> Anyone have any insights as to why the below code does not work
> correctly?
>
>
> BegISdate = 1031201;
> EndISdate = 1090201;
> StepIS = 100;
>
>
> for ( X = BegISDate; X <= EndISdate; X = X + StepIS )
> {
>
> Xstr = NumToStr( round(X) );
>
> YearStr = StrLeft( Xstr, 3 );
> YearNum = StrToNum(YearStr);
>
> MonthDayStr = StrRight( Xstr, 4 );
>
>
> if ( MonthDayStr == "1301" )
> {
> YearNum2 = YearNum + 1;
>
> YearStr2 = StrToNum(YearNum2);
>
> Xstr = StrReplace(Xstr,"1301", "0101");
> Xstr = StrReplace(Xstr,YearStr, YearStr2);
> }
>
> printf(Xstr+"%.0f\n");
>
> }
>
>
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" sjdugas@ wrote:
> >
> > I would think you could associate your dates to BarIndex() and
> increment that by 100, something like...
> >
> > BegISbar = Valuewhen( DateNum() == BegISdate, BarIndex() );
> > EndISbar = Valuewhen( DateNum() == EndISdate, BarIndex() );
> > ...
> > for (FromISbarNum = BegISbar; FromISbarNum <= EndISbar; FromISbarNum =
> FromISbarNum + StepIS)
> >
> > ----- Original Message -----
> > From: ozzyapeman
> > To: amibroker@xxxxxxxxxxxxxxx
> > Sent: Tuesday, May 12, 2009 8:18 PM
> > Subject: [amibroker] How to increment dates in a for loop?
> >
> >
> >
> >
> > Hello, hoping someone can point out a good method for incrementing
> dates. I am currently trying to build a basic Walk-Forward engine that
> does an Optimization on In-Sample (IS) data using one formula, followed
> by an Optimization on Out-Of-Sample (OOS) data using a second formula.
> >
> > This is different than AB's built-in WF engine, which performs an
> Optimization, followed by a Backtest using only one formula.
> >
> > Anyway, I am currently stuck right at the beginning, trying to
> figure out a sensible way to increment dates. This is what I have so
> far:
> >
> > // datenum format: 10000 * (year - 1900) + 100 * month + day,
> > // so 2001-12-31 becomes 1011231 and 1995-12-31 becomes 951231
> >
> > BegISdate = 1031201;
> > EndISdate = 1090201;
> > StepIS = 100;
> >
> > BegOOSdate = 1050101;
> > EndOOSdate = 1090301;
> > StepOOS = 100;
> >
> > Formula1 = "F:\\formula1.afl";
> > Formula2 = "F:\\formula2.afl";
> > Database = "F:\\AB Databases\\MyDB";
> > Settings = "F:\\My Settings.ABS";
> >
> >
> > for (FromISdateNum = BegISDate; FromISdateNum <= EndISdate;
> FromISdateNum = FromISdateNum + StepIS)
> > {
> >
> > AB = CreateObject("Broker.Application");
> >
> > // Etc. .........
> >
> > Now the above won't exactly work because simply adding 100 to a
> datenum will not allow the datenum to correctly roll over from December
> to January. For example, incrementing 1031201 by 100 yields 1031301
> instead of 1040101.
> >
> > I know I can first convert the datenum to a string, then build a
> parser that splits the datenum apart and analyzes the last four digits,
> converting 1301 to 0101, then reconstitute the string and reconvert to a
> datenum again. But that all feels rather convoluted.
> >
> > Is there an easier way to increment dates in AFL? I've searched the
> help manual and can't seem to find anything. What if I first converted
> to DateTime format? Is there an easy way to step through that format
> month by month?
> >
> > Any pointers much appreciated.
> >
> > And when I complete the WF Opt-Opt engine, I will be happy to post
> it here, in case anyone else has a need for it.
> >
> > Thanks!
> >
>


__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___