|
Intraday Charting Q |
Posted by Kumar on Feb-26-2013 13:25 |
|
Hi Peter,
I had sent an email earlier, but wasn't sure if it reached you. Could you please help me with
the following doubt?
1) Until now we were only using charting for EOD and now trying it for intraday. Code is
written, chart is being drawn just fine. The problem is that aggregation isn't happening
properly. Is there an easy way of converting the data fetched?
In our DB, we have 1 minute data and are trying to display 1/2/3/5/10 minute intervals. In
each case, we are fetching all the data available and need to display only as requested.
However, right now everything is being displayed at 1 minute interval. I guess we are pretty
close and need to get something on the lines of convertDailyToMonthlyData. May be a
convertMinuteTo2MinuteDate, convertMinuteTo5MinuteDate etc.
2) During intraday chart display, all the data that we fetch the next minute/time, is there a
way to cache it because previous data doesn?t change? For example, trading day starts @
930AM. @ 10AM, we have 30 minutes data in the DB. @ 1001AM, the data/chart
fetched/displayed wouldn?t change for prices between 930-1000AM. If there is a way to
cache, we could only fetch the next 1 minute at anytime. This way we will save a lot on DB
roundtrips, bandwidth usage and time taken to redraw the next bar.
Please Help.
Thanks
Kumar |
Re: Intraday Charting Q |
Posted by Peter Kwan on Feb-27-2013 02:10 |
|
Hi Kumar,
1. If you do not have the data in the format you need, you can always write code to convert your data to the format you need.
Note that the convertDailyToMonthlyData, etc, are part of the sample code. It is expected you would modify the sample code to fit your own needs, such as creating a function convertMinuteTo5MinuteDate or any function that may fit your conversion needs.
As I am not of your programming language, I will use PHP as an example. For using 10 minute intevals, the aggregation boundary can be easily determined by checking which 10 minute slot a certain timeStamps falls intto.
#aggregator for 10 minute inteval
for ($i = 0; $i < count($timeStamps); ++$i)
$boundary[$i] = (($i == 0) || (floor($timeStamps[$i] / 600) != floor($timeStamps[$i - 1] / 600))) ? $timeStamps[$i] : NoValue;
After determining the aggregator, data can be aggregated as usual:
aggregateData(new ArrayMath($boundary));
2) Yes. You can always cache your data in anyway to you like. For example, you can cache the data you have already obtained in RAM (eg. as array variables) instead of getting it from the database. In this way, you can add new data to RAM, and when you need data to plot the chart, you can get it from RAM. ChartDirector does not require the data to be from a database.
Hope this can help.
Regards
Peter Kwan |
Re: Intraday Charting Q |
Posted by Kumar on Feb-27-2013 08:10 |
|
Amazing! Thank you for your prompt response/help. That did help further. I have couple
follow up q, please.
1) After using the sample 10 min interval function, all of the data is now transformed (the
date/time). All times now by default start @ 00:00 instead of the DB entered/fetched
time. Can you please help in figuring out how to go about it?
2) Regarding caching, is there a function/mechanism that i can use in CD itself? I mean,
how can this be done via a program? We will have to reinvent the wheel for this.
Hence, before venturing that route, i wanted to see if there is a pre-defined
function/method/process that i can use to implement this.
Please help
KK
Peter Kwan wrote:
Hi Kumar,
1. If you do not have the data in the format you need, you can always write code to
convert your data to the format you need.
Note that the convertDailyToMonthlyData, etc, are part of the sample code. It is
expected you would modify the sample code to fit your own needs, such as creating a
function convertMinuteTo5MinuteDate or any function that may fit your conversion
needs.
As I am not of your programming language, I will use PHP as an example. For using 10
minute intevals, the aggregation boundary can be easily determined by checking which 10
minute slot a certain timeStamps falls intto.
#aggregator for 10 minute inteval
for ($i = 0; $i < count($timeStamps); ++$i)
$boundary[$i] = (($i == 0) || (floor($timeStamps[$i] / 600) != floor($timeStamps[$i -
1] / 600))) ? $timeStamps[$i] : NoValue;
After determining the aggregator, data can be aggregated as usual:
aggregateData(new ArrayMath($boundary));
2) Yes. You can always cache your data in anyway to you like. For example, you can
cache the data you have already obtained in RAM (eg. as array variables) instead of
getting it from the database. In this way, you can add new data to RAM, and when you
need data to plot the chart, you can get it from RAM. ChartDirector does not require the
data to be from a database.
Hope this can help.
Regards
Peter Kwan
|
Re: Intraday Charting Q |
Posted by Peter Kwan on Feb-27-2013 23:51 |
|
Hi Kumar,
1) I have just modified the original "Interactive Financial Chart" sample code to use 1 minute data for an intraday chart (duration = 1 day), with the aggregate code in my last message to aggregate it to 10 minutes per data point, and it works normally. I have attached the code and the chart generated. The labels on the x-axis is 9:30am, 10:00am, 11:00am, etc.. There are 6 candlesticks between two labels (showing that they are 10 minutes per candlestick).
If you think there are issues, is it possible to provide an runnable example to illustrate the problem? You may use the same "Interactive Finance Chart", but replace the random numbers with your real data hard coded.
2) For caching, you do not need to reinvent the wheel. As it is a common database issue (not related or specific to charts), there should be plenty of caching systems available.
For example, in PHP, you may use shared memory session storage, memcached, etc.. You may use google to search for common caching systems.
For desktop applications (as opposed to web applications), you just need to store the data in a variable and do not destroy the variable. The data are then in memory. There is no need to have additional caching system at all.
Hope this can help.
Regards
Peter Kwan
|
Re: Intraday Charting Q |
Posted by Kumar on Feb-28-2013 04:03 |
|
Peter,
Thanks a bunch again for prompt help.
After going through your code and over 5 hours of debugging, i realized that the
date/time formation/retrieval from DB and how it was being populated into the chart is
different between daily and intraday charts. After fixing it, things look good now.
Regarding caching, i will look into it further.
Thanks again for your great support.
KK
Peter Kwan wrote:
Hi Kumar,
1) I have just modified the original "Interactive Financial Chart" sample code to use 1
minute data for an intraday chart (duration = 1 day), with the aggregate code in my last
message to aggregate it to 10 minutes per data point, and it works normally. I have
attached the code and the chart generated. The labels on the x-axis is 9:30am,
10:00am, 11:00am, etc.. There are 6 candlesticks between two labels (showing that they
are 10 minutes per candlestick).
If you think there are issues, is it possible to provide an runnable example to illustrate the
problem? You may use the same "Interactive Finance Chart", but replace the random
numbers with your real data hard coded.
2) For caching, you do not need to reinvent the wheel. As it is a common database issue
(not related or specific to charts), there should be plenty of caching systems available.
For example, in PHP, you may use shared memory session storage, memcached, etc.. You
may use google to search for common caching systems.
For desktop applications (as opposed to web applications), you just need to store the
data in a variable and do not destroy the variable. The data are then in memory. There is
no need to have additional caching system at all.
Hope this can help.
Regards
Peter Kwan
|
|