public static void AddShortPosition(
            Framework framework,
            SmartQuant.Portfolio pf,
            DateTime dateTime,
            Instrument instrument, byte currencyId,
            double old_qty, double new_qty,
            double price,
            string text)
        {
            double diff = new_qty - old_qty;

            if (diff == 0)
            {
                return;
            }

            if (diff > 0)
            {
                // 数量变多是开仓
                AddPosition(framework, pf, dateTime, instrument, currencyId, OrderSide.Sell, SubSide.SellShort, diff, price, "Short+" + text);
            }
            else
            {
                AddPosition(framework, pf, dateTime, instrument, currencyId, OrderSide.Buy, SubSide.BuyCover, -diff, price, "Short-" + text);
            }

            Console.WriteLine("Portfolio:{0};Instrument:{1};ShortPositionQty:{2} + {3} = {4}",
                              pf.Name, instrument.Symbol, old_qty, diff, new_qty);
        }
Exemplo n.º 2
0
 public void OnInit(string name)
 {
     this.name      = name;
     this.portfolio = Framework.Current.PortfolioManager[name];
     if (this.portfolio == null)
     {
         return;
     }
     this.ltvStatistics.BeginUpdate();
     this.ltvStatistics.Groups.Clear();
     this.ltvStatistics.Items.Clear();
     for (int index = 0; index < this.portfolio.Statistics.Items.Count; ++index)
     {
         PortfolioStatisticsItem statistics = this.portfolio.Statistics.Items[index];
         if (statistics.Show)
         {
             if (this.ltvStatistics.Groups[statistics.Category] == null)
             {
                 this.ltvStatistics.Groups.Add(statistics.Category, statistics.Category);
             }
             StatisticsViewItem statisticsViewItem = new StatisticsViewItem(statistics);
             statisticsViewItem.Group = this.ltvStatistics.Groups[statistics.Category];
             this.ltvStatistics.Items.Add((ListViewItem)statisticsViewItem);
         }
     }
     this.ltvStatistics.EndUpdate();
 }
        private TreeGridNodeCollection FindNodesByPortfolio(SmartQuant.Portfolio portfolio)
        {
            // 找到对应的节点然后再,然后再做决定
            TreeGridNodeCollection Nodes = null;

            if (portfolio.Parent == null)
            {
                // 根节点
                Nodes = this.treeGridView1.Nodes;
            }
            else
            {
                // 子节点
                TreeGridNode _node;
                if (portfolio_nodes.TryGetValue(portfolio.Parent, out _node))
                {
                    Nodes = _node.Nodes;
                }
                else
                {
                    Nodes = this.treeGridView1.Nodes;
                }
            }

            return(Nodes);
        }
        private TreeGridNode AddPortfolio(SmartQuant.Portfolio portfolio, TreeGridNodeCollection Nodes, bool hasChildren)
        {
            // 添加投资组合
            var node = Nodes.Add(
                portfolio.Name,
                null,
                null,
                null,
                null,
                portfolio.AccountValue,
                null,
                DateTime.Today
                );

            node.Cells[IDX_Symbol].ReadOnly              = false;
            node.Cells[IDX_Symbol].Style.BackColor       = Color.LightYellow;
            node.Cells[IDX_Long].ReadOnly                = true;
            node.Cells[IDX_Short].ReadOnly               = true;
            node.Cells[IDX_AccountValue].Style.BackColor = Color.LightYellow;
            node.Cells[IDX_EntryDate].Style.BackColor    = Color.LightYellow;

            // 记录下,下次添加子节点使用
            portfolio_nodes.Add(portfolio, node);
            // 记录下,用于回头修改持仓,它一般有子节点
            nodes_position_portfolio.Add(node, portfolio);

            if (!hasChildren)
            {
                node.DefaultCellStyle.BackColor = Color.LightPink;
            }

            return(node);
        }
        public static void AddPosition2(
            Framework framework,
            SmartQuant.Portfolio pf,
            DateTime dateTime,
            Instrument instrument, byte currencyId,
            OrderSide side, SubSide subSide,
            double qty, double price,
            string text)
        {
            // 强行改变Portfolio,无法存盘,所以被淘汰

            var order = new Order(null, pf, instrument, OrderType.Limit, side, qty, price, 0, TimeInForce.Day, 0, text);

            order.SubSide = subSide;

            var er = new ExecutionReport(order);

            er.DateTime   = dateTime;
            er.CurrencyId = currencyId;
            er.LastQty    = qty;
            er.LastPx     = price;
            er.Text       = text;
            var f = new Fill(er);

            pf.Add(f);
        }
Exemplo n.º 6
0
 public ChildrenStatisticsViewItem(SmartQuant.Portfolio portfolio)
   : base(new string[8])
 {
     this.Portfolio = portfolio;
     this.SubItems[0].Text = this.Portfolio.Name;
     this.UseItemStyleForSubItems = false;
     this.Update();
 }
Exemplo n.º 7
0
 public ChildrenStatisticsViewItem(SmartQuant.Portfolio portfolio)
     : base(new string[8])
 {
     this.Portfolio               = portfolio;
     this.SubItems[0].Text        = this.Portfolio.Name;
     this.UseItemStyleForSubItems = false;
     this.Update();
 }
        private void button_import_Click(object sender, EventArgs e)
        {
            // 导入数据时,可以通过导入的方式进行改仓,或记录今昨
            // 比如第一天收盘后多5手,第二天收盘后多2手,按此记录即可
            // 它会在第二天的指定时间平仓3手

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "CSV文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //设置“另存为文件类型”或“文件类型”框中出现的选择内容
            ofd.Title            = "打开文件";                             //获取或设置文件对话框标题
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var list = PortfolioHelper.from_csv <PositionItem>(ofd.FileName);

            foreach (var it in list)
            {
                var inst = framework.InstrumentManager.GetBySymbol(it.Symbol);
                var pf   = framework.PortfolioManager.GetByName(it.PortfolioName);
                if (pf == null)
                {
                    pf = new SmartQuant.Portfolio(it.PortfolioName);
                    framework.PortfolioManager.Add(pf);
                    pf.Parent = framework.PortfolioManager.GetByName(it.Parent);
                }
                if (inst == null)
                {
                    continue;
                }
                var position = pf.GetPosition(inst);
                var old_qty  = 0.0;

                if (it.Side == PositionSide.Long)
                {
                    if (position != null)
                    {
                        old_qty = position.LongPositionQty;
                    }
                    PortfolioHelper.AddLongPosition(framework, pf, it.EntryDate, inst, inst.CurrencyId, old_qty, it.Qty, it.EntryPrice, "Import from csv");
                }
                else
                {
                    if (position != null)
                    {
                        old_qty = position.ShortPositionQty;
                    }
                    PortfolioHelper.AddShortPosition(framework, pf, it.EntryDate, inst, inst.CurrencyId, old_qty, it.Qty, it.EntryPrice, "Import from csv");
                }
            }

            // refresh();
        }
        private TreeGridNode FindNodeByPortfolio(SmartQuant.Portfolio portfolio)
        {
            TreeGridNode _node = null;

            if (portfolio_nodes.TryGetValue(portfolio, out _node))
            {
                return(_node);
            }

            return(null);
        }
Exemplo n.º 10
0
 public void OnInit(string name, Portfolio portfolioControl)
 {
   this.name = name;
   this.portfolioControl = portfolioControl;
   this.portfolio = Framework.Current.PortfolioManager[name];
   this.PositionViewItems.Clear();
   this.ltvPositions.Items.Clear();
   this.TransactionsViewItems.Clear();
   this.ltvTransactions.VirtualListSize = this.TransactionsViewItems.Count;
   this.ltvPortfolio.Items.Clear();
   this.ltvPortfolio.Items.Add(new ListViewItem(new string[this.ltvPortfolio.Columns.Count]));
 }
Exemplo n.º 11
0
 public void OnInit(string name, Portfolio portfolioControl)
 {
     this.name             = name;
     this.portfolioControl = portfolioControl;
     this.portfolio        = Framework.Current.PortfolioManager[name];
     this.PositionViewItems.Clear();
     this.ltvPositions.Items.Clear();
     this.TransactionsViewItems.Clear();
     this.ltvTransactions.VirtualListSize = this.TransactionsViewItems.Count;
     this.ltvPortfolio.Items.Clear();
     this.ltvPortfolio.Items.Add(new ListViewItem(new string[this.ltvPortfolio.Columns.Count]));
 }
Exemplo n.º 12
0
 public void OnInit(string name)
 {
     this.name = name;
     if (Framework.Current.PortfolioManager[name] != null)
     {
         this.portfolio = Framework.Current.PortfolioManager[name];
     }
     this.cmbChooseStatistics.Items.Clear();
     this.cmbChooseStatistics.Items.Add((object)"Daily Return %");
     this.cmbChooseStatistics.Items.Add((object)"Drawdown %");
     this.cmbChooseStatistics.SelectedIndex = 0;
     this.UpdateGUI();
 }
Exemplo n.º 13
0
 public void UpdateGUI()
 {
   this.portfolio = Framework.Current.PortfolioManager[this.name];
   if (this.portfolio == null)
     return;
   this.ltvPortfolio.BeginUpdate();
   string format = "F2";
   this.ltvPortfolio.Items[0].SubItems[0].Text = CurrencyId.GetName(this.portfolio.Account.CurrencyId);
   this.ltvPortfolio.Items[0].SubItems[1].Text = this.portfolio.AccountValue.ToString(format);
   this.ltvPortfolio.Items[0].SubItems[2].Text = this.portfolio.PositionValue.ToString(format);
   this.ltvPortfolio.Items[0].SubItems[3].Text = this.portfolio.Value.ToString(format);
   this.ltvPortfolio.EndUpdate();
   this.ltvTransactions.VirtualListSize = this.TransactionsViewItems.Count;
 }
Exemplo n.º 14
0
 public Order(IExecutionProvider provider, Instrument instrument, OrderType type, OrderSide side, double qty, double price = 0.0, double stopPx = 0.0, TimeInForce timeInForce = TimeInForce.Day, string text = "")
     : this()
 {
     this.provider = provider;
     this.instrument = instrument;
     this.type = type;
     this.side = side;
     this.qty = qty;
     this.price = price;
     this.stopPx = stopPx;
     this.timeInForce = timeInForce;
     this.text = text;
     this.portfolio = null;
 }
        private void AddNodes_Portfolio(SmartQuant.Portfolio portfolio)
        {
            // 找到对应的节点然后再,然后再做决定
            TreeGridNodeCollection Nodes = FindNodesByPortfolio(portfolio);

            if (Nodes == null)
            {
                return;
            }
            TreeGridNode node = null;

            bool hasChildren = portfolio.Children.Count > 0;

            node = AddPortfolio(portfolio, Nodes, hasChildren);
            node.Expand();
        }
        private void AddNodes_Position(SmartQuant.Portfolio portfolio)
        {
            // 找到对应的节点然后再,然后再做决定
            TreeGridNode node = FindNodeByPortfolio(portfolio);

            bool hasChildren = portfolio.Children.Count > 0;

            if (node == null)
            {
                AddPositions(portfolio, this.treeGridView1.Nodes, hasChildren);
            }
            else
            {
                AddPositions(portfolio, node.Nodes, hasChildren);
            }
        }
        public static void AddPosition(
            Framework framework,
            SmartQuant.Portfolio pf,
            DateTime dateTime,
            Instrument instrument, byte currencyId,
            OrderSide side, SubSide subSide,
            double qty, double price,
            string text)
        {
            // 创建Order
            var order = new Order(null, pf, instrument, OrderType.Limit, side, qty, price, 0, TimeInForce.Day, 0, text);

            order.SubSide = subSide;
            // 想记录下来就得注册
            framework.OrderManager.Register(order);

            // 模拟下单
            var executionCommand = new ExecutionCommand(ExecutionCommandType.Send, order);

            executionCommand.DateTime = dateTime;
            executionCommand.IsLoaded = true;
            framework.OrderManager.Messages.Add(executionCommand);
            order.OnExecutionCommand(executionCommand);
            framework.EventServer.OnEvent(executionCommand);

            // 直接保存不管用
            //if (framework.StrategyManager.Persistence == StrategyPersistence.Save || framework.StrategyManager.Persistence == StrategyPersistence.Full)
            //{
            //    framework.OrderServer.Save(executionCommand);
            //}

            // 模拟成交
            var executionReport = new ExecutionReport(executionCommand);

            executionReport.OrdStatus = OrderStatus.Filled;
            executionReport.ExecType  = ExecType.ExecTrade;
            executionReport.DateTime  = dateTime;
            executionReport.LastPx    = price;
            executionReport.LastQty   = qty;
            executionReport.LeavesQty = 0;
            executionReport.CumQty    = qty;
            executionReport.IsLoaded  = true;
            // 成交不需要额外添加
            // framework.OrderManager.Messages.Add(executionReport);
            order.OnExecutionReport(executionReport);
            framework.EventServer.OnEvent(executionReport);
        }
        public static void AddAccountValue(
            Framework framework,
            SmartQuant.Portfolio pf,
            DateTime dateTime,
            byte currencyId, double old_value, double new_value, string text)
        {
            double diff = new_value - old_value;

            if (diff == 0)
            {
                return;
            }

            pf.Account.Deposit(dateTime, diff, currencyId, text);

            Console.WriteLine("Portfolio:{3};AccountValue: {0} + {1} = {2}", old_value, diff, new_value, text);
        }
Exemplo n.º 19
0
 public void OnInit(string name)
 {
     this.name      = name;
     this.portfolio = Framework.Current.PortfolioManager[name];
     this.indexes   = new Dictionary <string, int>();
     if (this.portfolio == null)
     {
         return;
     }
     this.ltvChldStatistics.BeginUpdate();
     this.ltvChldStatistics.Items.Clear();
     for (int index = 0; index < this.portfolio.Children.Count; ++index)
     {
         this.ltvChldStatistics.Items.Add((ListViewItem) new ChildrenStatisticsViewItem(this.portfolio.Children[index]));
     }
     this.ltvChldStatistics.EndUpdate();
 }
Exemplo n.º 20
0
        public void UpdateGUI()
        {
            this.portfolio = Framework.Current.PortfolioManager[this.name];
            if (this.portfolio == null)
            {
                return;
            }
            this.ltvPortfolio.BeginUpdate();
            string format = "F2";

            this.ltvPortfolio.Items[0].SubItems[0].Text = CurrencyId.GetName(this.portfolio.Account.CurrencyId);
            this.ltvPortfolio.Items[0].SubItems[1].Text = this.portfolio.AccountValue.ToString(format);
            this.ltvPortfolio.Items[0].SubItems[2].Text = this.portfolio.PositionValue.ToString(format);
            this.ltvPortfolio.Items[0].SubItems[3].Text = this.portfolio.Value.ToString(format);
            this.ltvPortfolio.EndUpdate();
            this.ltvTransactions.VirtualListSize = this.TransactionsViewItems.Count;
        }
Exemplo n.º 21
0
        public void UpdateGUI()
        {
            if (Framework.Current.PortfolioManager[this.name] != null)
            {
                this.portfolio = Framework.Current.PortfolioManager[this.name];
            }
            this.indexes = new Dictionary <string, int>();
            if (this.portfolio == null)
            {
                return;
            }
            this.ltvMatrix.BeginUpdate();
            this.ltvMatrix.Items.Clear();
            this.ltvMatrix.Columns.Clear();
            int count = this.portfolio.Children.Count;

            if (count > 0)
            {
                string[] items = new string[count + 1];
                List <List <TimeSeries> > list1 = new List <List <TimeSeries> >();
                for (int index1 = 0; index1 < count; ++index1)
                {
                    items[index1 + 1] = this.portfolio.Children[index1].Name;
                    List <TimeSeries> list2 = new List <TimeSeries>();
                    list2.Add(this.GetTimeSeries(this.portfolio.Children[index1].Statistics));
                    for (int index2 = 0; index2 < count; ++index2)
                    {
                        list2.Add(this.GetTimeSeries(this.portfolio.Children[index2].Statistics));
                    }
                    list1.Add(list2);
                }
                for (int index = 0; index < items.Length; ++index)
                {
                    this.ltvMatrix.Columns.Add("");
                    this.ltvMatrix.Columns[index].Width = 125;
                }
                this.ltvMatrix.Items.Add(new ListViewItem(items));
                for (int index = 0; index < list1.Count; ++index)
                {
                    this.ltvMatrix.Items.Add((ListViewItem) new CorrelationMatrixViewItem(items[index + 1], list1[index]));
                }
            }
            this.ltvMatrix.EndUpdate();
        }
Exemplo n.º 22
0
 private void Reset()
 {
     Invoke((System.Action)delegate
     {
         this.portfolio = Framework.Current.PortfolioManager.Portfolios.GetByIndex(0);
         if (this.portfolio == null)
             return;
         PortfolioPerformance performance = this.portfolio.Performance;
         this.chart3.Reset();
         this.chart3.SetMainSeries(performance.EquitySeries, false, Color.White);
         this.chart3.AddPad();
         this.chart3.DrawSeries(performance.DrawdownSeries, 2, Color.White, SimpleDSStyle.Line, SearchOption.ExactFirst, SmoothingMode.HighSpeed);
         this.chart3.UpdateStyle = ChartUpdateStyle.WholeRange;
         performance.Updated += new EventHandler((sender, e) =>
         {
             this.chart3.OnItemAdedd(this.portfolio.Performance.EquitySeries.LastDateTime);
         });
     });
 }
        private void AddPositions(SmartQuant.Portfolio portfolio, TreeGridNodeCollection Nodes, bool hasChildren)
        {
            // 检查是否有持仓
            foreach (var position in portfolio.Positions)
            {
                // 添加持仓
                var entryPrice = 0.0;
                var entyDate   = DateTime.Today;
                if (position.Fills.Count > 0)
                {
                    entryPrice = position.Fills.Last().Price;
                    entyDate   = position.Fills.Last().DateTime;
                }
                var _node = Nodes.Add(
                    portfolio.Name,
                    position.Instrument.Symbol,
                    position.Amount,
                    position.LongPositionQty,
                    position.ShortPositionQty,
                    null,
                    entryPrice,
                    entyDate
                    );

                _node.Cells[IDX_Symbol].ReadOnly            = true;
                _node.Cells[IDX_Long].Style.BackColor       = Color.LightYellow;
                _node.Cells[IDX_Short].Style.BackColor      = Color.LightYellow;
                _node.Cells[IDX_AccountValue].ReadOnly      = true;
                _node.Cells[IDX_EntryPrice].Style.BackColor = Color.LightYellow;
                _node.Cells[IDX_EntryDate].Style.BackColor  = Color.LightYellow;

                if (!hasChildren)
                {
                    _node.DefaultCellStyle.BackColor = Color.LightGreen;
                }

                // 记录下,用于回头修改持仓,它没有子节点
                nodes_position_portfolio.Add(_node, position);
            }
        }
Exemplo n.º 24
0
 public void UpdateGUI()
 {
     if (this.portfolio == null)
     {
         this.OnInit(this.name);
     }
     this.portfolio = Framework.Current.PortfolioManager[this.name];
     if (this.portfolio == null)
     {
         return;
     }
     this.ltvChldStatistics.BeginUpdate();
     foreach (ListViewItem listViewItem in this.ltvChldStatistics.Items)
     {
         ChildrenStatisticsViewItem statisticsViewItem = listViewItem as ChildrenStatisticsViewItem;
         if (statisticsViewItem != null)
         {
             statisticsViewItem.Update();
         }
     }
     this.ltvChldStatistics.EndUpdate();
 }
Exemplo n.º 25
0
 public Strategy(Framework framework, string name)
 {
     this.framework = framework;
     this.Name = name;
     this.strategiesByInstrument = new IdArray<LinkedList<Strategy>>(1000);
     this.strategyByOrderId = new IdArray<Strategy>(1000);
     this.strategies = new LinkedList<Strategy>();
     this.status = StrategyStatus.Stopped;
     this.instruments = new InstrumentList();
     this.instrumentCountTable = new IdArray<int>(1000);
     if (framework != null)
     {
         this.portfolio = new Portfolio(framework, this.Name);
         framework.PortfolioManager.Add(this.portfolio);
     }
     this.bars = new BarSeries("", "");
     this.equity = new TimeSeries();
     this.bids = new TickSeries("");
     this.asks = new TickSeries("");
     this.stops = new List<Stop>();
     this.stopsByInstrument = new IdArray<List<Stop>>(1000);
 }
        private void AddNodes(SmartQuant.Portfolio portfolio, ShowType show_type)
        {
            // 找到对应的节点然后再,然后再做决定
            TreeGridNodeCollection Nodes = FindNodesByPortfolio(portfolio);

            if (Nodes == null)
            {
                return;
            }
            TreeGridNode node = null;

            bool hasChildren = portfolio.Children.Count > 0;

            switch (show_type)
            {
            case ShowType.All:
                node = AddPortfolio(portfolio, Nodes, hasChildren);
                AddPositions(portfolio, node.Nodes, hasChildren);
                node.Expand();
                break;

            case ShowType.PortfolioOnly:
                node = AddPortfolio(portfolio, Nodes, hasChildren);
                node.Expand();
                break;

            case ShowType.PositionOnly:
                // 只显示根节点
                // 注意,如果出现在父节点上添加持仓将无法处理,所以最好不要使用特别的用法
                if (hasChildren)
                {
                    return;
                }
                AddPositions(portfolio, this.treeGridView1.Nodes, hasChildren);
                break;
            }
        }
Exemplo n.º 27
0
		internal void OnParentChanged(Portfolio portfolio)
		{
			this.OnEvent(new OnPortfolioParentChanged(portfolio));
		}
Exemplo n.º 28
0
		public void OnPortfolioDeleted(Portfolio portfolio)
		{
			this.OnEvent(new OnPortfolioDeleted(portfolio));
		}
Exemplo n.º 29
0
		internal void OnPositionChanged(Portfolio portfolio, Position position)
		{
			this.OnEvent(new OnPositionChanged(portfolio, position));
		}
Exemplo n.º 30
0
 public void OnInit(string name)
 {
   this.name = name;
   this.portfolio = Framework.Current.PortfolioManager[name];
   if (this.portfolio == null)
     return;
   this.ltvStatistics.BeginUpdate();
   this.ltvStatistics.Groups.Clear();
   this.ltvStatistics.Items.Clear();
   for (int index = 0; index < this.portfolio.Statistics.Items.Count; ++index)
   {
     PortfolioStatisticsItem statistics = this.portfolio.Statistics.Items[index];
     if (statistics.Show)
     {
       if (this.ltvStatistics.Groups[statistics.Category] == null)
         this.ltvStatistics.Groups.Add(statistics.Category, statistics.Category);
       StatisticsViewItem statisticsViewItem = new StatisticsViewItem(statistics);
       statisticsViewItem.Group = this.ltvStatistics.Groups[statistics.Category];
       this.ltvStatistics.Items.Add((ListViewItem) statisticsViewItem);
     }
   }
   this.ltvStatistics.EndUpdate();
 }
Exemplo n.º 31
0
 public OnPortfolioAdded(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }
Exemplo n.º 32
0
 public void OnInit(string name)
 {
   this.name = name;
   if (Framework.Current.PortfolioManager[name] != null)
     this.portfolio = Framework.Current.PortfolioManager[name];
   this.cmbChooseStatistics.Items.Clear();
   this.cmbChooseStatistics.Items.Add((object) "Daily Return %");
   this.cmbChooseStatistics.Items.Add((object) "Drawdown %");
   this.cmbChooseStatistics.SelectedIndex = 0;
   this.UpdateGUI();
 }
Exemplo n.º 33
0
        private void Reset()
        {
            Invoke((Action)delegate
            {
                this.portfolio = Framework.Current.PortfolioManager.Portfolios.GetByIndex(0);
                if (this.portfolio == null)
                    return;
                foreach (var p in Framework.Current.PortfolioManager.Portfolios)
                {
                    var portfolio = new SmartQuant.Controls.Portfolios.Portfolio();
                    portfolio.Dock = DockStyle.Fill;
                    portfolio.Name = p.Name;
                    portfolio.Init(dataLoader.PortfolioEventQueue, new []{p.Name});

                    var tpage = new TabPage();
                    tpage.Controls.Add(portfolio);
                    tpage.Name = portfolio.Name;
                    tpage.Text = portfolio.Name;
                    this.tabControl1.Controls.Add(tpage);
                    portfolio.UpdateGUI();
                }

                var accountData = new SmartQuant.Controls.Data.Account.AccountData();
                accountData.Dock = DockStyle.Fill;
                accountData.Name = "Account";

                var page = new TabPage();
                page.Controls.Add(accountData);
                page.Name = accountData.Name;
                page.Text = accountData.Name;
                this.tabControl1.Controls.Add(page);

                var performance = this.portfolio.Performance;
                this.chart3.Reset();
                this.chart3.SetMainSeries(performance.EquitySeries, false, Color.White);
                this.chart3.AddPad();
                this.chart3.DrawSeries(performance.DrawdownSeries, 2, Color.White, SimpleDSStyle.Line, SearchOption.ExactFirst, SmoothingMode.HighSpeed);
                this.chart3.UpdateStyle = ChartUpdateStyle.WholeRange;
                performance.Updated += (sender, e) => this.chart3.OnItemAdded();
            });
        }
Exemplo n.º 34
0
 public void OnPositionOpened(Portfolio portfolio, Position position)
 {
     this.OnEvent(new OnPositionOpened(portfolio, position));
 }
Exemplo n.º 35
0
 public Position(Portfolio portfolio, Instrument instrument)
 {
     this.portfolio = portfolio;
     this.instrument = instrument;
 }
Exemplo n.º 36
0
 public OnFill(Portfolio portfolio, Fill fill)
 {
     this.portfolio = portfolio;
     this.fill      = fill;
 }
        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;
            }
        }
Exemplo n.º 38
0
 public PositionEventArgs(Portfolio portfolio, Position position)
     : base(portfolio)
 {
     this.Position = position;
 }
Exemplo n.º 39
0
 public OnPositionClosed(Portfolio portfolio, Position position)
 {
     this.portfolio = portfolio;
     this.position = position;
 }
Exemplo n.º 40
0
		public ExecutionCommand(ExecutionCommand command)
		{
			this.id = command.id;
			this.providerId = command.providerId;
			this.portfolioId = command.portfolioId;
			this.transactTime = command.transactTime;
			this.dateTime = command.dateTime;
			this.instrument = command.instrument;
			this.provider = command.provider;
			this.portfolio = command.portfolio;
			this.side = command.side;
			this.orderType = command.OrdType;
			this.timeInForce = command.timeInForce;
			this.price = command.price;
			this.stopPx = command.stopPx;
			this.qty = command.qty;
			this.oCA = command.oCA;
			this.text = command.text;
		}
Exemplo n.º 41
0
 public OnPortfolioParentChanged(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }
Exemplo n.º 42
0
 internal void OnPositionOpened(Portfolio portfolio, Position position)
 {
     if (this.strategy != null && this.strategy.status == StrategyStatus.Running)
     {
         this.strategy.OnPositionOpened_(position);
     }
 }
Exemplo n.º 43
0
 public Order(Order order)
     : base()
 {
     this.id = -1;
     this.oCA = "";
     this.text = "";
     this.id = order.id;
     this.providerId = order.providerId;
     this.portfolioId = order.portfolioId;
     this.transactTime = order.transactTime;
     this.dateTime = order.dateTime;
     this.instrument = order.instrument;
     this.provider = order.provider;
     this.portfolio = order.portfolio;
     this.status = order.status;
     this.side = order.side;
     this.type = order.type;
     this.timeInForce = order.timeInForce;
     this.price = order.price;
     this.stopPx = order.stopPx;
     this.avgPx = order.avgPx;
     this.qty = order.qty;
     this.cumQty = order.cumQty;
     this.text = order.text;
     this.commands = order.commands;
     this.reports = order.reports;
     this.messages = order.messages;
 }
Exemplo n.º 44
0
 public void OnPortfolioDeleted(Portfolio portfolio)
 {
     this.OnEvent(new OnPortfolioDeleted(portfolio));
 }
Exemplo n.º 45
0
 public void UpdateGUI()
 {
   if (Framework.Current.PortfolioManager[this.name] != null)
     this.portfolio = Framework.Current.PortfolioManager[this.name];
   this.indexes = new Dictionary<string, int>();
   if (this.portfolio == null)
     return;
   this.ltvMatrix.BeginUpdate();
   this.ltvMatrix.Items.Clear();
   this.ltvMatrix.Columns.Clear();
   int count = this.portfolio.Children.Count;
   if (count > 0)
   {
     string[] items = new string[count + 1];
     List<List<TimeSeries>> list1 = new List<List<TimeSeries>>();
     for (int index1 = 0; index1 < count; ++index1)
     {
       items[index1 + 1] = this.portfolio.Children[index1].Name;
       List<TimeSeries> list2 = new List<TimeSeries>();
       list2.Add(this.GetTimeSeries(this.portfolio.Children[index1].Statistics));
       for (int index2 = 0; index2 < count; ++index2)
         list2.Add(this.GetTimeSeries(this.portfolio.Children[index2].Statistics));
       list1.Add(list2);
     }
     for (int index = 0; index < items.Length; ++index)
     {
       this.ltvMatrix.Columns.Add("");
       this.ltvMatrix.Columns[index].Width = 125;
     }
     this.ltvMatrix.Items.Add(new ListViewItem(items));
     for (int index = 0; index < list1.Count; ++index)
       this.ltvMatrix.Items.Add((ListViewItem) new CorrelationMatrixViewItem(items[index + 1], list1[index]));
   }
   this.ltvMatrix.EndUpdate();
 }
Exemplo n.º 46
0
 public OnFill(Portfolio portfolio, Fill fill)
 {
     this.portfolio = portfolio;
     this.fill = fill;
 }
Exemplo n.º 47
0
 internal PortfolioPerformance(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }
Exemplo n.º 48
0
 internal void OnParentChanged(Portfolio portfolio)
 {
     this.OnEvent(new OnPortfolioParentChanged(portfolio));
 }
Exemplo n.º 49
0
 internal PortfolioStatistics(Portfolio portfolio)
 {
     this.portfolio = portfolio;
     this.detector = new TradeDetector(TradeDetectionType.FIFO);
     this.detector.TradeDetected += new TradeInfoEventHandler(this.detector_TradeDetected);
 }
Exemplo n.º 50
0
 public void UpdateGUI()
 {
   if (this.portfolio == null)
     this.OnInit(this.name);
   this.portfolio = Framework.Current.PortfolioManager[this.name];
   if (this.portfolio == null)
     return;
   this.ltvChldStatistics.BeginUpdate();
   foreach (ListViewItem listViewItem in this.ltvChldStatistics.Items)
   {
     ChildrenStatisticsViewItem statisticsViewItem = listViewItem as ChildrenStatisticsViewItem;
     if (statisticsViewItem != null)
       statisticsViewItem.Update();
   }
   this.ltvChldStatistics.EndUpdate();
 }
Exemplo n.º 51
0
 public OnPortfolioDeleted(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }
Exemplo n.º 52
0
 internal void OnFill(Portfolio portfolio, Fill fill)
 {
     this.OnEvent(new OnFill(portfolio, fill));
 }
Exemplo n.º 53
0
		public void OnPositionOpened(Portfolio portfolio, Position position)
		{
			this.OnEvent(new OnPositionOpened(portfolio, position));
		}
Exemplo n.º 54
0
 public void OnInit(string name)
 {
   this.name = name;
   this.portfolio = Framework.Current.PortfolioManager[name];
   this.indexes = new Dictionary<string, int>();
   if (this.portfolio == null)
     return;
   this.ltvChldStatistics.BeginUpdate();
   this.ltvChldStatistics.Items.Clear();
   for (int index = 0; index < this.portfolio.Children.Count; ++index)
     this.ltvChldStatistics.Items.Add((ListViewItem) new ChildrenStatisticsViewItem(this.portfolio.Children[index]));
   this.ltvChldStatistics.EndUpdate();
 }
Exemplo n.º 55
0
		internal void OnFill(Portfolio portfolio, Fill fill)
		{
			this.OnEvent(new OnFill(portfolio, fill));
		}
Exemplo n.º 56
0
 internal void OnPositionChanged(Portfolio portfolio, Position position)
 {
     this.OnEvent(new OnPositionChanged(portfolio, position));
 }
Exemplo n.º 57
0
 internal PortfolioPerformance(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }
Exemplo n.º 58
0
 public PortfolioEventArgs(Portfolio portfolio)
 {
     this.Portfolio = portfolio;
 }
Exemplo n.º 59
0
 public PortfolioEventArgs(Portfolio portfolio)
 {
     this.Portfolio = portfolio;
 }
Exemplo n.º 60
0
 public OnPortfolioParentChanged(Portfolio portfolio)
 {
     this.portfolio = portfolio;
 }