public PositionViewItem(Position position) : base(new string[4]) { this.Position = position; this.SubItems[0].Text = position.Instrument.Symbol; this.Update(); }
public virtual double GetPrice(Position position) { Trade trade = this.framework.DataManager.GetTrade(position.instrument); if (trade != null) { return trade.price; } return 0.0; }
protected override void OnPositionOpened(SmartQuant.Position position) { // 止损条件 // 1、亏损固定点数 // 2、亏损当前价格的百分比 //StopEx stop = new StopEx(this, position, 0.01, StopType.Trailing, StopMode.Percent, StopIndicator.Value); //stop.TraceOnBar = false; //stop.TraceOnTrade = true; //AddStop(stop); }
public Stop(Strategy strategy, Position position, DateTime time) { this.strategy = strategy; this.position = position; this.instrument = position.instrument; this.qty = position.qty; this.side = position.Side; this.type = StopType.Time; this.creationTime = strategy.framework.Clock.DateTime; this.completionTime = time; this.stopPrice = this.GetInstrumentPrice(); if (this.completionTime > this.creationTime) { strategy.framework.Clock.AddReminder(new Reminder(new ReminderCallback(this.OnClock), this.completionTime, null)); } }
public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode) { this.strategy = strategy; this.position = position; this.instrument = position.instrument; this.qty = position.qty; this.side = position.Side; this.level = level; this.type = type; this.mode = mode; this.currPrice = this.GetInstrumentPrice(); this.trailPrice = this.currPrice; this.stopPrice = this.GetStopPrice(); this.creationTime = strategy.framework.Clock.DateTime; this.completionTime = DateTime.MinValue; this.Connect(); }
public void QtyToNet(Instrument instrument, double NetQty, Portfolio Net) { double Qty = 0; SmartQuant.Position p = Net.GetPosition(instrument); if (p != null) { Qty = p.Qty; } double diff = NetQty - Qty; if (diff > 0) { Net.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Buy, diff, 0, "Initial Position")); } else if (diff < 0) { Net.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Sell, -diff, 0, "Initial Position")); } }
public void QtyToLongShort(Instrument instrument, double LongQty, double ShortQty, Portfolio Long, Portfolio Short) { { double Qty = 0; SmartQuant.Position p = Long.GetPosition(instrument); if (p != null) { Qty = p.Qty; } double diff = LongQty - Qty; if (diff > 0) { Long.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Buy, diff, 0, "Initial Long Position")); } else if (diff < 0) { Long.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Sell, -diff, 0, "Initial Long Position")); } } { double Qty = 0; SmartQuant.Position p = Short.GetPosition(instrument); if (p != null) { Qty = p.Qty; } double diff = ShortQty - Qty; if (diff > 0) { Short.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Sell, diff, 0, "Initial Short Position")); } else if (diff < 0) { Short.Add(new Fill(framework.Clock.DateTime, null, instrument, CurrencyId.CNY, SmartQuant.OrderSide.Buy, -diff, 0, "Initial Short Position")); } } }
internal virtual void OnPositionClosed_(Position position) { if (this.raiseEvents && position.portfolio == this.portfolio) { this.OnPositionClosed(position); List<Stop> list = this.stopsByInstrument[position.instrument.Id]; if (list != null) { for (int i = 0; i < list.Count; i++) { if (list[i].position == position) { list[i].Cancel(); } } } } for (LinkedListNode<Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnPositionClosed_(position); } }
protected internal virtual void OnPositionClosed(Position position) { }
internal virtual void OnPositionChanged_(Position position) { if (this.raiseEvents && position.portfolio == this.portfolio) { this.OnPositionChanged(position); } for (LinkedListNode<Strategy> linkedListNode = this.strategies.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnPositionChanged_(position); } }
protected internal virtual void OnPositionOpened(Position position) { }
public void UpdatePosition(Position position) { this.PositionViewItems[position].Update(); }
public StopEx(SmartQuant.Strategy strategy, SmartQuant.Position position, double level, StopType type, StopMode mode, StopIndicator stopIndicator) : base(strategy, position, level, type, mode) { this.indicator = stopIndicator; }
internal void OnPositionChanged(Portfolio portfolio, Position position) { this.OnEvent(new OnPositionChanged(portfolio, position)); }
public virtual void OnPositionClosed(Position position) { }
public virtual void OnPositionOpened(Position position) { }
public virtual void OnPositionChanged(Position position) { }
public void AddPosition(Position position) { PositionViewItem positionViewItem = new PositionViewItem(position); this.PositionViewItems.Add(position, positionViewItem); this.ltvPositions.Items.Insert(0, (ListViewItem) positionViewItem); }
public void RemovePosition(Position position) { this.PositionViewItems[position].Remove(); this.PositionViewItems.Remove(position); }
public void Add(Fill fill) { this.fills.Add(fill); Instrument instrument = fill.instrument; bool flag = false; Position position = this.positionByInstrument[instrument.Id]; if (position == null) { position = new Position(this, instrument); this.positionByInstrument[instrument.Id] = position; this.positions.Add(position); flag = true; } if (position.qty == 0.0) { flag = true; } position.Add(fill); this.account.Add(fill); if (flag) { this.framework.eventServer.OnPositionOpened(this, position); this.framework.eventServer.OnPositionChanged(this, position); } else { this.framework.eventServer.OnPositionChanged(this, position); if (position.qty == 0.0) { this.framework.eventServer.OnPositionClosed(this, position); } } this.framework.eventServer.OnFill(this, fill); if (this.parent != null) { this.parent.Add(fill); } this.statistics.Add(fill); }
protected internal override void OnPositionChanged(Position position) { this.positionComponent.OnPositionChanged(position); this.riskComponent.OnPositionChanged(position); }
public void OnPositionOpened(Portfolio portfolio, Position position) { this.OnEvent(new OnPositionOpened(portfolio, position)); }
public StopEx(SmartQuant.Strategy strategy, SmartQuant.Position position, DateTime time) : base(strategy, position, time) { }
internal override void OnPositionClosed_(Position position) { if (position.portfolio == this.portfolio) { this.OnPositionClosed(position); return; } foreach (Strategy current in this.strategies) { current.OnPositionClosed_(position); } }
internal void OnPositionOpened(Portfolio portfolio, Position position) { if (this.strategy != null && this.strategy.status == StrategyStatus.Running) { this.strategy.OnPositionOpened_(position); } }
public PositionEventArgs(Portfolio portfolio, Position position) : base(portfolio) { this.Position = position; }
internal void OnPositionClosed(Position position) { if (this.position == position) { this.Disconnect(); this.Complete(StopStatus.Canceled); } }
public OnPositionClosed(Portfolio portfolio, Position position) { this.portfolio = portfolio; this.position = position; }
private void CellEndEdit(SmartQuant.Portfolio pf, SmartQuant.Position pos) { double price = GetCellDouble(this.treeGridView1.Rows[this.treeGridView1.CurrentCell.RowIndex].Cells[IDX_EntryPrice]); DateTime dateTime = GetCellDateTime(this.treeGridView1.Rows[this.treeGridView1.CurrentCell.RowIndex].Cells[IDX_EntryDate]); switch (this.treeGridView1.CurrentCell.ColumnIndex) { case IDX_AccountValue: { double new_data = GetCellDouble(this.treeGridView1.CurrentCell); PortfolioHelper.AddAccountValue(framework, pf, dateTime, pf.Account.CurrencyId, pf.AccountValue, new_data, "TreeGridView"); } break; case IDX_Short: { if (pos == null) { Console.WriteLine("Error:Position == null"); return; } double new_data = GetCellDouble(this.treeGridView1.CurrentCell); if (new_data < 0) { Console.WriteLine("Error:Short must >0"); return; } PortfolioHelper.AddShortPosition(framework, pf, dateTime, pos.Instrument, pos.Instrument.CurrencyId, pos.ShortPositionQty, new_data, price, "TreeGridView"); } break; case IDX_Long: { if (pos == null) { Console.WriteLine("Error:Position == null"); return; } double new_data = GetCellDouble(this.treeGridView1.CurrentCell); if (new_data < 0) { Console.WriteLine("Error:Long must >0"); return; } PortfolioHelper.AddLongPosition(framework, pf, dateTime, pos.Instrument, pos.Instrument.CurrencyId, pos.LongPositionQty, new_data, price, "TreeGridView"); } break; case IDX_Symbol: { string new_data = this.treeGridView1.CurrentCell.Value.ToString(); if (string.IsNullOrWhiteSpace(new_data)) { Console.WriteLine("Error:Symbol is empty"); return; } var inst = framework.InstrumentManager.Instruments[new_data]; if (inst == null) { Console.WriteLine("Error:Instrument is not exists"); return; } pos = pf.GetPosition(inst); if (pos != null) { Console.WriteLine("Error:Position is exists"); return; } PortfolioHelper.AddPosition2(framework, pf, dateTime, inst, inst.CurrencyId, OrderSide.Buy, SubSide.Undefined, 0, price, "TreeGridView"); } break; default: return; } }