예제 #1
0
 public PositionViewItem(Position position)
   : base(new string[4])
 {
   this.Position = position;
   this.SubItems[0].Text = position.Instrument.Symbol;
   this.Update();
 }
예제 #2
0
파일: Pricer.cs 프로젝트: ForTrade/CSharp
 public virtual double GetPrice(Position position)
 {
     Trade trade = this.framework.DataManager.GetTrade(position.instrument);
     if (trade != null)
     {
         return trade.price;
     }
     return 0.0;
 }
예제 #3
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);
 }
예제 #4
0
파일: Stop.cs 프로젝트: ForTrade/CSharp
 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));
     }
 }
예제 #5
0
파일: Stop.cs 프로젝트: ForTrade/CSharp
 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();
 }
예제 #6
0
        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"));
            }
        }
예제 #7
0
        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"));
                }
            }
        }
예제 #8
0
파일: Strategy.cs 프로젝트: ForTrade/CSharp
 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);
     }
 }
예제 #9
0
파일: Strategy.cs 프로젝트: ForTrade/CSharp
 protected internal virtual void OnPositionClosed(Position position)
 {
 }
예제 #10
0
파일: Strategy.cs 프로젝트: ForTrade/CSharp
 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);
     }
 }
예제 #11
0
파일: Strategy.cs 프로젝트: ForTrade/CSharp
 protected internal virtual void OnPositionOpened(Position position)
 {
 }
예제 #12
0
 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;
 }
예제 #14
0
		internal void OnPositionChanged(Portfolio portfolio, Position position)
		{
			this.OnEvent(new OnPositionChanged(portfolio, position));
		}
예제 #15
0
 public virtual void OnPositionClosed(Position position)
 {
 }
예제 #16
0
 public virtual void OnPositionOpened(Position position)
 {
 }
예제 #17
0
 public virtual void OnPositionChanged(Position position)
 {
 }
예제 #18
0
 public void AddPosition(Position position)
 {
   PositionViewItem positionViewItem = new PositionViewItem(position);
   this.PositionViewItems.Add(position, positionViewItem);
   this.ltvPositions.Items.Insert(0, (ListViewItem) positionViewItem);
 }
예제 #19
0
 public void RemovePosition(Position position)
 {
   this.PositionViewItems[position].Remove();
   this.PositionViewItems.Remove(position);
 }
예제 #20
0
 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);
 }
예제 #21
0
		protected internal override void OnPositionChanged(Position position)
		{
			this.positionComponent.OnPositionChanged(position);
			this.riskComponent.OnPositionChanged(position);
		}
예제 #22
0
		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)
 {
 }
예제 #24
0
		internal override void OnPositionClosed_(Position position)
		{
			if (position.portfolio == this.portfolio)
			{
				this.OnPositionClosed(position);
				return;
			}
			foreach (Strategy current in this.strategies)
			{
				current.OnPositionClosed_(position);
			}
		}
예제 #25
0
 internal void OnPositionOpened(Portfolio portfolio, Position position)
 {
     if (this.strategy != null && this.strategy.status == StrategyStatus.Running)
     {
         this.strategy.OnPositionOpened_(position);
     }
 }
예제 #26
0
 public PositionEventArgs(Portfolio portfolio, Position position)
     : base(portfolio)
 {
     this.Position = position;
 }
예제 #27
0
파일: Stop.cs 프로젝트: ForTrade/CSharp
 internal void OnPositionClosed(Position position)
 {
     if (this.position == position)
     {
         this.Disconnect();
         this.Complete(StopStatus.Canceled);
     }
 }
예제 #28
0
 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;
            }
        }