Brief background:
I am trying to plot Candlestick charts of Stocks, by using QCustomPlot version 1.3 beta. I skipped through the library's code, and found out that for the time-series, it uses a type-def (qcustomplot.h:line 3140)
typedef QMap<double, QCPFinancialData> QCPFinancialDataMap;
Where QCPFinancialData is (qcustomplot.h:line 3124)
class QCP_LIB_DECL QCPFinancialData
{
public:
QCPFinancialData();
QCPFinancialData(double key, double open, double high, double low, double close);
double key, open, high, low, close;
};
So, the OHLC data is obviously there, and the class uses a key, which is used in the QMap, to index the Time-series entry.
So, the obvious key, would be the date-time (I am plotting End-Of-Day charts, so each entry is simply a date, no time used). In my Parsing code, I've used
boost::gregorian::date
Since it has quite a lot of advantages (conversion from string, calculation of date-time elapsed, etc).
Question is, should I go ahead and simply convert the boost::gregorian::date to a unix timestamp, and then record that timestamp as a double? I found a small template function on github that converts it to time_t type, but I guess double shouldn't be a problem in this case, or is this a potential bug? AFAIK, Unix time-stamp denotes the seconds since Jan 01 1970, which when represented as a double should be more than enough for a key?
In the examples of QCustomPlot, they use an accumulator/counter since the beginning of the time series sequence (e.g., starting date) rather than the time-stamp.
A timestamp since the epoch can be stored quite conventiently in a double as you have enough space for the seconds since the epoch (ie Jan 1, 1970) and still have enough resolution for a little more than a microsecond.
Eg R does this:
I used these as
double
at the C/C++ layer all the time. And if I am not mistaken, you can get Boost to do the conversion for you.Edit: I knew I had it somewhere:
A conversion to
time_t
including subseconds: