コード例 #1
0
 public void Add(StockList list)
 {
     if (list != null && !Contains(list.Name))
     {
         _stockLists.Add(list);
     }
 }
コード例 #2
0
        public static void Initialize()
        {
            _watchLists = new WatchLists();
            _watchLists.Load();
            _watchLists.Remove("RecentlyUsed");

            _recentList = new StockList("RecentlyUsed");
            _recentList.Load("RecentlyUsed.json");
        }
コード例 #3
0
        private void FillListBoxRecent()
        {
            StockList list = WatchListManager.RecentList;

            listBoxRecent.Items.Clear();
            if (list != null)
            {
                listBoxRecent.Items.AddRange(list.Stocks);
            }
        }
コード例 #4
0
        public static void AddNewList(string listName)
        {
            StockList list = new StockList(listName);

            _watchLists.Add(list);

            if (ListChanged != null)
            {
                ListChanged();
            }
        }
コード例 #5
0
        private void FillListBoxWatchList()
        {
            string selected = "";

            if (_activeWatchList != null)
            {
                selected = _activeWatchList;
            }
            StockList list = WatchListManager.GetList(selected);

            listBoxWatchList.Items.Clear();
            if (list != null)
            {
                listBoxWatchList.Items.AddRange(list.Stocks);
            }
        }
コード例 #6
0
        public void Load()
        {
            string listDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DataMAN\\WatchLists";

            if (Directory.Exists(listDirectory))
            {
                foreach (string file in Directory.GetFiles(listDirectory))
                {
                    FileInfo fileInfo = new FileInfo(file);
                    if (fileInfo.Extension == ".json")
                    {
                        StockList stockList = new StockList(fileInfo.Name);
                        stockList.Load(fileInfo.Name);
                        _stockLists.Add(stockList);
                    }
                }
            }
        }
コード例 #7
0
        public async void Run(StockTradeList tradeList)
        {
            if (tradeList != null && tradeList.Trades.Count > 0)
            {
                //find all stocks traded
                StockList stocks = new StockList("TradeList");
                foreach (StockTrade trade in tradeList.Trades)
                {
                    stocks.Add(trade.Stock);
                }

                //find DataRange
                StockData firstData = await StockDataBase.Get(stocks.GetStock(0), tradeList.Interval);

                int startIndex = firstData.FindDateIndex(_startDate);
                int stopIndex  = firstData.FindDateIndex(_endDate);
                int dataCount  = firstData.TimeSeries.DataPoints.Count;

                if (stopIndex == 0)
                {
                    stopIndex = dataCount - 1;
                }

                //Simulate trades
                double         startBalance     = _balanceChart[0];
                StockPortfolio portfolio        = new StockPortfolio(startBalance);
                List <double>  balanceChartList = new List <double>();
                balanceChartList.Add(startBalance);

                for (int i = startIndex; i <= stopIndex; i++)
                {
                    foreach (StockTrade trade in tradeList.Trades)
                    {
                        if (trade.DataIndex == i)
                        {
                            portfolio.MakeTrade(trade, tradeList.Interval);
                        }
                    }
                    balanceChartList.Add(await portfolio.TotalBalance(i, tradeList.Interval));
                }
                _balanceChart = balanceChartList.ToArray();
            }
        }
コード例 #8
0
        public async void Load(Panel controlPanel, Panel variablePanel)
        {
            panelControl  = controlPanel;
            panelVariable = variablePanel;
            string dataBasePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DataMAN\\Financial data\\Options\\HistoricalOptionData";
            string listName     = "Historical Data";

            /*WatchListManager.AddNewList(listName);
             * foreach (string stockFolder in Directory.GetDirectories(dataBasePath))
             * {
             *  DirectoryInfo dInfo = new DirectoryInfo(stockFolder);
             *  string symbol = dInfo.Name;
             *  Stock stock = new Stock(symbol);
             *  WatchListManager.AddToList(listName, stock);
             * }*/
            if (MessageBox.Show("ready") == DialogResult.OK)
            {
                StockList list = WatchListManager.GetList("Historical Data");
                foreach (string symbol in list.Stocks)
                {
                    Stock     stock = new Stock(symbol);
                    StockData data  = await StockDataBase.Get(stock, Api.Interval.Daily, TimeSpan.FromDays(200));

                    DateTime lastRefeshed;
                    try
                    {
                        lastRefeshed = DateTime.Parse(data.MetaData.LastRefreshed);
                    }
                    catch
                    {
                        lastRefeshed = DateTime.MinValue;
                    }

                    if (DateTime.UtcNow - lastRefeshed < TimeSpan.FromMinutes(10))
                    {
                        Thread.Sleep(new TimeSpan(0, 0, 25));
                    }
                }
                MessageBox.Show("Done");
            }
        }
コード例 #9
0
 public void Remove(StockList list)
 {
     Remove(list.Name);
 }
コード例 #10
0
        public async void Run(StockTradeList tradeList)
        {
            if (tradeList != null && tradeList.Trades.Count > 0)
            {
                //find all stocks traded
                StockList stocks = new StockList("TradeList");
                foreach (StockTrade trade in tradeList.Trades)
                {
                    stocks.Add(trade.Stock);
                }

                //find DataRange
                StockData firstData = await StockDataBase.Get(stocks.GetStock(0), tradeList.Interval);

                int startIndex = firstData.FindDateIndex(_startDate);
                int stopIndex  = firstData.FindDateIndex(_endDate);
                int dataCount  = firstData.TimeSeries.DataPoints.Count;

                if (stopIndex == 0)
                {
                    stopIndex = dataCount - 1;
                }

                //Simulate trades
                double     timesTraded  = 0;
                double     timesRight   = 0;
                StockTrade currentTrade = new StockTrade();
                StockData  data         = firstData;
                for (int i = startIndex; i <= stopIndex; i++)
                {
                    foreach (StockTrade trade in tradeList.Trades)
                    {
                        if (trade.DataIndex == i)
                        {
                            if (trade.PortfolioPercentage > 0)
                            {
                                data = await StockDataBase.Get(trade.Stock, tradeList.Interval);

                                currentTrade = trade;
                            }
                            else
                            {
                                timesTraded++;
                                double openPrice  = data.TimeSeries.DataPoints[currentTrade.DataIndex].Close;
                                double closePrice = data.TimeSeries.DataPoints[i].Close;

                                if (currentTrade.Type == StockTradeType.LongStock && closePrice > openPrice)
                                {
                                    timesRight++;
                                }
                                if (currentTrade.Type == StockTradeType.ShortStock && closePrice < openPrice)
                                {
                                    timesRight++;
                                }
                            }
                        }
                    }
                }

                //save results
                _rightPredictPercentage = timesRight / timesTraded;
                _tradesMade             = (int)timesTraded;
            }
        }