Time series for intraday charts (mon-fri, 9.30 - 4.00pm)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Martin
Posts: 23
Joined: Thu Apr 24, 2003 10:25 am
Location: Germany-Essen

Any progress?

Post by Martin » Wed Jan 18, 2006 3:42 pm

Hi David,
did you make any progress on this issue?

Martin

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Tue May 09, 2006 12:30 pm

Any updates on this?

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Wed May 17, 2006 11:17 am

Jii wrote:Any updates on this?
Come on :(

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Wed May 31, 2006 12:09 pm

Jii wrote:
Jii wrote:Any updates on this?
Come on :(
Pretty please? :)

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Mon Jun 12, 2006 2:22 pm

Jii wrote:
Jii wrote:
Jii wrote:Any updates on this?
Come on :(
Pretty please? :)
?? 8)

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Mon Jun 19, 2006 8:01 am

Jii wrote:
Jii wrote:
Jii wrote: Come on :(
Pretty please? :)
?? 8)
!! :o

fede
Posts: 20
Joined: Tue May 23, 2006 9:15 am

Post by fede » Mon Jun 19, 2006 2:48 pm

HI!
i got the same problem using segmented timeline to plot intraday Chart.
I figure out doing the following:
I used only a segmented Timeline to remove market close hours.
To remove weekend days, i don't take into account the date of the day, but only the minutes and hours. I manage myself the date of the day.


This mean that if i have to plot an intraday chart for the following days: Friday 1, Saturday 2, Sunday 3, monday 4, Tuesday 5.

When i receive quotes for friday, i create a new Date() which contain only the minute and the hour of the quote. When i receive quotes for following days, i do exactly the same, adding 1000*60*60*24(representation of 1 day in long ) for each new Day. LIke that, i avoid to plot gaps for days for which i don't receive quotes(like weekends).

Sory for my poor English, hope this can help you!

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Wed Jul 05, 2006 7:08 am

Jii wrote:
Jii wrote:
Jii wrote: Pretty please? :)
?? 8)
!! :o
-_- :shock:

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jul 05, 2006 1:26 pm

david.gilbert wrote:I have some ideas for an alternative implementation based on the PeriodAxis class, but won't have time to work on that until after the 1.0.0 release.
I haven't started working on this yet, but I'd like to get onto it soon, as this area of JFreeChart is going to continue to cause trouble. I'll try to keep everyone posted, but please keep reminding me about it as I'm easily distracted.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Fri Jul 07, 2006 10:50 am

Bumpmeister reporting in ;)

RulinSun
Posts: 1
Joined: Mon Jul 10, 2006 4:14 pm

Intraday + mondayToFriday

Post by RulinSun » Mon Jul 10, 2006 4:22 pm

I made this working.

SegmentedTimeline intraDayStockUS = SegmentedTimeline.newFifteenMinuteTimeline();

//mondayToFriday in 15 minutes intervals
SegmentedTimeline weeklyTime = new SegmentedTimeline(intraDayStockUS.getSegmentSize(), 480, 192);

weeklyTime.setStartTime(intraDayStockUS.getStartTime());
intraDayStockUS.setBaseTimeline(weeklyTime);

However, I had trouble to exclude holidays, following code didn't work:

String[] holidays = someHolidayString;

for(int h=0; h<holidays.length; h++){
try{
Date hdate = dff.parse(holidays[h]); //dff dateFormat

intraDayStockUS.addBaseTimelineExclusions(hdate.getTime(),
(hdate.getTime()+86400000));
}
catch(ParseException e) {}
}

Anyone can share the solution for holidays?

Thanks!

Rulin Sun

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu Jul 20, 2006 8:05 am

I had success truncated out the Saturday, Sunday and non-trading/market day.

Although there have some bugs when timezone set wrongly.
I use GMT + 8:00 and it's fine. Sometimes, the label data is overlapping when u zoom too deep.

http://chart.n2nconnect.com/FAChart/NNSP.jsp

Minimum requirements: JRE 1.4.2_04 and above

regards,
Zi Wei.

*By the way, can RunlinSun pass me your demo on the intraday exclusion(using SegmentedTimeline and your overriden class)? (excluded long date everyday... I hope can publish the stable version to help everyone).

Thanks in advance.

Any helps & query on holiday + non-market day exclusion are welcomed, my email is wzwei28@yahoo.com

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Fri Jul 21, 2006 10:46 am

* Demo : http://chart.n2nconnect.com/FAChart/NNSP.jsp
Requirements: JRE 1.4.2_04 and above and set Timezone to GMT+8:00


Sorry due to time constraint, I only able to do a simple solution(demo) for Non-Trading Day Exclusion (Holiday, suspend-day, Saturday, Sunday)

Anyone who interested can plug in this two class (JHistoricalCSChart & ConfigSegmentedTimeline) and u guys & girls can find the keyword 'ziwei', theres the place I had edited.

However if anyone using Apache Http Server or Tomcat Web Server and willing to direct plug in in Web-INF > classes. U may request from me, and I email whole package source for you, jar also can.

* Version : jfreechart-1.0.0-rc1.jar
My email address is wzwei28@yahoo.com (any comments and query are welcomed).
hope can contribute little effort in open source application.


ConfigSegmentedTimeline.java
------------------------------------

Code: Select all

/* 
 * (C) Copyright 2000-2006, by Wong Zi Wei.
 *
 *
 * Original Author	:  	Wong Zi Wei(WZW);
 * Contributor(s)	:  	-;
 * 
 * Email			:	wzwei28@yahoo.com
 *
 * Version 1.0.1    :	21/07/2006(WZW)	Store and calculate the SegmentedTimeline
 *
 * Error Code		:	001
 *						002
 *						003
 *
 *
 */

package cfg;

import java.util.Date;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;

//---segmentedTimeline---
import java.util.Calendar;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import org.jfree.chart.axis.DateTickUnit; 
import org.jfree.chart.axis.SegmentedTimeline;

public class ConfigSegmentedTimeline{
	
	private static long m_lFirstMonday = 0;
	private static ArrayList m_alHDate = new ArrayList(); 
	private static SegmentedTimeline m_segmentedTimeline = null;
	private static JFreeChart m_chart = null;
	private static Date m_aTrdDate[] = new Date[1];
	private static Date m_dtDateInit = null;
	
	public void configSegmentedTimeline(){		
	}
	
	public static void run(){
	  //@@ Segmented Timeline - Exclude Non-Trading Day, Suspended date, Saturday & Sunday
	  Date dtInit = getDateInit();
	  JFreeChart chart = getChart();
	  DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
	  //SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); 
	  SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.DAY_SEGMENT_SIZE, 5, 2); 

	  if(dtInit!=null){	    
	    SimpleDateFormat sdfYC = new SimpleDateFormat("yyyy");
	    SimpleDateFormat sdfMC = new SimpleDateFormat("MM");
	    SimpleDateFormat sdfDC = new SimpleDateFormat("dd");
	    int iYC = Integer.parseInt(sdfYC.format(dtInit));
	    int iMC = Integer.parseInt(sdfMC.format(dtInit));
	    int iDC = Integer.parseInt(sdfDC.format(dtInit));
	   	//-Select your Timezone-
		GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+8")); //use standard GMT + 0
	    //calendar.set(2006, Calendar.MARCH, 25, 12, 0, 0); 
	    Date d1 = calendar.getTime(); 
	    
		//GregorianCalendar calendar = new GregorianCalendar();
		ArrayList alHDate = new ArrayList(); //HDate-Hide Date
		Date aTrdDate[] = getTrdDate();
		Date dtDate = calendar.getTime();
		int iTrdDateLast = aTrdDate.length-1;
		int iIndex = 0;
		if(aTrdDate.length>0){
			Date aTrdDateInit = aTrdDate[0]; 
			Date aTrdDateLast = aTrdDate[iTrdDateLast];
			calendar.setTime(aTrdDateInit); //set init date		
			double dDays = (aTrdDateLast.getTime()-aTrdDateInit.getTime())/1000/60/60/24; //60 minutes, 60 seconds, 24 hour.
			for(int i=0; i<=dDays; i++){
				dtDate = calendar.getTime();	
				if(dtDate.equals(aTrdDate[iIndex])){
					iIndex++;
				}else{
					alHDate.add(dtDate);		
				}
				calendar.add(Calendar.DATE, 1);//increment 1 day		
	    	}
	    }
	    
		int offset = TimeZone.getDefault().getRawOffset();
		TimeZone NO_DST_TIME_ZONE = new SimpleTimeZone(offset, "UTC-" + offset);        
	    Calendar cal = new GregorianCalendar(NO_DST_TIME_ZONE);
	    cal.set(iYC, 0, 1, 0, 0, 0); //can't use iMC and iDC, because the crosshair have bugs in locking data
	    cal.set(Calendar.MILLISECOND, 0);
	    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
	         cal.add(Calendar.DATE, 1);
	    }
	    long lFirstMonday = cal.getTime().getTime();
	    
	    //Store parameter
	    setFirstMonday(lFirstMonday);
	    setHDate(alHDate);
	    setSegmentedTimeline(segmentedTimeline);
	  }
	    
	}	
	
	private static void setFirstMonday(long vs_lFirstMonday){ m_lFirstMonday = vs_lFirstMonday; }
	private static void setHDate(ArrayList vs_alHDate){ m_alHDate = vs_alHDate; }
	private static void setSegmentedTimeline(SegmentedTimeline vs_segmentedTimeline){ m_segmentedTimeline = vs_segmentedTimeline; }
	public static void setChart(JFreeChart vs_chart){ m_chart = vs_chart; }
	public static void setTrdDate(Date[] vs_aTrdDate){ m_aTrdDate = vs_aTrdDate; }
	public static void setDateInit(Date vs_dtDateInit){ m_dtDateInit = vs_dtDateInit; }
	
	public static long getFirstMonday(){ return m_lFirstMonday; }
	public static ArrayList getHDate(){ return m_alHDate; }
	public static SegmentedTimeline getSegmentedTimeline(){ return m_segmentedTimeline; }	
	public static JFreeChart getChart(){ return m_chart; }
	public static Date[] getTrdDate(){ return m_aTrdDate; }
	public static Date getDateInit(){ return m_dtDateInit; }
	
	public static void main(String[] args){
		
	}
}


JHistoricalCSChart------------------------

Code: Select all

package demo;

import java.awt.Dimension;
import java.util.Date;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.data.xy.OHLCDataset;
import org.jfree.date.DateUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.axis.NumberAxis;

//-ziwei import-
import java.util.ArrayList;
import java.text.SimpleDateFormat;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.SegmentedTimeline;

public class JHistoricalCSChart extends ApplicationFrame{

	//-ziwei import-
	private static cfg.ConfigSegmentedTimeline m_CST;
	
    public JHistoricalCSChart(String s)
    {
        super(s);
        OHLCDataset ohlcdataset = createDataset();
        JFreeChart jfreechart = createChart(ohlcdataset);
        jfreechart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setRangeZoomable(false);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartpanel);
    }

    private static JFreeChart createChart(OHLCDataset ohlcdataset)
    {
        JFreeChart jfreechart = ChartFactory.createCandlestickChart("Historical Non-Trading Day Exclusion", "Time", "Value", ohlcdataset, true);
        jfreechart.setAntiAlias(false);
        
        XYPlot xyplot = jfreechart.getXYPlot();
        //@@ edit: solution is to se the autoRangeIncludesZero to false, so that no more return to 0 for candlestick.
        NumberAxis numberAxis = (NumberAxis) xyplot.getRangeAxis();
		numberAxis.setAutoRangeIncludesZero(false); //exclude 0;
		xyplot.setRangeAxis(numberAxis);
        //@@ edit: when zooming in & out, u will notice the range had move back to 0,
        //@@ edit: set Margin of range(highest & lowest margin)
        ValueAxis rangeAxis = (ValueAxis) xyplot.getRangeAxis();
		rangeAxis.setAutoRange(false);		//no use, because in ValueAxis:In resizeRange(% > 0.0)->setAutoRange(true)->autoAdjustRange() still run it
		//rangeAxis.setRangeWithMargins(20,100);
		rangeAxis.setRange(20,100);
		xyplot.setRangeAxis(rangeAxis);
		
		//-ziwei Edit(Optional)-
		DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis();
		domainAxis.setVerticalTickLabels(true);
		domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
		//---Set bar chart to middle---
		domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);		
				
		//==================================================================================
		//@@ Segmented Timeline - Exclude Holiday, Non-Trading Day, Suspended date, Saturday & Sunday
		m_CST.setChart(jfreechart);
		m_CST.run();
		
		SegmentedTimeline segmentedTimeline = m_CST.getSegmentedTimeline();
		long lFirstMonday = m_CST.getFirstMonday();
		ArrayList alHDate = m_CST.getHDate();
		
		segmentedTimeline.setStartTime(lFirstMonday); //Must remake the calendar segment to avoid overlapping (Monday-Friday)
	    segmentedTimeline.addExceptions(alHDate);     //Exclude non-trading day
	    DateAxis axis = (DateAxis) jfreechart.getXYPlot().getDomainAxis();
		axis.setTimeline(segmentedTimeline);
	   
        return jfreechart;
    }

    public static OHLCDataset createDataset()
    {
        Date aDate[] = new Date[9]; //(11-2=9),47
        double ad[] = new double[9];
        double ad1[] = new double[9];
        double ad2[] = new double[9];
        double ad3[] = new double[9];
        double ad4[] = new double[9];
        int i = 1;
        byte byte0 = 2;
     //-------------------------
     //ziwei edit
     //-1st week(monday-friday)-
        aDate[0] = DateUtilities.createDate(2007, 12, 24, 12, 0);
        ad[0] = 47D;
        ad1[0] = 33D;
        ad2[0] = 35D;
        ad3[0] = 33D;
        ad4[0] = 100D;
     //-Holiday Christmas-
     /*
        aDate[1] = DateUtilities.createDate(2007, 12, 25, 12, 0);
        ad[1] = 47D;
        ad1[1] = 32D;
        ad2[1] = 41D;
        ad3[1] = 37D;
        ad4[1] = 150D;
     */
        aDate[1] = DateUtilities.createDate(2007, 12, 26, 12, 0);
        ad[1] = 49D;
        ad1[1] = 43D;
        ad2[1] = 46D;
        ad3[1] = 48D;
        ad4[1] = 70D;
        aDate[2] = DateUtilities.createDate(2007, 12, 27, 12, 0);
        ad[2] = 51D;
        ad1[2] = 39D;
        ad2[2] = 40D;
        ad3[2] = 47D;
        ad4[2] = 200D;
        aDate[3] = DateUtilities.createDate(2007, 12, 28, 12, 0);
        ad[3] = 60D;
        ad1[3] = 40D;
        ad2[3] = 46D;
        ad3[3] = 53D;
        ad4[3] = 120D; 
     
     //-------------------------
     //-2nd week(monday-friday)-          
        aDate[4] = DateUtilities.createDate(2007, 12, 31, 12, 0);
        ad[4] = 62D;
        ad1[4] = 55D;
        ad2[4] = 57D;
        ad3[4] = 61D;
        ad4[4] = 110D;
        
     //-New Year Holiday-
     /*    
        aDate[6] = DateUtilities.createDate(2008, 1, 1, 12, 0);
        ad[6] = 65D;
        ad1[6] = 56D;
        ad2[6] = 62D;
        ad3[6] = 59D;
        ad4[6] = 70D;
      */
        aDate[5] = DateUtilities.createDate(2008, 1, 2, 12, 0);
        ad[5] = 55D;
        ad1[5] = 43D;
        ad2[5] = 45D;
        ad3[5] = 47D;
        ad4[5] = 20D;
        aDate[6] = DateUtilities.createDate(2008, 1, 3, 12, 0);
        ad[6] = 54D;
        ad1[6] = 33D;
        ad2[6] = 40D;
        ad3[6] = 51D;
        ad4[6] = 30D;
        aDate[7] = DateUtilities.createDate(2008, 1, 4, 12, 0);
        ad[7] = 47D;
        ad1[7] = 33D;
        ad2[7] = 35D;
        ad3[7] = 33D;
        ad4[7] = 100D;
      
     //-------------------------   
     //-3rd week(monday-friday)-   
        aDate[8] = DateUtilities.createDate(2008, 1, 7, 12, 0);
        ad[8] = 54D;
        ad1[8] = 38D;
        ad2[8] = 43D;
        ad3[8] = 52D;
        ad4[8] = 50D;
      
     //-------------------------
       
     //---------------------------------------------------
	 //@@ SegmentedTimeline - Exclude Holiday, Non-Trading Day, Suspended date, Saturday & Sunday
		m_CST.setDateInit(aDate[0]);
		m_CST.setTrdDate(aDate);
		
        return new DefaultHighLowDataset("Series 1", aDate, ad, ad1, ad2, ad3, ad4);
    }

    public static JPanel createDemoPanel()
    {
        JFreeChart jfreechart = createChart(createDataset());
        return new ChartPanel(jfreechart);
    }

    public static void main(String args[])
    {
        JHistoricalCSChart JHistoricalCSChart = new JHistoricalCSChart("Historical Non-Trading Day Exclusion");
        JHistoricalCSChart.pack();
        RefineryUtilities.centerFrameOnScreen(JHistoricalCSChart);
        JHistoricalCSChart.setVisible(true);
    }
}


* Well now I am still solving bugs in overlapping and Exclusion of intraday gap (hour. i.e. 08:45-12:45 , rest, 14:30-17:15) and I want to exclude the gap in the rest session and also market close hour(17:15-08:45 another morning) for historical movement chart).

* If anyone have some solution, please email to me wzwei28@yahoo.com, and I help to publish to everyone. Thanks!

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Mon Aug 07, 2006 7:41 am

We get signal. Main screen turn on.

Jii
Posts: 128
Joined: Thu Apr 21, 2005 11:17 am

Post by Jii » Tue Aug 15, 2006 2:04 pm

CATS: Hello gentlemen.

Locked