public void CloseOpenRoundTrip(Instrument instrument, double exitPrice, DateTime exitDate) { RoundTrip roundTrip = this.openRoundTrips[instrument]; if (roundTrip == null) { return; } this.openRoundTrips.Remove(instrument); roundTrip.Close(exitDate); this.list.Add((object)roundTrip); }
private void AWvyKropOG([In] RoundTrip obj0) { DateTime entryDateTime = obj0.EntryDateTime; int index = 0; int num1 = 0; int num2 = this.KxFygqIpbZ.Count - 1; bool flag = true; while (flag) { if (num2 < num1) { if (num1 == 0) { this.KxFygqIpbZ.Insert(0, (object)obj0); return; } else { this.KxFygqIpbZ.Insert(this.KxFygqIpbZ.Count, (object)obj0); return; } } else { index = (num1 + num2) / 2; if ((this.KxFygqIpbZ[index] as RoundTrip).EntryDateTime == entryDateTime && (index + 1 == this.KxFygqIpbZ.Count || (this.KxFygqIpbZ[index + 1] as RoundTrip).EntryDateTime > entryDateTime)) { flag = false; } else if ((this.KxFygqIpbZ[index] as RoundTrip).EntryDateTime > entryDateTime) { num2 = index - 1; } else if ((this.KxFygqIpbZ[index] as RoundTrip).EntryDateTime <= entryDateTime) { num1 = index + 1; } } } this.KxFygqIpbZ.Insert(index, (object)obj0); }
public void Add(RoundTrip roundTrip) { this.array.Add((object) roundTrip); }
public bool Contains(RoundTrip roundTrip) { return this.array.Contains((object) roundTrip); }
public void AddOpenRoundTrip(RoundTrip openRoundTrip) { this.openRoundTrips.Add(openRoundTrip); }
public int GetClosedRoundTripIndex(RoundTrip roundTrip) { return(this.list.IndexOf((object)roundTrip)); }
public bool IsRoundTripOpen(RoundTrip roundTrip) { return(this.openRoundTrips.Contains(roundTrip)); }
public void Test(DateTime firstDateTime, DateTime lastDateTime, bool followChanges) { lock (this) { this.connected = followChanges; this.isTested = true; int local_0 = this.portfolio.Transactions.Count; this.Reset(); this.Disconnect(); this.Connect(); int local_4 = 0; for (DateTime local_5 = this.GetIntervalEnd(firstDateTime, this.timeInterval); local_5 <= lastDateTime; local_5 = this.AddInterval(local_5, this.timeInterval)) { bool local_2 = false; bool local_3 = false; for (int local_6 = local_4; local_6 < local_0; ++local_6) { Transaction local_1 = this.portfolio.Transactions[local_6]; if (local_1.DateTime <= local_5) { switch (local_1.Side) { case Side.Buy: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocationLong += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); local_2 = true; break; case Side.Sell: this.currentAccount += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocationLong -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); local_2 = true; break; case Side.BuyMinus: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocationShort += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); local_3 = true; break; case Side.SellShort: this.currentAccount += FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); this.allocationShort -= FreeQuant.Instruments.Currency.Convert(local_1.Value, local_1.Currency, this.portfolio.Account.Currency); local_3 = true; break; } if (this.isRoundTripsOnly) { if (!this.tempPortfolio.Positions.Contains(local_1.Instrument)) { this.roundTripList.CloseOpenRoundTrip(local_1.Instrument, local_1.Price, local_1.DateTime); if (local_1.Side == Side.Buy) this.shortRoundTripList.CloseOpenRoundTrip(local_1.Instrument, local_1.Price, local_1.DateTime); else this.longRoundTripList.CloseOpenRoundTrip(local_1.Instrument, local_1.Price, local_1.DateTime); } else if (this.tempPortfolio.Positions[local_1.Instrument].Transactions.Count == 1) { PositionSide local_7 = PositionSide.Short; if (local_1.Side == Side.Buy) local_7 = PositionSide.Long; RoundTrip local_8 = new RoundTrip(this.tempPortfolio.Positions[local_1.Instrument], local_1.Instrument, local_7, local_1.Amount, local_1.Price, local_1.Price, local_1.DateTime, local_1.DateTime, RoundTripStatus.Opened); this.roundTripList.AddOpenRoundTrip(local_8); if (local_1.Side == Side.Buy) this.longRoundTripList.AddOpenRoundTrip(local_8); else this.shortRoundTripList.AddOpenRoundTrip(local_8); } else { this.isRoundTripsOnly = false; this.EmitRoundTripsFinished(); } } this.currentAccount -= local_1.Cost; this.tempPortfolio.Add(local_1); this.cost += local_1.Cost; local_4 = local_6 + 1; } else if (local_1.DateTime.Date >= local_5) break; } double local_9 = this.currentWealth; this.currentWealth = this.currentAccount + this.tempPortfolio.GetPositionValue(local_5); this.pnL = this.currentWealth - local_9; this.maxPreviousWealth = Math.Max(this.maxPreviousWealth, local_9); this.drawdown = Math.Min(this.currentWealth - this.maxPreviousWealth, 0.0); this.percentDrawdown = this.currentWealth / this.maxPreviousWealth - 1.0; this.returnValue = (this.currentWealth / local_9 - 1.0) * 100.0; this.totalCost += this.cost; if (this.businessDaysOnly) Calendar.IsWeekend(local_5); if (local_5 >= this.FirstDate.Date) { this.wealthSeries.Add(local_5.AddTicks(1L), this.currentWealth); this.drawdownSeries.Add(local_5.AddTicks(1L), this.drawdown); this.percentDrawdownSeries.Add(local_5.AddTicks(1L), this.percentDrawdown); this.pnLSeries.Add(local_5.AddTicks(1L), this.pnL); this.costSeries.Add(local_5.AddTicks(1L), this.cost); this.returnSeries.Add(local_5.AddTicks(1L), this.returnValue); this.EmitPnLSeriesValueAdded(); this.EmitWealthSeriesValueAddedd(); this.EmitDrawdownSeriesValueAdded(); this.EmitCostSeriesValueAdded(); this.EmitReturnSeriesValueAdded(); if (local_2 || local_3) { this.allocationSeries.Add(local_5.AddTicks(1L), this.allocation); this.EmitAllocationSeriesValueAdded(); } if (local_2) { this.allocationLongSeries.Add(local_5.AddTicks(1L), this.allocationLong); this.EmitAllocationLongSeriesValueAdded(); } if (local_3) { this.allocationShortSeries.Add(local_5.AddTicks(1L), this.allocationShort); this.EmitAllocationShortSeriesValueAdded(); } } } this.EmitStatisticChanged(); if (!this.isRoundTripsOnly) return; this.EmitRoundTripsUpdated(); this.EmitRoundTripStatisticChanged(); } }
public int GetClosedRoundTripIndex(RoundTrip roundTrip) { return this.list.IndexOf((object) roundTrip); }
public bool IsRoundTripOpen(RoundTrip roundTrip) { return this.openRoundTrips.Contains(roundTrip); }
public void Remove(RoundTrip roundTrip) { this.t3XyVaLbw1.Remove((object)roundTrip.Instrument); this.KxFygqIpbZ.Remove((object)roundTrip); }
public void Add(RoundTrip roundTrip) { this.t3XyVaLbw1.Add((object)roundTrip.Instrument, (object)roundTrip); this.AWvyKropOG(roundTrip); }
public bool Contains(RoundTrip roundTrip) { return(this.array.Contains((object)roundTrip)); }
private void o38yaR1giJ(object obj0, TransactionEventArgs obj1) { lock (this) { if (!this.followChanges) return; this.tempPortfolio.Add(obj1.Transaction); this.tempPortfolio.Monitored = true; switch (obj1.Transaction.Side) { case Side.Buy: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationLong += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationLong = true; break; case Side.Sell: this.currentAccount += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationLong -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationLong = true; break; case Side.BuyMinus: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationShort += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationShort = true; break; case Side.SellShort: this.currentAccount += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationShort -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationShort = true; break; } if (this.isRoundTripsOnly) { if (!this.tempPortfolio.Positions.Contains(obj1.Transaction.Instrument)) { this.roundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); if (obj1.Transaction.Side == Side.Buy) this.shortRoundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); else this.longRoundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); } else if (this.tempPortfolio.Positions[obj1.Transaction.Instrument].Transactions.Count == 1) { PositionSide local_0 = PositionSide.Short; if (obj1.Transaction.Side == Side.Buy) local_0 = PositionSide.Long; RoundTrip local_1 = new RoundTrip(this.tempPortfolio.Positions[obj1.Transaction.Instrument], obj1.Transaction.Instrument, local_0, obj1.Transaction.Amount, obj1.Transaction.Price, obj1.Transaction.Price, obj1.Transaction.DateTime, obj1.Transaction.DateTime, RoundTripStatus.Opened); this.roundTripList.AddOpenRoundTrip(local_1); if (obj1.Transaction.Side == Side.Buy) this.longRoundTripList.AddOpenRoundTrip(local_1); else this.shortRoundTripList.AddOpenRoundTrip(local_1); } else { this.isRoundTripsOnly = false; this.EmitRoundTripsFinished(); } } if (this.isRoundTripsOnly) this.roundTripList.UpdateOpenRoundTrips(); this.currentAccount -= obj1.Transaction.Cost; this.cost += obj1.Transaction.Cost; if (this.isRoundTripsOnly) { this.EmitRoundTripsUpdated(); this.EmitRoundTripStatisticChanged(); } if (!this.waitingForStart) return; this.waitingForStart = false; this.awaitTime = this.GetIntervalEnd(obj1.Transaction.DateTime, this.timeInterval); this.awaitHandler = new ReminderEventHandler(this.JKNyi7SDXu); Clock.AddReminder(this.awaitHandler, this.awaitTime, (object)null); } }
public void Add(RoundTrip roundTrip) { this.array.Add((object)roundTrip); }
public bool Contains(RoundTrip roundTrip) { return(this.KxFygqIpbZ.Contains((object)roundTrip)); }