Page 1 of 2
incorrect financial functions behavior
Posted: Thu May 06, 2010 10:47 am
by 16055208
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);
}
}
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 10:54 am
by narcis
Hi luzhetsky,
I think this is a bug which I have added to the defect list (TF02014860) to be fixed for future releases.
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 11:05 am
by 16055208
'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.
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 1:11 pm
by narcis
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.
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 1:57 pm
by narcis
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));
}
}
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 2:13 pm
by 16055208
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)
Re: incorrect financial functions behavior
Posted: Thu May 06, 2010 2:53 pm
by narcis
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.
Re: incorrect financial functions behavior
Posted: Fri May 07, 2010 11:52 am
by 16055208
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.
Re: incorrect financial functions behavior
Posted: Fri May 07, 2010 1:59 pm
by narcis
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.
Re: incorrect financial functions behavior
Posted: Tue May 11, 2010 1:56 pm
by 16055208
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);
}
}
Re: incorrect financial functions behavior
Posted: Tue May 11, 2010 2:08 pm
by narcis
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.
Re: incorrect financial functions behavior
Posted: Tue May 11, 2010 2:21 pm
by 16055208
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.
Re: incorrect financial functions behavior
Posted: Wed May 12, 2010 8:47 am
by narcis
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!
Re: incorrect financial functions behavior
Posted: Wed May 12, 2010 11:10 am
by 16055208
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!
Re: incorrect financial functions behavior
Posted: Wed May 12, 2010 11:52 am
by narcis
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.