| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- namespace IndexFormula.Finance
- {
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Reflection;
- using System.Xml.Serialization;
- public class ExchangeIntraday : ICloneable
- {
- private ArrayList alRemoveDay;
- private ArrayList alTimePeriods = new ArrayList();
- private bool nativeCycle;
- private bool showFirstXLabel;
- private double timeZone;
- private int yahooDelay = 30;
- public static double YahooTimeZone = -4.0;
- public virtual void Add(TimePeriod tp)
- {
- this.alTimePeriods.Add(tp);
- }
- public void AddRemoveDays(int Start, int End)
- {
- if (this.alRemoveDay == null)
- {
- this.alRemoveDay = new ArrayList();
- }
- else
- {
- this.alRemoveDay.Clear();
- }
- for (int i = Start + 1; i < End; i++)
- {
- this.alRemoveDay.Add(i);
- }
- }
- public object Clone()
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.nativeCycle = this.nativeCycle;
- intraday.showFirstXLabel = this.showFirstXLabel;
- intraday.timeZone = this.timeZone;
- intraday.yahooDelay = this.yahooDelay;
- intraday.TimePeriods = (TimePeriod[]) this.TimePeriods.Clone();
- return intraday;
- }
- public DateTime GetCurrentTradingDay()
- {
- DateTime d = DateTime.UtcNow.AddHours(this.TimeZone);
- if (this.IsBeforeMarketStart(d))
- {
- d = d.AddDays(-1.0);
- }
- while ((d.DayOfWeek == DayOfWeek.Saturday) || (d.DayOfWeek == DayOfWeek.Sunday))
- {
- d = d.AddDays(-1.0);
- }
- return d.Date;
- }
- public static ExchangeIntraday GetExchangeIntraday(string Exchange)
- {
- if (Exchange == "")
- {
- return US;
- }
- try
- {
- Type type = typeof(ExchangeIntraday);
- return (ExchangeIntraday) type.InvokeMember(Exchange, BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Static, null, null, null);
- }
- catch
- {
- return US;
- }
- }
- public double[] GetMinuteDate(DateTime t1, DateTime t2)
- {
- ArrayList list = new ArrayList();
- double num = t1.ToOADate();
- double num2 = t2.ToOADate();
- while (num <= num2)
- {
- foreach (TimePeriod period in this.alTimePeriods)
- {
- int num3 = 0;
- double num4 = period.Time1;
- while (num4 < period.Time2)
- {
- num4 = period.Time1 + ((((double) num3) / 24.0) / 60.0);
- list.Add(num + num4);
- num3++;
- }
- }
- num++;
- }
- return (double[]) list.ToArray(typeof(double));
- }
- public double GetOpenTimePerDay()
- {
- double num = 0.0;
- foreach (TimePeriod period in this.alTimePeriods)
- {
- num += period.Time2 - period.Time1;
- }
- return num;
- }
- public bool InRemoveDays(double D)
- {
- return ((this.alRemoveDay != null) && (this.alRemoveDay.IndexOf((int) D) >= 0));
- }
- public bool InTimePeriod(double D)
- {
- double num = D - ((int) D);
- foreach (TimePeriod period in this.alTimePeriods)
- {
- if ((num >= period.Time1) && (num <= (period.Time2 + 0.00069444444444444436)))
- {
- return true;
- }
- }
- return false;
- }
- public bool IsBeforeMarketStart(DateTime D)
- {
- TimePeriod period = this[0];
- DateTime time = DateTime.FromOADate(period.Time1);
- return ((D.Hour < time.Hour) || ((D.Hour == time.Hour) && (D.Minute < time.Minute)));
- }
- public bool IsEstimateOpen(DateTime D)
- {
- TimePeriod period = this[0];
- return ((D.Hour >= DateTime.FromOADate(period.Time1).Hour) && (D.Hour <= DateTime.FromOADate(this[this.Count - 1].Time2).AddMinutes((double) this.YahooDelay).Hour));
- }
- public double OneDayTime(double D)
- {
- double num = D - ((int) D);
- double num2 = 0.0;
- foreach (TimePeriod period in this.alTimePeriods)
- {
- if (num > period.Time2)
- {
- num2 += period.Time2 - period.Time1;
- }
- else
- {
- if (num > period.Time1)
- {
- num2 += num - period.Time1;
- }
- return num2;
- }
- }
- return num2;
- }
- public int RawDaysBetween(double d1, double d2)
- {
- int num = 0;
- int num2 = ((int) d1) + 1;
- int num3 = (int) d2;
- if (this.alRemoveDay != null)
- {
- for (int i = num2; i < num3; i++)
- {
- if (this.alRemoveDay.IndexOf(i) < 0)
- {
- num++;
- }
- }
- return num;
- }
- return (num3 - num2);
- }
- public static ExchangeIntraday ASX
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 10, 0, 0), new DateTime(1, 1, 1, 0x10, 0, 0)));
- intraday.timeZone = 9.0;
- return intraday;
- }
- }
- public static ExchangeIntraday ASXE
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 9, 0, 0), new DateTime(1, 1, 1, 0x11, 0, 0)));
- intraday.timeZone = 10.0;
- return intraday;
- }
- }
- public static string[] BuildInExchange
- {
- get
- {
- PropertyInfo[] properties = typeof(ExchangeIntraday).GetProperties(BindingFlags.Public | BindingFlags.Static);
- string[] strArray = new string[properties.Length - 1];
- for (int i = 1; i < properties.Length; i++)
- {
- strArray[i - 1] = properties[i].Name;
- }
- return strArray;
- }
- }
- public static ExchangeIntraday Canada
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 9, 30, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x10, 0, 0);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.timeZone = YahooTimeZone;
- return intraday;
- }
- }
- public static ExchangeIntraday China
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.NativeCycle = true;
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 9, 30, 0), new DateTime(1, 1, 1, 11, 30, 0)));
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 13, 0, 0), new DateTime(1, 1, 1, 15, 0, 0)));
- intraday.timeZone = 8.0;
- intraday.showFirstXLabel = true;
- return intraday;
- }
- }
- [Browsable(false), XmlIgnore]
- public int Count
- {
- get
- {
- return this.alTimePeriods.Count;
- }
- }
- [Browsable(false), XmlIgnore]
- public DateTime ExchangeDate
- {
- get
- {
- return this.ExchangeTime.Date;
- }
- }
- [Browsable(false), XmlIgnore]
- public DateTime ExchangeTime
- {
- get
- {
- return DateTime.UtcNow.AddHours(this.TimeZone);
- }
- }
- public static ExchangeIntraday Forex
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 0, 0, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x17, 0x3b, 0x3b);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.TimeZone = 0.0;
- intraday.yahooDelay = 0;
- intraday.ShowFirstXLabel = true;
- return intraday;
- }
- }
- public static ExchangeIntraday France
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 9, 0, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x11, 30, 0);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.timeZone = 6.0 + YahooTimeZone;
- return intraday;
- }
- }
- public static ExchangeIntraday Germany
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 9, 0, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x11, 0, 0);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.timeZone = 6.0 + YahooTimeZone;
- return intraday;
- }
- }
- public static ExchangeIntraday HK
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.NativeCycle = true;
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 10, 0, 0), new DateTime(1, 1, 1, 12, 30, 0)));
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 14, 30, 0), new DateTime(1, 1, 1, 0x10, 0, 0)));
- intraday.timeZone = 8.0;
- intraday.showFirstXLabel = true;
- return intraday;
- }
- }
- public virtual TimePeriod this[int Index]
- {
- get
- {
- return (TimePeriod) this.alTimePeriods[Index];
- }
- }
- public static ExchangeIntraday Japan
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.NativeCycle = true;
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 9, 0, 0), new DateTime(1, 1, 1, 11, 0, 0)));
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 12, 30, 0), new DateTime(1, 1, 1, 15, 0, 0)));
- intraday.timeZone = 9.0;
- intraday.showFirstXLabel = true;
- return intraday;
- }
- }
- [Description("Use exchange data cycle in X-axis, used in two periods exchanges."), DefaultValue(false), XmlAttribute]
- public bool NativeCycle
- {
- get
- {
- return this.nativeCycle;
- }
- set
- {
- this.nativeCycle = true;
- }
- }
- public static ExchangeIntraday Sg
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- intraday.nativeCycle = true;
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 9, 0, 0), new DateTime(1, 1, 1, 12, 30, 0)));
- intraday.Add(new TimePeriod(new DateTime(1, 1, 1, 14, 0, 0), new DateTime(1, 1, 1, 0x11, 0, 0)));
- intraday.timeZone = 8.0;
- intraday.showFirstXLabel = true;
- return intraday;
- }
- }
- [Description("Show first label in the X-axis"), DefaultValue(false), XmlAttribute]
- public bool ShowFirstXLabel
- {
- get
- {
- return this.showFirstXLabel;
- }
- set
- {
- this.showFirstXLabel = value;
- }
- }
- [TypeConverter(typeof(TimePeriodsConverter)), Description("Time periods, separate by comma.")]
- public TimePeriod[] TimePeriods
- {
- get
- {
- return (TimePeriod[]) this.alTimePeriods.ToArray(typeof(TimePeriod));
- }
- set
- {
- this.alTimePeriods.Clear();
- this.alTimePeriods.AddRange(value);
- }
- }
- [DefaultValue(0), XmlAttribute, Description("Time zone of the exchange")]
- public double TimeZone
- {
- get
- {
- return this.timeZone;
- }
- set
- {
- this.timeZone = value;
- }
- }
- public static ExchangeIntraday UK
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 8, 0, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x10, 0x2d, 0);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.timeZone = 5.0 + YahooTimeZone;
- return intraday;
- }
- }
- public static ExchangeIntraday US
- {
- get
- {
- ExchangeIntraday intraday = new ExchangeIntraday();
- DateTime time = new DateTime(1, 1, 1, 9, 30, 0);
- DateTime time2 = new DateTime(1, 1, 1, 0x10, 0, 0);
- intraday.Add(new TimePeriod(time.ToOADate(), time2.ToOADate()));
- intraday.timeZone = YahooTimeZone;
- return intraday;
- }
- }
- [DefaultValue(30), Browsable(false), XmlIgnore]
- public int YahooDelay
- {
- get
- {
- return this.yahooDelay;
- }
- set
- {
- this.yahooDelay = value;
- }
- }
- }
- }
|