Beispiel #1
0
        public BearSpread(Position Leg1, Position Leg2)
        {
            Legs.Add(Leg1);
            Legs.Add(Leg2);

            Strategy = ComboStrategy.BearSpread;

            if (VaildateSameSymbol() && VaildateBearSpread())
            {
                IsVaildated = true;
            }
            else
            {
                IsVaildated = false;
            }
        }
Beispiel #2
0
        private void AddNewLeg(LegType Type, Connection C, ref SolutionLeg LegPrev, ref SolutionLeg Leg, double Time)
        {
            if (C is RConnection)
            {
                Type = LegType.Foot;
            }
            else if (C is TConnection)
            {
                Type = LegType.Transport;
            }
            else if (C is CConnection)
            {
                Type = LegType.Carpool;
            }

            LegPrev = Leg;
            Leg     = new SolutionLeg(Time, Type);
            Legs.Add(Leg);
        }
Beispiel #3
0
        public HedgedPut(Position LegPut, Position LegSpot)
        {
            PosPut  = LegPut;
            PosSpot = LegSpot;

            Legs.Add(LegPut);
            Legs.Add(LegSpot);

            Put = (Option)PosPut.Asset;

            this.LoseType   = LoseType.LimitedLose;
            this.ProfitType = ProfitType.UnLimitedProfit;

            if (VaildateSameSymbol() && VaildateHedgedPut())
            {
                IsVaildated = true;
            }
            else
            {
                IsVaildated = false;
            }
        }
Beispiel #4
0
        public void StateLocationUpdate(Location location, Action legCompletedAction = null)
        {
            if (Current == null)
            {
                Current = new Leg(Car, DrivePath);
            }
            else if (Current.Completed)
            {
                if (legCompletedAction != null)
                {
                    legCompletedAction.Invoke();
                }

                var legPath = Current.Save();
                Legs.Add(Current);
                Current.Dispose();
                Current = new Leg(Car, DrivePath);
                service.Run(ObdPid.PendingTroubleCodes);
            }

            Current.UpdateLocation(location);
        }
Beispiel #5
0
        public BearCollar(Position LegSpot, Position LegHigherK, Position LegLowerK)
        {
            PosSpot    = LegSpot;
            PosLowerK  = LegLowerK;
            PosHigherK = LegHigherK;

            Legs.Add(LegSpot);
            Legs.Add(LegHigherK);
            Legs.Add(LegLowerK);

            this.LoseType   = LoseType.LimitedLose;
            this.ProfitType = ProfitType.LimitedProfit;

            if (VaildateSameSymbol() && VaildateBearCollar())
            {
                IsVaildated = true;
            }
            else
            {
                IsVaildated = false;
            }
        }
Beispiel #6
0
        private void CalculateTrip()
        {
            for (var i = 0; i < Coordinates.Count; i++)
            {
                Legs.Add(new List <DirectionSteps>());

                Distances.Add(new List <double>());

                Durations.Add(new List <double>());

                for (var j = 0; j < Coordinates.Count; j++)
                {
                    Legs[i].Add(new DirectionSteps());

                    Distances[i].Add(0);

                    Durations[i].Add(0);
                }
            }

            GetDistTable(0, 0);

            BestPath = new List <int>();

            NextSet = new List <int>();

            BestTrip = MaxTripSentry;

            var numActive = Coordinates.Count;

            var numCombos = 1 << Coordinates.Count;

            var c = new List <List <double> >();

            var parent = new List <List <int> >();

            for (var i = 0; i < numCombos; i++)
            {
                c.Add(new List <double>());

                parent.Add(new List <int>());

                for (var j = 0; j < numActive; ++j)
                {
                    c[i].Add(0.0);

                    parent[i].Add(0);
                }
            }

            int index;

            for (var k = 1; k < numActive; ++k)
            {
                index = 1 + (1 << k);

                c[index][k] = Durations[0][k];
            }

            for (var s = 3; s <= numActive; ++s)
            {
                for (var i = 0; i < numActive; ++i)
                {
                    NextSet.Add(0);
                }

                index = NextSetOf(s);

                while (index >= 0)
                {
                    for (var k = 1; k < numActive; ++k)
                    {
                        if (NextSet[k] != 0)
                        {
                            var previousIndex = index - (1 << k);

                            c[index][k] = MaxTripSentry;

                            for (var m = 1; m < numActive; ++m)
                            {
                                if (NextSet[m] != 0 && m != k)
                                {
                                    if (c[previousIndex][m] + Durations[m][k] < c[index][k])
                                    {
                                        c[index][k]      = c[previousIndex][m] + Durations[m][k];
                                        parent[index][k] = m;
                                    }
                                }
                            }
                        }
                    }
                    index = NextSetOf(s);
                }
            }

            for (var i = 0; i < numActive; ++i)
            {
                BestPath.Add(0);
            }

            index = (1 << numActive) - 1;

            var currentNode = -1;

            BestPath.Add(0);

            for (var i = 1; i < numActive; ++i)
            {
                if (c[index][i] + Durations[i][0] < BestTrip)
                {
                    BestTrip = c[index][i] + Durations[i][0];

                    currentNode = i;
                }
            }

            BestPath[numActive - 1] = currentNode;

            for (var i = numActive - 1; i > 0; --i)
            {
                currentNode = parent[index][currentNode];

                index -= 1 << BestPath[i];

                BestPath[i - 1] = currentNode;
            }
        }
Beispiel #7
0
        private void CalculateTrip()
        {
            for (int i = 0; i < Coordinates.Count; i++)
            {
                Legs.Add(new List <DirectionSteps>());

                Distances.Add(new List <double>());

                Durations.Add(new List <double>());

                for (int j = 0; j < Coordinates.Count; j++)
                {
                    Legs[i].Add(new DirectionSteps());

                    Distances[i].Add(0);

                    Durations[i].Add(0);
                }
            }

            GetDistTable(0, 0);

            BestPath = new List <int>();

            double minDistance = -1;

            for (int i = 1; i < Coordinates.Count; i++)
            {
                List <int> coordinatesIndex = new List <int>();

                for (int j = 1; (j < Coordinates.Count); j++)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    coordinatesIndex.Add(j);
                }
                var coordinatesIndexPermutation = GetPermutations(coordinatesIndex, coordinatesIndex.Count);

                List <List <int> > listCoordinatesIndexPermutationComplete = new List <List <int> >();

                foreach (var coordinateIndexPermutation in coordinatesIndexPermutation)
                {
                    var coordinateIndexPermutationTemp = new List <int> {
                        0
                    };

                    coordinateIndexPermutationTemp.AddRange(coordinateIndexPermutation);

                    coordinateIndexPermutationTemp.Add(i);

                    listCoordinatesIndexPermutationComplete.Add(coordinateIndexPermutationTemp);
                }

                // get min
                foreach (var coordinatesIndexPermutationComplete in listCoordinatesIndexPermutationComplete)
                {
                    double pathDistance = 0;

                    for (int j = 0; j < coordinatesIndexPermutationComplete.Count - 1; j++)
                    {
                        pathDistance += Distances[coordinatesIndexPermutationComplete[j]][coordinatesIndexPermutationComplete[j + 1]];
                    }

                    if (minDistance < 0 || pathDistance < minDistance)
                    {
                        BestPath    = coordinatesIndexPermutationComplete;
                        minDistance = pathDistance;
                    }
                }
            }
            // get min of results is best path
        }
Beispiel #8
0
        public SecurityDefinition(Security security) : base(MessageType.SecurityDefinition)
        {
            MatchEventIndicator  = MatchEventIndicator.LastMessage;
            TotNumReports        = 1;
            SecurityUpdateAction = SecurityUpdateAction.Add;
            LastUpdateTime       = DateTime.UtcNow;
            //ChannelId = security.ChannelId;

            MarketSegmentId = security.MarketSegmentId;
            Contract        = security.Contract;
            Id            = security.Id;
            IdSource      = security.IdSource;
            MaturityMonth = security.MaturityMonth;
            Product       = security.Product;
            Group         = security.Group;
            //SecurityType = security.Type;
            //SecuritySubType = security.StrategyType;
            CfiCode                 = security.CfiCode;
            PutOrCall               = security.PutOrCall;
            UnderlyingAssetClass    = security.AssetClass;
            Exchange                = security.Exchange;
            MDSecurityTradingStatus = security.TradingStatus;
            StrikePrice             = security.StrikePrice;
            //StrikeCurrency = security.StrikeCurrency;
            //Currency = security.Currency;
            //SettlementCurrency = security.SettlementCurrency;
            MinCabPrice           = security.MinCabPrice;
            UserDefinedInstrument = security.UserDefinedInstrument;

            foreach (var u in security.Underlyings)
            {
                Underlyings.Add(new SecurityDefinitionUnderlying()
                {
                    Symbol           = u.Symbol,
                    SecurityId       = u.Id,
                    SecurityIdSource = u.IdSource,
                });
            }

            foreach (var l in security.Legs)
            {
                Legs.Add(new SecurityDefinitionLeg()
                {
                    LegSecurityID = l.Security.Id,
                    LegSide       = l.Side,
                    LegRatioQty   = l.Quantity,
                    LegPrice      = l.Price,
                    //LegOptionDelta = l.OptionDelta,
                });
            }

            foreach (var f in security.FeedTypes)
            {
                MdFeedTypes.Add(new SecurityDefinitionFeedTypes()
                {
                    MDFeedType  = f.IncludesImplieds ? "GBX" : "GBI",
                    MarketDepth = f.Depth,
                });
            }
            if (security.ActivationTime.HasValue)
            {
                Events.Add(new SecurityDefinitionEvent()
                {
                    EventType = EventType.Activation,
                    EventTime = security.ActivationTime.Value,
                });
            }
            if (security.ExpiryTime.HasValue)
            {
                Events.Add(new SecurityDefinitionEvent()
                {
                    EventType = EventType.LastEligibleTradeDate,
                    EventTime = security.ExpiryTime.Value,
                });
            }
            MatchAlgorithm = security.MatchAlgorithm;

            foreach (var ltr in security.LotTypeRules)
            {
                LotTypeRules.Add(new SecurityDefinitionLotTypeRule()
                {
                    LotType    = ltr.LotType,
                    MinLotSize = ltr.MinLotSize,
                });
            }
            MinTradeVol             = security.MinOrderQuantity;
            MaxTradeVol             = security.MaxOrderQuantity;
            MinPriceIncrement       = security.TickSize;
            MinPriceIncrementAmount = security.TickValue;
            DisplayFactor           = security.DisplayFactor;
            PriceRatio         = security.PriceRatio;
            TickRule           = security.TickRule;
            MainFraction       = security.MainFraction;
            SubFraction        = security.SubFraction;
            PriceDisplayFormat = security.PriceDisplayFormat;

            foreach (var ia in security.InstrumentAttributes)
            {
                InstAttribs.Add(new SecurityDefinitionInstrumentAttribute()
                {
                    InstAttribType  = ia.Type,
                    InstAttribValue = ia.Value,
                });
            }

            ContractMultiplierUnit = security.ContractMultiplierUnit;
            FlowScheduleType       = security.FlowScheduleType;
            //ContractMultiplier = security.ContractMultiplier;
            //UnitOfMeasure = security.UnitOfMeasure;
            UnitOfMeasureQty     = security.UnitOfMeasureQuantity;
            DecayQty             = security.DecayQty;
            DecayStartDate       = security.DecayStartDate;
            OriginalContractSize = security.OriginalContractSize;

            TradingReferencePrice = security.TradingReferencePrice;
            SettlementPriceType   = security.SettlementPriceType;
            TradingReferenceDate  = security.TradingReferenceDate;
            OpenInterest          = security.OpenInterest;
            ClearedVolume         = security.ClearedVolume;
            HighLimitPrice        = security.HighLimitPrice;
            LowLimitPrice         = security.LowLimitPrice;
            MaxPriceVariation     = security.MaxPriceVariation;
        }
Beispiel #9
0
 public TestCase AddLeg(Symbol symbol, int quantity)
 {
     Legs.Add(new OptionPosition(symbol, quantity));
     return(this);
 }
 public void AddLeg(OptionDetailImpl optionLeg)
 {
     Legs.Add(optionLeg);
 }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="paymentCalendar"> </param>
        /// <param name="capFloorFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"> </param>
        public CapFloorPricer(ILogger logger, ICoreCache cache, String nameSpace,
                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                              CapFloor capFloorFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            if (capFloorFpML == null)
            {
                return;
            }
            //AnalyticsModel = new SimpleIRSwapInstrumentAnalytic();
            BusinessCentersResolver.ResolveBusinessCenters(capFloorFpML);
            ForecastRateInterpolation = forecastRateInterpolation;
            //We make the assumption that the termination date is the same for all legs..
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(capFloorFpML.capFloorStream.calculationPeriodDates);

            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace);
            }
            RiskMaturityDate  = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate);
            ProductType       = ProductTypeSimpleEnum.CapFloor;
            PaymentCurrencies = new List <string>();
            //Resolve the payer
            if (capFloorFpML.capFloorStream == null)
            {
                return;
            }
            var calculation             = capFloorFpML.capFloorStream.calculationPeriodAmount.Item as Calculation;
            var floatingRatecalculation = calculation?.Items[0] as FloatingRateCalculation;

            if (floatingRatecalculation == null)
            {
                return;
            }
            if (floatingRatecalculation.capRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.capRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            if (floatingRatecalculation.capRateSchedule == null && floatingRatecalculation.floorRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.floorRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            BasePartyBuyer = basePartyReference == BuyerPartyReference;//TODO add in the calendar functionality.
            //Set the id of the first stream. THe generator requires the flag: BasePartyPayer.
            var capFloorLeg = new PriceableCapFloorStream(logger, cache, nameSpace, !BasePartyBuyer, capFloorFpML.capFloorStream, ForecastRateInterpolation, fixingCalendar, paymentCalendar);

            Legs.Add(capFloorLeg);
            //Add the currencies for the trade pricer.
            if (!PaymentCurrencies.Contains(capFloorLeg.Currency.Value))
            {
                PaymentCurrencies.Add(capFloorLeg.Currency.Value);
            }
            if (capFloorFpML.additionalPayment != null)
            {
                AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, capFloorFpML.additionalPayment, null);
                foreach (var payment in capFloorFpML.additionalPayment)
                {
                    if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value))
                    {
                        PaymentCurrencies.Add(payment.paymentAmount.currency.Value);
                    }
                }
            }
        }
Beispiel #12
0
        private void ConstructLegs()
        {
            double     Time   = this.StartTime;
            Connection C      = null;
            Connection C_prev = null;

            LegType Type = LegType.Foot;

            if (Modes == TravelMode.Car)
            {
                Type = LegType.Car;
            }

            SolutionLeg Leg     = new SolutionLeg(StartTime, Type);
            SolutionLeg LegPrev = Leg;

            Legs.Add(Leg);

            for (int i = 0; i < Connections.Count; ++i)
            {
                C = Connections[i];

                if ((C is LConnection) && (i < Connections.Count - 1))
                {
                    AddNewLeg(Type, Connections[i + 1], ref LegPrev, ref Leg, Time);
                }
                else if (Modes == TravelMode.Carpool)
                {
                    double TTime;

                    TTime = C.GetTravelTime(Date, Time, Modes);

                    Leg.AddConnection(C, TTime, C.GetWaitingTime());

                    Time += TTime;
                }
                else
                {
                    double TTime, TTimeWithWaitings;

                    TTime             = C.GetTravelTime(Date, Time, Modes);
                    TTimeWithWaitings = TTime;

                    /* Remove waiting times from the single legs */
                    TTime -= C.GetWaitingTime();
                    if (TTime < 0)
                    {
                        //TODO in rare cases TTime is negative, unfortunately this is not deterministic. Instead to make the RP crash set to 0 the TTime for this connection.
                        TTime = 0;
                        //throw new Exception("negative time value");
                    }

                    Leg.AddConnection(C, TTime, C.GetWaitingTime());
                    //Leg.AddConnection(C, TTime);

                    TTime = TTimeWithWaitings;
                    Time += TTime;

                    /* If there are 2 adjacent TConnections, split them */
                    if ((i < Connections.Count - 1) && (Connections[i + 1] is TConnection))
                    {
                        //if (String.Compare(C.GetRouteId(), Connections[i + 1].GetRouteId()) != 0)
                        if ((String.Compare(C.GetRouteShortName(), Connections[i + 1].GetRouteShortName()) != 0) ||
                            (String.Compare(C.GetRouteLongName(), Connections[i + 1].GetRouteLongName()) != 0))
                        {
                            AddNewLeg(Type, Connections[i + 1], ref LegPrev, ref Leg, Time);
                        }
                    }
                }

                C_prev = C;
            }
        }
 public void AddLeg(Leg leg)
 {
     leg.Request = this;
     Legs.Add(leg);
 }