Time series for intraday charts (mon-fri, 9.30 - 4.00pm)
-
- Posts: 6
- Joined: Wed Dec 27, 2006 1:03 am
See if this works for you. Although the weekend gap is removed with this code, I find that zoom-in/zoom-out doesn't work quite right, and the labels sometimes overlap. There also appears to be a performance issue with the SegmentedTimeline that has too many base time exclusions, although I have not investigated it fully. I think those are the bugs in the SegmentedTimeline itself.
Code: Select all
package com.jsystemtrader.chart;
import java.util.*;
import org.jfree.chart.axis.*;
public class MarketTimeLine {
private static final long MILLIS_IN_MINUTE = 60 * 1000;
private static final long MILLIS_IN_DAY = MILLIS_IN_MINUTE * 60 * 24;
private static final long MARKET_OPEN_TIME = (9 * 60 + 30) * MILLIS_IN_MINUTE;
private static final int TRADING_MINUTES = 6 * 60 + 30;
private static final int NON_TRADING_MINUTES = 17 * 60 + 30;
private static final int WEEKEND_MINUTES = 65 * 60 + 20; // from 16:05 Fri to 9:25 Mon
private final int barSizeInMinutes;
private final long startTime, endTime;
public MarketTimeLine(int barSizeInMinutes, long startTime, long endTime) {
this.barSizeInMinutes = barSizeInMinutes;
this.startTime = startTime;
this.endTime = endTime;
}
public SegmentedTimeline getNormalHoursTimeline() {
long segmentSize = barSizeInMinutes * MILLIS_IN_MINUTE;
int segmentsIncluded = TRADING_MINUTES / barSizeInMinutes;
int segmentsExcluded = NON_TRADING_MINUTES / barSizeInMinutes;
SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded);
timeline.setAdjustForDaylightSaving(true);
timeline.setStartTime(startTime);
timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
Calendar lastBarDate = Calendar.getInstance();
lastBarDate.setTimeInMillis(endTime);
Calendar now = Calendar.getInstance();
now.setTimeInMillis(startTime);
now.set(Calendar.HOUR_OF_DAY, 16);
now.set(Calendar.MINUTE, 5);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
// find the first Friday
while (now.get(Calendar.DAY_OF_WEEK) != Calendar.FRIDAY) {
now.add(Calendar.DAY_OF_YEAR, 1);
}
// exclude weekends
while (now.before(lastBarDate)) {
long excludeFrom = now.getTimeInMillis();
long excludeTo = excludeFrom + WEEKEND_MINUTES * MILLIS_IN_MINUTE;
timeline.addBaseTimelineExclusions(excludeFrom, excludeTo);
now.add(Calendar.DAY_OF_YEAR, 7); // move to next Friday
}
return timeline;
}
public SegmentedTimeline getAllHoursTimeline() {
SegmentedTimeline timeline = new SegmentedTimeline(SegmentedTimeline.DAY_SEGMENT_SIZE, 7, 0);
return timeline;
}
}
dave, any ideas about periodaxis class?
david.gilbert wrote:I will look at this when I get time. I didn't write the segmented timeline code, so I don't know it so well. I know it works well for some people and not well for others - in the medium term, I'd like to find an alternative implementation that's easier to debug (for me anyway), perhaps based on the PeriodAxis class.
Re: Time series for intraday charts (mon-fri, 9.30 - 4.00pm)
As in documentation it is said:
""
in code of this method is:
""
and if you just search where the
is used, you will see, that is uesed in 3 other methods:
- which adds some exception to baseTimeline,
- same here, and
.
Note that this getter is not used anywhere else.
So my question is, where is implementation, that allows to add weekends as an exceptions to segmentedTimeline, which is above baseTimeline?
Summary: Adding baseTimeline to any timeline does nothing.
Why???????
"
Code: Select all
/**
* Factory method to create a 15-min, 9:00 AM thought 4:00 PM, Monday
* through Friday SegmentedTimeline.
* <P>
* This timeline uses a segmentSize of FIFTEEN_MIN_SEGMENT_SIZE. The
* segment group is defined as 28 included segments (9:00 AM through
* 4:00 PM) and 68 excluded segments (4:00 PM through 9:00 AM the next day).
* <P>
* In order to exclude Saturdays and Sundays it uses a baseTimeline that
* only includes Monday through Friday days.
* <P>
* The <code>startTime</code> of the resulting timeline will be 9:00 AM
* after the startTime of the baseTimeline. This will correspond to 9:00 AM
* of the first Monday after 1/1/1900.
*
* @return A fully initialized SegmentedTimeline.
*/
public static SegmentedTimeline newFifteenMinuteTimeline()
in code of this method is:
"
Code: Select all
timeline.setBaseTimeline(newMondayThroughFridayTimeline());
and if you just search where the
Code: Select all
SegmentedTimeline baseTimeline
Code: Select all
public void addBaseTimelineException(long domainValue)
Code: Select all
public void addBaseTimelineExclusions(long fromBaseDomainValue,
long toBaseDomainValue)
Code: Select all
public SegmentedTimeline getBaseTimeline()
Note that this getter is not used anywhere else.
So my question is, where is implementation, that allows to add weekends as an exceptions to segmentedTimeline, which is above baseTimeline?
Summary: Adding baseTimeline to any timeline does nothing.
Why???????