Esempio n. 1
0
File: OHLC.cs Progetto: lulzzz/Quant
        public virtual long TR(OHLC prev)
        {
            // To do check the logic
            // adjusted for Roll.
            var adj_prevClose  = prev.Close.Price + Offset;
            var high_prevclose = Math.Abs(this.High.Price - adj_prevClose);
            var low_prevclose  = Math.Abs(this.Low.Price - adj_prevClose);

            return(Math.Max(this.Range, Math.Max(low_prevclose, high_prevclose)));
        }
Esempio n. 2
0
File: OHLC.cs Progetto: lulzzz/Quant
        public virtual int get_Offset(OHLC old)
        {
            int retVal = Offset;

            // roll happened at end of bar and bar includes multiple contracts
            if (old != null && old.Close.Security != this.Open.Security)
            {
                retVal += (int)(this.Open.Price - old.Close.Price);
            }
            return(retVal);
        }
Esempio n. 3
0
File: OHLC.cs Progetto: lulzzz/Quant
 /// <summary>
 /// Aggregates all the Ticks and creates OHLC bar
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static IObservable <OHLC> OHLC(this IObservable <Tick> source)
 {
     return(source.Aggregate((OHLC)null,
                             (oh, tk) => {
         // update or create (upsert) OHLC
         if (oh != null)
         {
             oh.Add(tk);
         }
         else
         {
             oh = new OHLC(tk);
         }
         return oh;
     }));
 }
Esempio n. 4
0
File: OHLC.cs Progetto: lulzzz/Quant
 /// <summary>
 /// Aggregates the ticks until the boundary Selector to create OHLC bar
 /// and starts a new OHLC
 /// </summary>
 /// <param name="source"></param>
 /// <param name="boundarySelector"></param>
 /// <returns></returns>
 internal static IObservable <OHLC> OHLC(this IObservable <Tick> source, Func <OHLC, Tick, bool> boundarySelector)
 {
     return(Observable.Create <OHLC>(obs => {
         OHLC ohlc = null;
         return source.Subscribe((tck) => {
             if (ohlc == null || boundarySelector(ohlc, tck))
             {
                 if (ohlc != null)
                 {
                     obs.OnNext(ohlc);
                 }
                 ohlc = new OHLC(tck);
             }
             else
             {
                 ohlc.Add(tck);
             }
         }, obs.OnError, () => { obs.OnNext(ohlc); obs.OnCompleted(); });
     }));
 }
Esempio n. 5
0
File: OHLC.cs Progetto: lulzzz/Quant
 public virtual (int hr, int tr, int lr) DM(OHLC prev)
 {
     // To do adjust for Roll
     return((int)(this.High.Price - prev.High.Price), (int)TR(prev), (int)(prev.Low.Price - this.Low.Price));
 }