/// <summary> /// Calculates all matches for the given teams, using the round robin system. /// </summary> /// <param name="refereeType">Determines how referees will be assigned for the matches.</param> /// <param name="legType">First leg or return leg.</param> /// <returns>Return a collection of team combinations.</returns> public TeamCombinationGroup <T> GetCombinationGroup(RefereeType refereeType, LegType legType) { _refereeType = refereeType; CalcCombinations(); return((legType == LegType.First) ? _combinationGroup : _combinationGroupReturnLeg); }
public SolutionLeg(double StartTime, LegType Type) { this.Connections = new List <Connection>(); this.StartTime = StartTime; this.Duration = 0; this.LegType = Type; }
public SuggestedStrategyLeg(LegType legType, BuyOrSell buyOrSell, int qty, double?strike = null, DateAndNumberOfDaysUntil expirationDate = null) { LegType = legType; BuyOrSell = buyOrSell; StrikePrice = strike; ExpirationDate = expirationDate; Quantity = qty; }
public void Init() { animator = GetComponent <Animator>(); renderer = GetComponent <SpriteRenderer>(); int type = Random.Range(0, 4); legType = (LegType)type; animator.SetInteger("Type", type); }
public BlackScholesModel(double daysToExpiry /*T-t, maturity*/, double strike /*K*/, double interestRate /*r*/, double spotPrice /*S*/, double ask, double bid, double lastPrice, LegType callOrPut, double?divYield /*q*/ = null) { _maturity = daysToExpiry / NumberOfDaysPerYear; _strikePrice = strike; _interestRate = interestRate / 100.0; _spotPrice = spotPrice; _ask = ask; _bid = bid; _lastPrice = lastPrice; _callOrPut = callOrPut; _divYield = (divYield ?? 0.0) / 100.0; }
public void Copy(BotLeg leg) { if (renderer == null) { renderer = GetComponent <SpriteRenderer>(); } this.legType = leg.legType; if (this.animator) { this.animator.SetInteger("Type", (int)this.legType); } this.isBroken = leg.isBroken; this.renderer.sprite = GetSprite(); }
public Legs(JSONObject json) : base(json.GetField("name").str, json.GetField("basevalue").f, (int)json.GetField("level").f, (int)json.GetField("levelcap").f, (int)json.GetField("tier").f) { type = parseLegType(json.GetField("type").str); setGrowth(json.GetField("growth").f); List <JSONObject> stats = json.GetField("stats").list; setBase(stats[0].f, stats[1].f, stats[2].f, stats[3].f, stats[4].f); List <JSONObject> dist = json.GetField("distribution").list; setDistribution(dist); }
public Option this[DateTime expiration, double strikePrice, LegType optionType] { get { OptionPair targetOptionChain = this[expiration, strikePrice]; if (targetOptionChain == null) { return(null); } Option optionMatch = optionType == LegType.Put ? targetOptionChain.PutOption : targetOptionChain.CallOption; return(optionMatch); } }
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); }
public static Greeks GetGreeks(double daysToExpiry /*T-t, maturity*/, double strike /*K*/, double interestRate /*r*/, double spotPrice /*S*/, double ask, double bid, double lastPrice, LegType callOrPut, double?divYield = null) { if (divYield == null) { divYield = 0; } BlackScholesModel bsm = new BlackScholesModel(daysToExpiry, strike, interestRate, spotPrice, ask, bid, lastPrice, callOrPut, divYield); Greeks greeks = new Greeks(); greeks.Delta = bsm.EuroDelta; greeks.Gamma = bsm.EuroGamma; greeks.Theta = bsm.EuroTheta; greeks.Sigma = bsm.Sigma; greeks.Rho = bsm.EuroRho; greeks.RhoFx = bsm.EuroRhoFx; greeks.Vega = bsm.EuroVega; return(greeks); }
public Sprite GetSpriteForType(LegType type) { if (isBroken) { return(BrokenLeg); } switch (type) { case LegType.speed: return(SpeedLeg); case LegType.atv: return(ATVLeg); case LegType.hover: return(HoverLeg); case LegType.unicycle: return(UnicycleLeg); } return(null); }
private static List <CoveredCall> GetCoveredCallsByLegType(OptionChain data, Dictionary <DateAndNumberOfDaysUntil, Prediction> predictions, /*EarningsCalendar calendar,*/ LegType legType, /*Signal volOfVol,*/ double?minimumPremiumParam, double?minimumReturnParam) { double minimumPremium = minimumPremiumParam ?? DefaultMinimumPremium; double minimumReturn = minimumReturnParam ?? DefaultMinimumReturn; HashSet <DateTime> optimalIsFound = new HashSet <DateTime>(); List <CoveredCall> coveredCalls = new List <CoveredCall>(); foreach (OptionPair optionChain in data) { Option option = legType == LegType.Call ? optionChain.CallOption : optionChain.PutOption; double bid = option.Bid; double currentPremium = bid; DateAndNumberOfDaysUntil expiry = optionChain.Expiry; double lastPrice = data.UnderlyingCurrentPrice; double strkePrice = optionChain.StrikePrice; List <OptionPair> chainsWithTheSameExpiry = data.Where(x => x.Expiry == expiry).ToList(); // todo: optionChain.OptionType //bool typeisSuitable = optionChain.OptionType == OptionType.Standard; double daysQuantity = expiry.TotalNumberOfDaysUntilExpiry; // Ignore expired options if (daysQuantity < 0 || daysQuantity.AlmostEqual(0) /*|| !typeisSuitable*/) { continue; } bool strikePriceIsSuitable = legType == LegType.Call ? optionChain.StrikePrice > lastPrice : optionChain.StrikePrice < lastPrice; if (!strikePriceIsSuitable) { // Check if fifth strike is suitable strikePriceIsSuitable = legType == LegType.Call ? chainsWithTheSameExpiry.Where(x => x.StrikePrice < lastPrice) .OrderBy(x => lastPrice - x.StrikePrice) .Take(5).Last().StrikePrice <optionChain.StrikePrice : chainsWithTheSameExpiry.Where(x => x.StrikePrice > lastPrice) .OrderBy(x => x.StrikePrice - lastPrice) .Take(5).Last().StrikePrice> optionChain.StrikePrice; } if (!strikePriceIsSuitable) { continue; } double intrinsicValue = legType == LegType.Call ? lastPrice > optionChain.StrikePrice ? lastPrice - optionChain.StrikePrice : 0 : lastPrice < optionChain.StrikePrice ? optionChain.StrikePrice - lastPrice : 0; double currentReturn = (Math.Pow(1 + (currentPremium - intrinsicValue) / lastPrice, 365.0 / daysQuantity) - 1) * 100; bool firstAboveBelowStdDev = false; Prediction prediction = predictions[optionChain.Expiry]; StdDevPrices stdDev = prediction.GetStdDevPrices(1); bool deviationIsSuitable = legType == LegType.Call ? strkePrice > stdDev.UpPrice : strkePrice < stdDev.DownPrice; if (deviationIsSuitable) { firstAboveBelowStdDev = legType == LegType.Call ? chainsWithTheSameExpiry .Where(x => x.StrikePrice >= stdDev.UpPrice) .Select(y => y.StrikePrice - stdDev.UpPrice) .Min() .AlmostEqual(strkePrice - stdDev.UpPrice) : chainsWithTheSameExpiry .Where(x => x.StrikePrice <= stdDev.DownPrice) .Select(y => stdDev.DownPrice - y.StrikePrice) .Min() .AlmostEqual(stdDev.DownPrice - optionChain.StrikePrice); } double probability = prediction.GetProbabilityByPrice(optionChain.StrikePrice) * 100; double probabilityInSigmas = MarketMath.GetSigmaProbabilityByDeviation(probability / 100); CoveredCall coveredCall = new CoveredCall(); coveredCall.Premium = currentPremium; coveredCall.Return = currentReturn; coveredCall.OptionNumber = option.OptionNumber; coveredCall.Probability = probability; coveredCall.ProbabilityInSigmas = probabilityInSigmas; // if (volOfVol != null) // { // coveredCall.VolOfVol = volOfVol.Value; // } coveredCall.PercentAboveBelowCurrentPrice = Math.Abs((optionChain.StrikePrice - lastPrice)) / lastPrice * 100; int numberOfStrikes = legType == LegType.Call ? chainsWithTheSameExpiry.Where(x => x.StrikePrice >= lastPrice) .OrderBy(x => x.StrikePrice) .ToList() .FindIndex(x => x.StrikePrice.AlmostEqual(optionChain.StrikePrice)) + 1 : chainsWithTheSameExpiry.Where(x => x.StrikePrice <= lastPrice) .OrderByDescending(x => x.StrikePrice) .ToList() .FindIndex(x => x.StrikePrice.AlmostEqual(optionChain.StrikePrice)) + 1; coveredCall.NumberOfStrikesBelowAboveCurrentPrice = numberOfStrikes; coveredCall.NumberOfSdBelowAboveCurrentPrice = probabilityInSigmas; // coveredCall.HasEarnings = calendar != null && calendar.Date >= DateTime.Now && calendar.Date <= optionChain.Expiry; // if (calendar != null) // { // coveredCall.DaysQuantityBeforeEarnings = (calendar.Date - DateTime.UtcNow).TotalDays; // } coveredCalls.Add(coveredCall); if (bid.AlmostEqual(0.0)) { coveredCall.RiskTolerance = RiskTolerance.NoBid; continue; } if (!deviationIsSuitable) { if (currentPremium < minimumPremium) { coveredCall.RiskTolerance = RiskTolerance.LowPremium; continue; } coveredCall.RiskTolerance = currentReturn >= minimumReturn ? RiskTolerance.Aggressive : RiskTolerance.LowReturn; continue; } if (currentPremium < minimumPremium) { coveredCall.RiskTolerance = RiskTolerance.LowPremium; continue; } if (currentReturn < minimumReturn) { coveredCall.RiskTolerance = RiskTolerance.LowReturn; continue; } if (!optimalIsFound.Contains(optionChain.Expiry.FutureDate) && daysQuantity >= 3 && daysQuantity <= 60 //&& (!coveredCall.HasEarnings || daysQuantity < coveredCall.DaysQuantityBeforeEarnings) && firstAboveBelowStdDev) { coveredCall.RiskTolerance = RiskTolerance.Optimal; optimalIsFound.Add(optionChain.Expiry.FutureDate); } else { coveredCall.RiskTolerance = RiskTolerance.Conservative; } } return(coveredCalls); }
public Legs(string name, float baseValue, int level, int levelCap, int tier, LegType type) : base(name, baseValue, level, levelCap, tier) { this.type = type; }
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; } }
/// <summary> /// Groups the calculated team combinations for matches. in a way, that most matches /// can be played in parallel. /// </summary> /// <param name="legType">First leg or return leg.</param> /// <param name="optiType">Optimization type for groups. Differences can be seen be with an uneven number of teams.</param> /// <returns>Return a collection containing collections of team combinations.</returns> internal Collection <TeamCombinationGroup <T> > GetBundledGroups(LegType legType, CombinationGroupOptimization optiType) { var combinationsQueue = new Queue <TeamCombination <T> >(_group.Count); TeamCombinationGroup <T> group; var bundledGroups = new Collection <TeamCombinationGroup <T> >(); // create the FIFO queue foreach (var combination in _group) { combinationsQueue.Enqueue(combination); } switch (optiType) { case CombinationGroupOptimization.NoGrouping: // every group contains a collection with only 1 match while (combinationsQueue.Count > 0) { group = new TeamCombinationGroup <T>(); group.Add(combinationsQueue.Dequeue()); bundledGroups.Add(group); } break; case CombinationGroupOptimization.GroupWithAlternatingHomeGuest: group = new TeamCombinationGroup <T>(); while (combinationsQueue.Count > 0) { TeamCombination <T> combination = combinationsQueue.Dequeue(); if (AnyTeamExistsInGroup(combination, group)) { bundledGroups.Add(group); group = new TeamCombinationGroup <T>(); } group.Add(combination); } if (group.Count > 0) { bundledGroups.Add(group); } break; case CombinationGroupOptimization.LeastGroupsPossible: while (combinationsQueue.Count > 0) { var tmpGroup = new List <TeamCombination <T> >(); tmpGroup.AddRange(combinationsQueue); group = new TeamCombinationGroup <T>(); foreach (var combination in tmpGroup) { if (!AnyTeamExistsInGroup(combination, group)) { group.Add(combinationsQueue.Dequeue()); } } bundledGroups.Add(group); } break; } return(bundledGroups); }
/// <summary> /// Calculates all matches for the given teams, using the round robin system. /// </summary> /// <param name="refereeType">Determines how referees will be assigned for the matches.</param> /// <param name="legType">First leg or return leg.</param> /// <param name="optiType">Optimization type for groups. Differences can be seen be with an uneven number of teams.</param> /// <returns>Return a collection containing collections of optimized team combinations.</returns> public Collection <TeamCombinationGroup <T> > GetBundledGroups(RefereeType refereeType, LegType legType, CombinationGroupOptimization optiType) { _refereeType = refereeType; CalcCombinations(); return(new CombinationGroupOptimizer <T>((legType == LegType.First) ? _combinationGroup : _combinationGroupReturnLeg).GetBundledGroups(legType, optiType)); }