incorrect financial functions behavior

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

incorrect financial functions behavior

Post by luzhetsky » Thu May 06, 2010 10:47 am

Hi,

we have problem with financial functions on 4th version (4.0.2009.42283) of TeeChart lib (on 2nd version (2.0.2469.25745) it is working ok): function line is drawing incorrect - it ends not on last data point, but with some left shift, and looks like visible points calculation is wrong too - see attached screens for both versions of lib.

How it may be resolved?

code is:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void simpleButton1_Click_1(object sender, EventArgs e)
{
Candle candle = new Candle();
candle.FillSampleValues();
tChart1.Series.Add(candle);

Momentum func = new Momentum();
func.Period = 7;

FastLine line = new FastLine();
line.DataSource = candle;
line.Function = func;
tChart1.Series.Add(line);
}
}
Attachments
v4.0.2009.42283.jpg
4th version is wrong
v4.0.2009.42283.jpg (69.73 KiB) Viewed 7894 times
v2.0.2469.25745.jpg
2nd version is Ok
v2.0.2469.25745.jpg (82.56 KiB) Viewed 7893 times
Last edited by luzhetsky on Thu May 06, 2010 11:50 am, edited 1 time in total.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Thu May 06, 2010 10:54 am

Hi luzhetsky,

I think this is a bug which I have added to the defect list (TF02014860) to be fixed for future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Thu May 06, 2010 11:05 am

'to be fixed for future releases' - it is good, but we have a huge problem with large commercial product with hundreds of customers and we need hot fix for it urgently!
Now we can't back to 2nd version of the library.

I've wrote e-mail to the info@steema.com (no other official e-mails are availble (info@steema.com and sales@steema.com only)) - could you give me any other contact who can make decision to resolve it as much quick as possible and deliver it for us?

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Thu May 06, 2010 1:11 pm

Hi luzhetsky,
'to be fixed for future releases' - it is good, but we have a huge problem with large commercial product with hundreds of customers and we need hot fix for it urgently!
Now we can't back to 2nd version of the library.
The main difference I see in v2 and v4 is at Steema.TeeChart.Functions.Moving.DoCalculation in Basic.cs. In v2 it's like this:

Code: Select all

    protected override void DoCalculation(Styles.Series source, Styles.ValueList notMandatorySource) 
    {
      int P=Utils.Round(dPeriod);
      for (int t=P-1; t<source.Count; t++)
        AddFunctionXY( source.yMandatory, notMandatorySource[t], Calculate(source,t-P+1,t));
    }
In v4 it changed to this:

Code: Select all

		protected override void DoCalculation(Styles.Series source, Styles.ValueList notMandatorySource)
		{
			int P = 1;
			if (PeriodStyle == PeriodStyles.NumPoints)
			{
				P = Utils.Round(dPeriod);
			}
			else if (PeriodStyle == PeriodStyles.Range)
			{
				P = source.XValues.IndexOf(source.XValues.Minimum + dPeriod);
				if (P < 1) P = 1;
			}

      for (int t = P - 1; t < source.Count; t += P)
      {
        AddFunctionXY(source.yMandatory, notMandatorySource[t], Calculate(source, t - P + 1, t));
      }
		}
For a quick fix and since you are source code customer, you can implement DoCalculation as in v2. I checked it behaves as in v2 as you requested. I can not incorporate this in the build without thorough investigation and knowing the reasons for this change as otherwise it might break other functionality.
I've wrote e-mail to the info@steema.com (no other official e-mails are availble (info@steema.com and sales@steema.com only)) - could you give me any other contact who can make decision to resolve it as much quick as possible and deliver it for us?
We are doing our best to provide technical support on this forum board in a timely and efficient fashion. If you are interested in direct e-mail technical support you may be interested in our Pro-Support service.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Thu May 06, 2010 1:57 pm

Hi luzhetsky,

Or even much easier changing the increment in the for loop from t += P to t++:

Code: Select all

		protected override void DoCalculation(Styles.Series source, Styles.ValueList notMandatorySource)
		{
			int P = 1;
			if (PeriodStyle == PeriodStyles.NumPoints)
			{
				P = Utils.Round(dPeriod);
			}
			else if (PeriodStyle == PeriodStyles.Range)
			{
				P = source.XValues.IndexOf(source.XValues.Minimum + dPeriod);
				if (P < 1) P = 1;
			}

      for (int t = P - 1; t < source.Count; t++)
      {
        AddFunctionXY(source.yMandatory, notMandatorySource[t], Calculate(source, t - P + 1, t));
      }
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Thu May 06, 2010 2:13 pm

Narcís wrote:Hi luzhetsky,

Or even much easier changing the increment in the for loop from t += P to t++:
Ok, thank you - we will try to change it...

looks loop with t++ should be under if (PeriodStyle == PeriodStyles.NumPoints) and t+P under if (PeriodStyle == PeriodStyles.Range)

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Thu May 06, 2010 2:53 pm

Hello,

Yes, probably something like this:

Code: Select all

      int tmpInc = (PeriodStyle == PeriodStyles.NumPoints) ? 1 : P;

      for (int t = P - 1; t < source.Count; t += tmpInc)
      {
        AddFunctionXY(source.yMandatory, notMandatorySource[t], Calculate(source, t - P + 1, t));
      }
I'll make this change for next release too.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Fri May 07, 2010 11:52 am

Hi Narcís!

Looks we have the same problem (set of last points are not calculated and other points calculation looks like with incorrect step) with Standard Deviation Function - I've looked at code, but can't understand what need to be changed - it is not inherited from moving.

Could you look at this, please, and post any code to fix?

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Fri May 07, 2010 1:59 pm

Hi luzhetsky,

StdDeviation inherits from TeeChart functions base class (hence called Function) and has own calculation methods (Calculate, CalculateDeviation and CalculateMany). You may want to look into those methods. You may also notice that StdDeviation.cs code has suffered very little changes between v2 and v4, any of them relevant to its functionality.

Confirming that, code below does the same in v2 and v4. Can you please modify it so that we can reproduce the issue here?

Code: Select all

      Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      line1.FillSampleValues();

      Steema.TeeChart.Functions.StdDeviation func = new Steema.TeeChart.Functions.StdDeviation();
      func.Period = 7;

      Steema.TeeChart.Styles.FastLine fastLine1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      fastLine1.DataSource = line1;
      fastLine1.Function = func;
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Tue May 11, 2010 1:56 pm

Hi Narcís!

Here is a code and result pic:

Code: Select all

    
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Candle candle = new Candle();
            candle.FillSampleValues();
            tChart1.Series.Add(candle);

            StdDeviation func = new StdDeviation();
            func.Period = 7;

            FastLine line = new FastLine();
            line.DataSource = candle;
            line.Function = func;
            tChart1.Series.Add(line);

        }
    }
Attachments
Std.jpg
Std.jpg (86.19 KiB) Viewed 7802 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Tue May 11, 2010 2:08 pm

Hi luzhetsky,

Thanks for the info. I have checked this code does exactly the same both in v2 and v2010. Which is the exact problem you are having here?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Tue May 11, 2010 2:21 pm

As I understand the behavior of Standard Deviation, it shall start drawing from 7th point ( where 7 - is period of StD) and stop on last, but now it starts on 4th point and stops far from last.

And BTW, StD uses in calculation MovingAverage function, but I did not found it in TeeChart's implementation.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Wed May 12, 2010 8:47 am

Hi luzhetsky,
As I understand the behavior of Standard Deviation, it shall start drawing from 7th point ( where 7 - is period of StD) and stop on last, but now it starts on 4th point and stops far from last.
If you want the function to behave like that you need to use PeriodAlign property set to Last. Also, it will plot until the last point in the series only if series has a number of points multiple of function's Period, for example:

Code: Select all

      Steema.TeeChart.Styles.Candle candle = new Steema.TeeChart.Styles.Candle(tChart1.Chart);      

      Steema.TeeChart.Functions.StdDeviation func = new Steema.TeeChart.Functions.StdDeviation();
      func.Period = 7;
      func.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Last;

      candle.FillSampleValues((int)(func.Period * 5));

      Steema.TeeChart.Styles.FastLine line = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      line.DataSource = candle;
      line.Function = func;
And BTW, StD uses in calculation MovingAverage function, but I did not found it in TeeChart's implementation.
I'm not sure about which is your exact question here. StdDeviation is implemented at StdDeviation.cs. In Visual Studio, if you are referencing TeeChart source code project from your projects you just need to press F12 on an object so that the IDE takes you to its declaration.

Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

luzhetsky
Newbie
Newbie
Posts: 16
Joined: Mon Feb 08, 2010 12:00 am

Re: incorrect financial functions behavior

Post by luzhetsky » Wed May 12, 2010 11:10 am

Hi Narcís!

It's not working!

look at the code - I'm using 1000 values:

Code: Select all

            Steema.TeeChart.Styles.Candle candle = new Steema.TeeChart.Styles.Candle(tChart1.Chart);

            Steema.TeeChart.Functions.StdDeviation func = new Steema.TeeChart.Functions.StdDeviation();
            func.Period = 7;
            func.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Last;

            candle.FillSampleValues((int)(1000)); //1000 values

            Steema.TeeChart.Styles.FastLine line = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            line.DataSource = candle;
            line.Function = func;
and here is result on screens (pic1):

and you can see on zoomed graph last value of Line is not on last value of Candle (pic2):

AND! please look that StD function should be smooth, and EACH point of it (starting from N) should be calculated based on data of previous N (N is period), but on graph I see that StD calculated only for each N points - it's incorrect!

And, THE SAME! with function High and Low (see pic. 3): line is not smooth and function is calculated only for each 7 pointh, but NOT FOR ALL POINTS, started from 7th!
Attachments
Hith.jpg
pic3: High function with period 7
Hith.jpg (88.22 KiB) Viewed 7766 times
Std_1000Values_zoomed.jpg
pic2: zoomed
Std_1000Values_zoomed.jpg (113.36 KiB) Viewed 7764 times
Std_1000Values_full.jpg
pic 1: 1000 values and StD - full
Std_1000Values_full.jpg (109.91 KiB) Viewed 7763 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: incorrect financial functions behavior

Post by Narcís » Wed May 12, 2010 11:52 am

Hi luzhetsky,
and you can see on zoomed graph last value of Line is not on last value of Candle (pic2):
1000 is not multiple of 7, according to what I told you before, it works fine with 994 or 1006 points
AND! please look that StD function should be smooth, and EACH point of it (starting from N) should be calculated based on data of previous N (N is period), but on graph I see that StD calculated only for each N points - it's incorrect!

And, THE SAME! with function High and Low (see pic. 3): line is not smooth and function is calculated only for each 7 pointh, but NOT FOR ALL POINTS, started from 7th!
This depends on PeriodStyle property. Setting it to PeriodStyles.Range does the job:

Code: Select all

      func.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.Range;
For more information please read Steema.TeeChart.Functions.Function.PeriodStyle's entry in TeeChart's help file.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply