Date Format for Mathematica - datetime

As I am trying to plot a few financial time series in Mathematica, I just ran into a problem illustrated in the figure below :
It seems the data are no longer dealt with after Year 2000
Is there a way to fix that ?
What would be the best format to export time series from Bloomberg or Excel to use them in Mathematic (Using version 8).
I do know about the FinancialData function. However, not knowing the exact symbols, it makes it extremely difficult to use Mathematica directly for this.

Why not to use WolframAlpha[...] function - it imports native to Mathematica format and goes up to current dates:
timeseries = WolframAlpha["msft close Jan 1, 2010 to Jan 21 2011",
{{"DateRangeSpecified:Close:FinancialData", 1}, "TimeSeriesData"}];
DateListPlot[timeseries]
That was just an example of input. I am not sure what kind of data you need exactly, but you can get a lot of them via WolframAlpha function. Read this:
1) WolframAlpha
2) Data Formats in Wolfram|Alpha

Use the DateFunction option to tell DateListPlot how to convert dates:
DateFunction -> (DateList[{#, {"MonthNameShort", "YearShort"}}] &)
(The parentheses are important.)

Here's a function to convert those date strings to a format Mathematica can handle better:
dateConv = With[{s = StringSplit[#, "-"]}, {DateList[{s[[2]], "YearShort"}][[1]],
DateList[s[[1]]][[2]]}] &
You can try
DateListPlot[data, DateFunction -> dateConv]
EDIT: Originally I tried DateList[{"Nov-11", {"MonthNameShort", "YearShort"}}] but this tells me String "Nov-
11" cannot be interpreted as a date in format {"MonthNameShort",
"YearShort"}.. Perhaps a bug?

Related

How to convert Unix Time to Human Readable in Integromat?

My preceding module in Integromat gives me an expiration date in UNIX time, which is 1640930400.
When I use the FormatDate function to convert this, I'm getting 12/31/1969 when I was expecting to get 12/31/2021. I can't seem to figure out what I'm doing wrong here. Any help would be much appreciated.
Use this instead to first parse the date and then apply the desired formatting to get the results that you want,
{{formatDate(parseDate(1.date; "X"); "MM/DD/YYYY")}}

Correct format for converting string to R date-time object

I've a system generated date and time format. It looks something like this, "2017-04-12-02.29.25.000000" . I want to convert this format into a standard one so that my system can read this and later on I can convert it into minutes. Someone please help to provide a code in R.
If you're unsure of the format, the guess_formats function in lubridate is pretty helpful:
w <- "2017-04-12-02.29.25.000000"
> lubridate::guess_formats(w, orders = 'YmdHMS')
YOmdHMS YmdHMS
"%Y-%Om-%d-%H.%M.%OS" "%Y-%m-%d-%H.%M.%OS"
orders is the format you want the function to investigate and it outputs the correct representation. If the second entry in the string is the day you can try YdmHMS.
The difference in the two formats in the output in the above example is based on formatting of the second entry (always with a leading zero or not). Trying the first format gives:
> as.POSIXct(w, format = "%Y-%Om-%d-%H.%M.%OS")
[1] "2017-04-12 02:29:25 EDT"
In the as.POSIXct call you may specify the timezone tz if required.

Format POSIX in R (quantstrat)

I'm working on extracting a date from a variable: "curIndex."
Here's what the code looks likes
show(txntime1 <- timestamp(mktdata[curIndex+1L])[,1])
show(txntime <- strftime(txntime1, '%Y-%m-%d %H:%M:%OS6'))
And the output is this:
"##------ Tue Mar 08 14:31:58 2016 ------##"
"NULL"
I'm working within ruleOrderProc of the quantstrat package.
The order time needs to be POSIXlt for the order book. Does anyone know what to do with this funky date format that I'm getting?
If so, thanks!
When all else fails, read the documentation. ;-) ?timestamp says:
The timestamp function writes a timestamp (or other message)
into the history and echos it to the console. On platforms that
do not support a history mechanism only the console message is
printed.
You probably meant to call time or index. Also, the time needs to be POSIXct for the order book, not POSIXlt.

Timezone as +0000 for format-dateTime

I'm trying to format the current datetime in XSLT with an explicit UTC offset (and no other literals and no millis), like: 20140710163601+0200.
However, this <x:value-of select="format-dateTime(current-dateTime(), '[Y0001][M01][D01][H01][m01][s01][z]')"/> gives me this: 20140710164200GMT+02:00. Note that I do not want the GMT part.
If there is no offset, I get 20140710144546.
Is there any way to force an explicit offset and set it to the format I want? Obviously, I could do some string manipulation, but maybe there's a library function I'm overlooking. And then there's the no-timezone result I have to force the format for.
Note that it's no problem for me to build a function around this, but rather I'd use something built in or more elegant.
The XSLT 2.0 spec of format-dateTime() is a bit muddled about timezones, so it may depend on which processor you are using. In 3.0 it's specified that you get the format you want with [Z0000]. Recent versions of Saxon implement the function according to the 3.0 spec, but other processors may well do something different. You might be better off using timezone-from-dateTime() to extract the timezone, and then formatting it using format-number().
Try using (capital) Z instead of (lower-case) z.

Package to parse dates in Common Lisp?

I'm writing a simple web scraper in Common Lisp (SBCL) as a learning exercise, & would like to sort by date. To do this, I'll need to parse dates in the format "MM/DD/YYYY" into universal time.
I could simply tokenise the string & pass the bits into encode-universal-time, but I figure that there must be a built-in function (or popular third-party package) for date parsing. I'd greatly appreciate someone recommending one :-)
This answer is very late but the local-time library is featureful and widely used. It is based on the article The long painful history of time.
It supports :
Time and date arithmetic
ISO 8601 timestring formatted output and parsing
Reader macros to embed timestrings directly in code
Timezone handling (will read unix tzfile format)
Conversion between universal and unix time epochs
Julian date calculation
See the net-telent-date and simple-date-time libraries for Common Lisp. The former has a parse-time function you can use (see parse-time.lisp). Both are included in the QuickLisp library collection.
You could try net-telent-date, which has PARSE-TIME which I think will do what you want.
It's now 2022, and net-telent-date is on github and is also deprecated. Better to find something else.
Many implementations have a UNIX interface and, in same cases, this includes the strptime function.
Antik handles dates and times and includes date/time parsers. The result is a "timepoint" which by default is UTC (CL's "universal-time" is something different, but it can be converted to that).
I use local-time and cl-date-time-parser:
edit: and chronicity for parsing natural language dates and times.
(local-time:parse-timestring "2019-11-13T18:09:06.313650+01:00") ;; OK
(local-time:parse-timestring "2019-11-13") ;;OK
This fails with local-time by default:
(local-time:parse-timestring "2019/11/13")
but it works with Chronicity:
(chronicity:parse "2019/11/13")
#2019-11-13T00:00:00.000000+01:00
and we can set the date separator of local-time to "/":
(local-time:parse-timestring "2019/11/13" :date-separator #\/) ;; OK
There is also the time and datetime separators.
Now a format like ""Wed Nov 13 18:13:15 2019" will fail. We'll use the
cl-date-time-parser library:
(cl-date-time-parser:parse-date-time "Wed Nov 13 18:13:15 2019")
;; 3782657595
;; 0
It returns the universal time which, in turn, we can ingest with the
local-time library:
(local-time:universal-to-timestamp *)
;; #2019-11-13T19:13:15.000000+01:00

Resources