PureBytes Links
Trading Reference Links
|
> > You can do it with perl as a single program.
>
> Isn't perl a programming language ? If so, it will give you a very
> steap learning curve wich i would not want to use.
Only if you have to write it yourself.
Here is a trivial Perl script that will shift time by a specified
amount of minutes. Assuming you have perl installed, and you
write out the attached script to "timeshift.pl", you call it like
this:
perl timeshift.pl MinutesToShift < OldFile > NewFile
(Open a Command window and call it from there.)
So e.g. if you want to shift EST-stamped data to CST, you need to
subtract 60 minutes:
perl timeshift.pl -60 < ESTFile.csv > CSTFile.csv
If you have a 5min file that is timestamped at the start of the
bar, you'll want to add 5 minutes to shift the timestamp to the
end of the bar the way TS wants it:
perl timeshift.pl 5 < StartBar.csv > EndBar.csv
Note that this script will NOT handle shifting minutes over a day
boundary. So if you want to shift globex data that spans
midnight, you'll have to find another solution.
Now you just need to install Perl. You can get it at
http://www.perl.com/pub/a/language/info/software.html#binary,
which will direct you to
http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl
This script doesn't handle converting 1-minute bars to N-minute,
but TS does that just fine. Just read your shifted file into TS
as ASCII (HistoryCentre is not required in this case), specify
the bar size you want, then write out the file from TS. (In
TS2k that's View -> Data Window, right-click in Data Window,
choose Send To File...)
Gary
# timeshift.pl:
# Shift the time field of an ASCII data file by a specified amount.
# Assumes a comma-separated list, with time in the second field.
#
if ($#ARGV < 0) { die "Usage: perl timeshift.pl MinutesToShift\n"; }
$shift = $ARGV[0];
while (defined($line = <STDIN>)) {
if ( (index(lc($line), "date") >= 0) ){ # don't process header
print $line;
}
else {
chomp($line);
($date, $time, $rest) = split(/,/, $line, 3);
$time =~ s/://; # Remove ":", if present
$minutes = 60*int($time / 100) + ($time % 100);
$minutes2 = $minutes + $shift;
$time2 = 100*int($minutes2 / 60) + ($minutes2 % 60);
printf("%s,%04d,%s\n", $date, $time2, $rest);
}
}
|