Beispiel #1
0
 private void UpdateSubItem(TimeSeries values, int index)
 {
     this.UpdateSubItem(values.Count > 0 ? values.Last : 0.0, index);
     if (!(this.Statistics.Category == "Daily / Annual returns") || values.Count != 0)
         return;
     this.SubItems[index].Text = string.Empty;
 }
Beispiel #2
0
 public DSView(Pad pad, TimeSeries series, Color color, SearchOption option, SmoothingMode smoothing)
     : base(pad)
 {
     this.series = series;
     Option = option;
     Color = color;
     SmoothingMode = smoothing;
     ToolTipFormat = "{0}\n{2} - {3:F*}".Replace("*", pad.Chart.LabelDigitsCount.ToString());
 }
 private double GetAvg(TimeSeries values)
 {
     double num = 0.0;
     if (values.Count > 0)
     {
         for (int index = 0; index < values.Count; ++index)
             num += values[index];
         num /= (double)values.Count;
     }
     return num;
 }
 private double GetStdDev(TimeSeries values)
 {
     double num = 0.0;
     if (values.Count > 1)
     {
         double avg = this.GetAvg(values);
         for (int index = 0; index < values.Count; ++index)
             num += Math.Pow(values[index] - avg, 2.0);
         num = Math.Sqrt(num / (double)(values.Count - 1));
     }
     return num;
 }
Beispiel #5
0
 public Strategy(Framework framework, string name)
 {
     this.framework = framework;
     this.Name = name;
     this.strategiesByInstrument = new IdArray<LinkedList<Strategy>>(1000);
     this.strategyByOrderId = new IdArray<Strategy>(1000);
     this.strategies = new LinkedList<Strategy>();
     this.status = StrategyStatus.Stopped;
     this.instruments = new InstrumentList();
     this.instrumentCountTable = new IdArray<int>(1000);
     if (framework != null)
     {
         this.portfolio = new Portfolio(framework, this.Name);
         framework.PortfolioManager.Add(this.portfolio);
     }
     this.bars = new BarSeries("", "");
     this.equity = new TimeSeries();
     this.bids = new TickSeries("");
     this.asks = new TickSeries("");
     this.stops = new List<Stop>();
     this.stopsByInstrument = new IdArray<List<Stop>>(1000);
 }
Beispiel #6
0
 public double GetCovariance(TimeSeries series)
 {
     if (series == null)
     {
         throw new ArgumentException("Argument series should be of TimeSeries type");
     }
     double num = this.GetMean();
     double num2 = series.GetMean();
     double num3 = 0.0;
     double num4 = 0.0;
     for (int i = 0; i < this.Count; i++)
     {
         DateTime dateTime = this.GetDateTime(i);
         if (series.Contains(dateTime))
         {
             num4 += (this[i] - num) * (series[dateTime, SearchOption.Exact] - num2);
             num3 += 1.0;
         }
     }
     if (num3 <= 1.0)
     {
         return 0.0;
     }
     return num4 / (num3 - 1.0);
 }
Beispiel #7
0
 public Cross Crosses(TimeSeries series, DateTime dateTime)
 {
     int num = this.IndexOf(dateTime, SearchOption.Exact);
     int num2 = series.IndexOf(dateTime, SearchOption.Exact);
     if (num <= 0 || num >= this.items.Count)
     {
         return Cross.None;
     }
     if (num2 <= 0 || num2 >= series.Count)
     {
         return Cross.None;
     }
     DateTime dateTime2 = this.GetDateTime(num - 1);
     DateTime dateTime3 = series.GetDateTime(num2 - 1);
     if (dateTime2 == dateTime3)
     {
         if (this.GetValue(num - 1) <= series.GetValue(num2 - 1) && this.GetValue(num) > series.GetValue(num2))
         {
             return Cross.Above;
         }
         if (this.GetValue(num - 1) >= series.GetValue(num2 - 1) && this.GetValue(num) < series.GetValue(num2))
         {
             return Cross.Below;
         }
     }
     else
     {
         double value;
         double value2;
         if (dateTime2 < dateTime3)
         {
             DateTime dateTime4 = this.GetDateTime(num - 1);
             value = this.GetValue(num - 1);
             if (series.IndexOf(dateTime4, SearchOption.Next) != num2)
             {
                 value2 = series.GetValue(series.IndexOf(dateTime4, SearchOption.Next));
             }
             else
             {
                 value2 = series.GetValue(series.IndexOf(dateTime4, SearchOption.Prev));
             }
         }
         else
         {
             DateTime dateTime5 = series.GetDateTime(num2 - 1);
             value2 = series.GetValue(num2 - 1);
             if (this.IndexOf(dateTime5, SearchOption.Prev) != num)
             {
                 value = this.GetValue(this.IndexOf(dateTime5, SearchOption.Next));
             }
             else
             {
                 value = this.GetValue(this.IndexOf(dateTime5, SearchOption.Prev));
             }
         }
         if (value <= value2 && this.GetValue(num) > series.GetValue(num2))
         {
             return Cross.Above;
         }
         if (value >= value2 && this.GetValue(num) < series.GetValue(num2))
         {
             return Cross.Below;
         }
     }
     return Cross.None;
 }
Beispiel #8
0
 public double GetCorrelation(TimeSeries series)
 {
     return this.GetCovariance(series) / (this.GetStdDev() * series.GetStdDev());
 }
Beispiel #9
0
 public DSView DrawSeries(TimeSeries series, int padNumber, Color color, SimpleDSStyle style, SearchOption option, SmoothingMode smoothingMode)
 {
     lock (this.lockObject)
     {
         if (!this.volumePadShown && padNumber > 1)
             --padNumber;
         DSView local_0 = new DSView(this.pads[padNumber], series, color, option, smoothingMode);
         local_0.Style = style;
         this.pads[padNumber].AddPrimitive(local_0);
         local_0.SetInterval(this.leftDateTime, this.rightDateTime);
         this.contentUpdated = true;
         return local_0;
     }
 }
Beispiel #10
0
 public static TimeSeries operator /(double Value, TimeSeries series)
 {
     if (series == null)
     {
         throw new ArgumentException("Operator argument can not be null");
     }
     TimeSeries timeSeries = new TimeSeries(string.Concat(new string[]
     {
         "(",
         Value.ToString("F2"),
         "/",
         series.Name,
         ")"
     }), "");
     for (int i = 0; i < series.Count; i++)
     {
         if (series[i, 0] != 0.0)
         {
             timeSeries.Add(series.GetDateTime(i), Value / series[i, 0]);
         }
     }
     return timeSeries;
 }
 private double GetCovariance(TimeSeries values1, TimeSeries values2)
 {
     double num1 = 0.0;
     int num2 = Math.Min(values1.Count, values2.Count);
     if (num2 > 1)
     {
         double avg1 = this.GetAvg(values1);
         double avg2 = this.GetAvg(values2);
         for (int index = num2 - 1; index >= 0; --index)
             num1 += (values1[index] - avg1) * (values2[index] - avg2);
         num1 /= (double)(num2 - 1);
     }
     return num1;
 }
Beispiel #12
0
 public void DrawSeries(TimeSeries series, int padNumber, Color color)
 {
     DrawSeries(series, padNumber, color, SearchOption.ExactFirst);
 }
Beispiel #13
0
 public void DrawSeries(TimeSeries series, int padNumber, Color color, SearchOption option)
 {
     lock (this.lockObject)
     {
         if (!this.volumePadShown && padNumber > 1)
             --padNumber;
         var view = new DSView(this.pads[padNumber], series, color, option, this.TimeSeriesSmoothingMode);
         this.pads[padNumber].AddPrimitive(view);
         view.SetInterval(this.leftDateTime, this.rightDateTime);
         this.contentUpdated = true;
     }
 }
Beispiel #14
0
 public virtual TimeSeries GetPositiveSeries()
 {
     TimeSeries timeSeries = new TimeSeries();
     for (int i = 0; i < this.Count; i++)
     {
         if (this[i] > 0.0)
         {
             timeSeries.Add(this.GetDateTime(i), this[i]);
         }
     }
     return timeSeries;
 }
Beispiel #15
0
 public DSView(Pad pad, TimeSeries series, SearchOption option)
     : this(pad, series, Color.White, option, SmoothingMode.AntiAlias)
 {
 }
Beispiel #16
0
 public DSView(Pad pad, TimeSeries series, Color color)
     : this(pad, series, color, SearchOption.ExactFirst, SmoothingMode.AntiAlias)
 {
 }
Beispiel #17
0
 public DSView(Pad pad, TimeSeries series)
     : this(pad, series, SearchOption.ExactFirst)
 {
 }
 private double GetCorrelation(TimeSeries values1, TimeSeries values2)
 {
     double num = 0.0;
     if (Math.Min(values1.Count, values2.Count) > 1)
         num = this.GetCovariance(values1, values2) / (this.GetStdDev(values1) * this.GetStdDev(values2));
     return num;
 }
Beispiel #19
0
 public Chart(TimeSeries mainSeries)
     : this()
 {
     SetMainSeries(mainSeries);
 }
 private TimeSeries GetEqualSeries(TimeSeries values1, TimeSeries values2)
 {
     TimeSeries timeSeries = new TimeSeries();
     for (int index = 0; index < values2.Count; ++index)
     {
         DateTime dateTime = values1.GetDateTime(index);
         if (values2.Contains(dateTime))
             timeSeries.Add(dateTime, values1[index]);
     }
     return timeSeries;
 }
Beispiel #21
0
 public static TimeSeries operator /(TimeSeries series1, TimeSeries series2)
 {
     if (series1 == null || series2 == null)
     {
         throw new ArgumentException("Operator argument can not be null");
     }
     TimeSeries timeSeries = new TimeSeries(string.Concat(new string[]
     {
         "(",
         series1.Name,
         "/",
         series2.Name,
         ")"
     }), "");
     for (int i = 0; i < series1.Count; i++)
     {
         DateTime dateTime = series1.GetDateTime(i);
         if (series2.Contains(dateTime) && series2[dateTime, SearchOption.Exact] != 0.0)
         {
             timeSeries.Add(dateTime, series1[dateTime, 0] / series2[dateTime, 0]);
         }
     }
     return timeSeries;
 }
Beispiel #22
0
 public virtual TimeSeries GetReturnSeries()
 {
     TimeSeries timeSeries = new TimeSeries(this.name, this.description + " (return)");
     if (this.Count > 1)
     {
         double num = this[0];
         for (int i = 0; i < this.Count; i++)
         {
             DateTime dateTime = this.GetDateTime(i);
             double num2 = this[i];
             if (num != 0.0)
             {
                 timeSeries.Add(dateTime, num2 / num);
             }
             else
             {
                 timeSeries.Add(dateTime, 0.0);
             }
             num = num2;
         }
     }
     return timeSeries;
 }
Beispiel #23
0
 public void DrawSeries(TimeSeries series, int padNumber, Color color, SimpleDSStyle style, SmoothingMode smoothingMode)
 {
     DrawSeries(series, padNumber, color, style, SearchOption.ExactFirst, smoothingMode);
 }
Beispiel #24
0
 public void OnNewGroupEvent(GroupEvent groupEvent)
 {
     var item = this.table[groupEvent.Group.Id];
     Tuple<Viewer, object> tuple = null;
     item.Table.TryGetValue(groupEvent.Obj.TypeId, out tuple);
     switch (groupEvent.Obj.TypeId)
     {
         case DataObjectType.Bar:
             object obj1;
             if (tuple == null)
             {
                 obj1 = new BarSeries("", "", -1);
                 int padNumber = item.PadNumber;
                 this.EnsurePadExists(padNumber, item.Format);
                 int viewerIndex = this.GetViewerIndex(groupEvent.Group, padNumber);
                 Viewer viewer = this.chart.Pads[padNumber].Insert(viewerIndex, obj1 as BarSeries);
                 this.chart.Pads[padNumber].Legend.Add(groupEvent.Group.Name, Color.Black);
                 item.Table.Add(groupEvent.Obj.TypeId, new Tuple<Viewer, object>(viewer, obj1));
             }
             else
                 obj1 = tuple.Item2 as BarSeries;
             (obj1 as BarSeries).Add(groupEvent.Obj as Bar);
             break;
         case DataObjectType.Fill:
             object obj2;
             if (tuple == null)
             {
                 obj2 = new FillSeries("");
                 int padNumber = item.PadNumber;
                 this.EnsurePadExists(padNumber, item.Format);
                 int viewerIndex = this.GetViewerIndex(groupEvent.Group, padNumber);
                 Viewer viewer = this.chart.Pads[padNumber].Insert(viewerIndex, obj2);
                 item.Table.Add(groupEvent.Obj.TypeId, new Tuple<Viewer, object>(viewer, obj2));
             }
             else
                 obj2 = tuple.Item2 as FillSeries;
             (obj2 as FillSeries).Add(groupEvent.Obj as Fill);
             break;
         case DataObjectType.TimeSeriesItem:
             object obj3;
             if (tuple == null)
             {
                 obj3 = new TimeSeries();
                 int padNumber = item.PadNumber;
                 EnsurePadExists(padNumber, item.Format);
                 int viewerIndex = this.GetViewerIndex(groupEvent.Group, padNumber);
                 Viewer viewer = this.chart.Pads[padNumber].Insert(viewerIndex, obj3);
                 foreach (var kv in groupEvent.Group.Fields)
                     viewer.Set(obj3, kv.Value.Name, kv.Value.Value);
                 if (groupEvent.Group.Fields.ContainsKey("Color"))
                     this.chart.Pads[padNumber].Legend.Add(groupEvent.Group.Name, (Color)groupEvent.Group.Fields["Color"].Value);
                 else
                     this.chart.Pads[padNumber].Legend.Add(groupEvent.Group.Name, Color.Black);
                 item.Table.Add(groupEvent.Obj.TypeId, new Tuple<Viewer, object>(viewer, obj3));
             }
             else
                 obj3 = tuple.Item2 as TimeSeries;
             (obj3 as TimeSeries).Add((groupEvent.Obj as TimeSeriesItem).DateTime, (groupEvent.Obj as TimeSeriesItem).Value);
             break;
     }
 }
Beispiel #25
0
 public TimeSeries Shift(int offset)
 {
     TimeSeries timeSeries = new TimeSeries(this.name, this.description);
     int num = 0;
     if (offset < 0)
     {
         num += Math.Abs(offset);
     }
     for (int i = num; i < this.Count; i++)
     {
         int num2 = i + offset;
         if (num2 >= this.Count)
         {
             break;
         }
         DateTime dateTime = this.GetDateTime(num2);
         double value = this[i];
         timeSeries[dateTime, SearchOption.Exact] = value;
     }
     return timeSeries;
 }