That's great; thanks Cliff and Doug. With a bit more digging through
the plplot documentation it looks like I can use seconds from the
epoch, add "d" to the XBOX flags, and set the output format with
pltimefmt. Here is the revised code if anyone is interested:
sub plot_returns {
my ( $dates, $values, $mkt_values ) = @_;
# Convert dates 'YYYY-MM-DD' into seconds since the epoch
my $strp = DateTime::Format::Strptime->new(
pattern => '%F',
locale => 'en_US',
time_zone => 'America/New_York'
);
my $x = pdl map { $strp->parse_datetime($_)->epoch } @$dates;
# Calculate the returns: x[i] / x[i-1] - 1
my $returns = $values / $values->(0) - 1;
my $mkt_returns = $mkt_values / $mkt_values->(0) - 1;
# Create the plot
my $pl = PDL::Graphics::PLplot->new( DEV => "xwin", );
PDL::Graphics::PLplot::pltimefmt("%b %y");
$pl->xyplot(
$x, $returns,
TITLE => 'Portfolio Return',
XBOX => 'adnst',
COLOR => 'BLUE',
CHARSIZE => 0.75,
YLAB => 'Return',
BOX => [ $x->minmax, cat( $returns, $mkt_returns )->minmax ],
);
$pl->xyplot( $x, $mkt_returns, COLOR => 'BLACK', );
$pl->close;
}
The result is pretty darn close to what I need. I'll try to submit a
patch to PDL::Graphics::PLplot to document the "d" flag.
Thanks!
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl