示例#1
0
文件: VWAP.cs 项目: ToniTsai/LeetCode
        public VWAP(Bars bars, string description)
            : base(bars, description)
        {
            Helper.CompatibilityCheck();

            base.FirstValidValue = 1;

            //Can't work if data isn't intraday
            if (!bars.IsIntraday)
            {
                return;
            }

            double x    = 0;
            double MVol = 0;

            //First, compute the typical price for the intraday period. This is the average of the high, low and close {(H+L+C)/3)}.
            AveragePrice ap = AveragePrice.Series(bars);

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                // daily initialization
                if (bars.IntradayBarNumber(bar) == 0)
                {
                    x    = 0;
                    MVol = 0;

                    //20180413 fix for not taking the intraday bar 0 value, replacing it with the prior day VWAP closing value
                    //if (bar > 0)
                    //    base[bar] = base[bar - 1];
                }
                //else  //20180413 fix for not taking the intraday bar 0 value, replacing it with the prior day VWAP closing value
                {
                    //Second, multiply the typical price by the period's volume.
                    //Third, create a running total of these values. This is also known as a cumulative total.
                    x += ap[bar] * bars.Volume[bar];

                    //Fourth, create a running total of volume (cumulative volume).
                    MVol += bars.Volume[bar];

                    //Fifth, divide the running total of price-volume by the running total of volume.
                    base[bar] = x / MVol;
                }

                // Old version (prior to 2012.04)

                /*x += ap[bar] * bars.Volume[bar];
                 * MVol += bars.Volume[bar];
                 * if (MVol == 0)
                 *  base[bar] = ap[bar];
                 * else
                 *  base[bar] = x / MVol;*/
            }
        }
示例#2
0
文件: DV2.cs 项目: ToniTsai/LeetCode
        public DV2(Bars bars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = 2;

            DataSeries dv2 = bars.Close / AveragePrice.Series(bars) - 1;

            dv2 = (dv2 + (dv2 >> 1)) / 2d;

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = dv2[bar];
            }
        }
示例#3
0
        public AwesomeOscillator(Bars bars, int period1, int period2, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period1 + period2;

            AveragePrice avg = AveragePrice.Series(bars);

            var rangePartitioner = Partitioner.Create(0, bars.Count);

            Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int bar = range.Item1; bar < range.Item2; bar++)
                {
                    base[bar] = Community.Indicators.FastSMA.Series(avg, period1)[bar] - Community.Indicators.FastSMA.Series(avg, period2)[bar];
                }
            });
        }
示例#4
0
            public override int GetHashCode()
            {
                int hash = 0;

                if (hashCode > 0)
                {
                    hash = hashCode;
                }
                else
                {
                    hash =
                        (ChildOrderAcceptanceId.GetHashCode() * 2)
                        + ((ChildOrderId == null ? 1 : ChildOrderId.GetHashCode()) * 3)
                        + (RemainingSize.GetHashCode() * 5)
                        + (AveragePrice.GetHashCode() * 7);
                }
                return(hash);
            }
示例#5
0
        public string[] ToStringArray()
        {
            string priceChange = "";

            if (!isFirstDay)
            {
                int change = Coin.Price - Coin.PastPrices[Coin.PastPrices.Count - 1];
                priceChange = change > 0 ? $"+{change}" : $"{change}";
            }

            string[] array = new string[5];
            array[0] = Coin.Name;
            array[1] = Coin.Price.ToString();
            array[2] = priceChange;
            array[3] = AveragePrice.ToString();
            array[4] = NumInInventory.ToString();

            return(array);
        }
示例#6
0
 public override int GetHashCode()
 {
     // credit: http://stackoverflow.com/a/263416/677735
     unchecked // Overflow is fine, just wrap
     {
         int hash = 41;
         // Suitable nullity checks etc, of course :)
         if (Symbol != null)
         {
             hash = hash * 59 + Symbol.GetHashCode();
         }
         hash = hash * 59 + Quantity.GetHashCode();
         hash = hash * 59 + AveragePrice.GetHashCode();
         hash = hash * 59 + MarketPrice.GetHashCode();
         hash = hash * 59 + MarketValue.GetHashCode();
         hash = hash * 59 + EntryValue.GetHashCode();
         hash = hash * 59 + UpdateTime.GetHashCode();
         return(hash);
     }
 }
示例#7
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Direction.GetHashCode();
                if (AveragePriceUsd != null)
                {
                    hashCode = hashCode * 59 + AveragePriceUsd.GetHashCode();
                }
                if (EstimatedLiquidationPrice != null)
                {
                    hashCode = hashCode * 59 + EstimatedLiquidationPrice.GetHashCode();
                }
                if (FloatingProfitLoss != null)
                {
                    hashCode = hashCode * 59 + FloatingProfitLoss.GetHashCode();
                }
                if (FloatingProfitLossUsd != null)
                {
                    hashCode = hashCode * 59 + FloatingProfitLossUsd.GetHashCode();
                }
                if (OpenOrdersMargin != null)
                {
                    hashCode = hashCode * 59 + OpenOrdersMargin.GetHashCode();
                }
                if (TotalProfitLoss != null)
                {
                    hashCode = hashCode * 59 + TotalProfitLoss.GetHashCode();
                }
                if (RealizedProfitLoss != null)
                {
                    hashCode = hashCode * 59 + RealizedProfitLoss.GetHashCode();
                }
                if (Delta != null)
                {
                    hashCode = hashCode * 59 + Delta.GetHashCode();
                }
                if (InitialMargin != null)
                {
                    hashCode = hashCode * 59 + InitialMargin.GetHashCode();
                }
                if (Size != null)
                {
                    hashCode = hashCode * 59 + Size.GetHashCode();
                }
                if (MaintenanceMargin != null)
                {
                    hashCode = hashCode * 59 + MaintenanceMargin.GetHashCode();
                }

                hashCode = hashCode * 59 + Kind.GetHashCode();
                if (MarkPrice != null)
                {
                    hashCode = hashCode * 59 + MarkPrice.GetHashCode();
                }
                if (AveragePrice != null)
                {
                    hashCode = hashCode * 59 + AveragePrice.GetHashCode();
                }
                if (SettlementPrice != null)
                {
                    hashCode = hashCode * 59 + SettlementPrice.GetHashCode();
                }
                if (IndexPrice != null)
                {
                    hashCode = hashCode * 59 + IndexPrice.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }
                if (SizeCurrency != null)
                {
                    hashCode = hashCode * 59 + SizeCurrency.GetHashCode();
                }
                return(hashCode);
            }
        }
示例#8
0
        /// <summary>
        /// Returns true if Position instances are equal
        /// </summary>
        /// <param name="other">Instance of Position to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Position other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Direction == other.Direction ||

                     Direction.Equals(other.Direction)
                     ) &&
                 (
                     AveragePriceUsd == other.AveragePriceUsd ||
                     AveragePriceUsd != null &&
                     AveragePriceUsd.Equals(other.AveragePriceUsd)
                 ) &&
                 (
                     EstimatedLiquidationPrice == other.EstimatedLiquidationPrice ||
                     EstimatedLiquidationPrice != null &&
                     EstimatedLiquidationPrice.Equals(other.EstimatedLiquidationPrice)
                 ) &&
                 (
                     FloatingProfitLoss == other.FloatingProfitLoss ||
                     FloatingProfitLoss != null &&
                     FloatingProfitLoss.Equals(other.FloatingProfitLoss)
                 ) &&
                 (
                     FloatingProfitLossUsd == other.FloatingProfitLossUsd ||
                     FloatingProfitLossUsd != null &&
                     FloatingProfitLossUsd.Equals(other.FloatingProfitLossUsd)
                 ) &&
                 (
                     OpenOrdersMargin == other.OpenOrdersMargin ||
                     OpenOrdersMargin != null &&
                     OpenOrdersMargin.Equals(other.OpenOrdersMargin)
                 ) &&
                 (
                     TotalProfitLoss == other.TotalProfitLoss ||
                     TotalProfitLoss != null &&
                     TotalProfitLoss.Equals(other.TotalProfitLoss)
                 ) &&
                 (
                     RealizedProfitLoss == other.RealizedProfitLoss ||
                     RealizedProfitLoss != null &&
                     RealizedProfitLoss.Equals(other.RealizedProfitLoss)
                 ) &&
                 (
                     Delta == other.Delta ||
                     Delta != null &&
                     Delta.Equals(other.Delta)
                 ) &&
                 (
                     InitialMargin == other.InitialMargin ||
                     InitialMargin != null &&
                     InitialMargin.Equals(other.InitialMargin)
                 ) &&
                 (
                     Size == other.Size ||
                     Size != null &&
                     Size.Equals(other.Size)
                 ) &&
                 (
                     MaintenanceMargin == other.MaintenanceMargin ||
                     MaintenanceMargin != null &&
                     MaintenanceMargin.Equals(other.MaintenanceMargin)
                 ) &&
                 (
                     Kind == other.Kind ||

                     Kind.Equals(other.Kind)
                 ) &&
                 (
                     MarkPrice == other.MarkPrice ||
                     MarkPrice != null &&
                     MarkPrice.Equals(other.MarkPrice)
                 ) &&
                 (
                     AveragePrice == other.AveragePrice ||
                     AveragePrice != null &&
                     AveragePrice.Equals(other.AveragePrice)
                 ) &&
                 (
                     SettlementPrice == other.SettlementPrice ||
                     SettlementPrice != null &&
                     SettlementPrice.Equals(other.SettlementPrice)
                 ) &&
                 (
                     IndexPrice == other.IndexPrice ||
                     IndexPrice != null &&
                     IndexPrice.Equals(other.IndexPrice)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     SizeCurrency == other.SizeCurrency ||
                     SizeCurrency != null &&
                     SizeCurrency.Equals(other.SizeCurrency)
                 ));
        }