/// <summary> /// Calculate VWAP for a timeseries /// </summary> /// <param name="outputColumn"></param> /// <param name="volumeColumn"></param> public static TimeSeries Calculate(TimeSeries timeSeries, int length, int calcColumn, int outputColumn, int volumeColumn) { _length = length; _timeSeries = timeSeries; for (int i = 0; i < timeSeries.Count; i++) { ((object[])timeSeries[i])[outputColumn] = Value(i, calcColumn, volumeColumn); } return timeSeries; }
private void btnVWAP_Click(object sender, System.EventArgs e) { if (this.txtPath.Text == "") { MessageBox.Show("Path not specified."); return; } Fabrefactum.TimeSeries tSeries = new Fabrefactum.TimeSeries(); using (CSVReader csv = new CSVReader(@txtPath.Text)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { object[] fieldArray = new object[fields.Length]; fieldArray[0] = DateTime.Parse(fields[0] + " " + fields[1]); for (int i = 2; i < fields.Length; i++) { fieldArray[i-1] = Convert.ToDouble(fields[i]); } if (fieldArray.Length > 1) { tSeries.Add(DateTime.Parse(fieldArray[0].ToString()),fieldArray); } } } // Calculate VWAP int length = 10; if (this.txtLength.Text != "") { length = Convert.ToInt32(txtLength.Text); } Fabrefactum.VWAP.Calculate(tSeries,length,4,6,5); axStockChartX1.ClearValues("EUR.Close"); axStockChartX1.ClearValues("EUR.VWAP"); axStockChartX1.ClearValues("EUR.Volume"); // Add our points for (int i = 0; i < tSeries.Count; i++) { object[] series = (object[])tSeries[i]; if ((double)series[6] != double.NaN) { DateTime date = tSeries.GetDateTime(i); double jDate = axStockChartX1.ToJulianDate(date.Year,date.Month,date.Day,date.Hour,date.Minute,date.Second); axStockChartX1.AppendValue("EUR.Close",jDate,(double)series[4]); axStockChartX1.AppendValue("EUR.VWAP",jDate,(double)series[6]); axStockChartX1.AppendValue("EUR.Volume",jDate,(double)series[5]); } } axStockChartX1.CtlUpdate(); }
public TimeSeriesEnumerator(TimeSeries Array) { fArray = Array; fIndex = -1; }
/// <summary> /// Clones a TimeSeries /// </summary> /// <param name="Index1"></param> /// <param name="Index2"></param> /// <returns></returns> public virtual TimeSeries Clone(int Index1, int Index2) { TimeSeries timeSeries = new TimeSeries(fName,fTitle); if (Count == 0) { return timeSeries; } for (int i = Index1; i <= Index2; i++) { timeSeries.Add(GetDateTime(i), this[i]); } return timeSeries; }