private void UpdateLableStockData(int mouseX, int mouseY) { if (Linked) { if (_chart.StockData != null) { StockDataPoint mouseDataPoint = _chart.PickStockData(mouseX); if (ShowCandleDate) { labelStockData.Text = "Date : " + mouseDataPoint.DateTime.ToString("dddd dd MMMM yyyy"); } else { labelStockData.Text = "Date : " + mouseDataPoint.DateTime.ToString("dddd dd MMMM"); } labelStockData.Text += "\nOpen : " + mouseDataPoint.Open.ToString() + "\nClose : " + mouseDataPoint.Close.ToString() + "\nVolume : " + mouseDataPoint.Volume.ToString(); labelStockData.Location = new Point(pictureBoxRender.Width - labelStockData.Width - 10, labelStockData.Location.Y); if (_chart.Graphs.Count > 0) { foreach (GraphData graph in _chart.Graphs) { int graphIndex = graph.FindDateIndex(mouseDataPoint.DateTime); GraphDataPoint graphDataPoint = graph.DataPoints[graphIndex]; labelGraphData.Text = "Date : " + graphDataPoint.DateTime.ToShortDateString() + "\nValue : " + graphDataPoint.GraphData.ToString(); labelGraphData.Location = new Point(pictureBoxRender.Width - labelGraphData.Width - 10, labelGraphData.Location.Y); } } } } }
public async static Task <GraphData> PriceGraph(DateTime openDate, Option option) { StockData data = await StockDataBase.Get(option.Stock, Api.Interval.Daily); int startIndex = data.FindDateIndex(openDate); int endIndex = data.FindDateIndex(option.ExpirationDate); GraphData graph = new GraphData("PriceGraph " + option.Stock.StockSymbol + " " + option.Strike.ToString() + option.OptionType.ToString()); for (int i = startIndex; i <= endIndex; i++) { DateTime dataPointDate = data.TimeSeries.DataPoints[i].DateTime; Option opt = Option.GetOption(option.Stock, option.OptionType, option.PositionType, option.Strike, option.ExpirationDate, dataPointDate); double price = await opt.Price(dataPointDate); GraphDataPoint point = new GraphDataPoint(dataPointDate, price); graph.DataPoints.Add(point); } return(graph); }
public async void Run(OptionTradeList tradeList) { if (tradeList != null && tradeList.Trades.Count > 0) { //find DataRange StockData firstData = await StockDataBase.Get(tradeList.Stock, 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 OptionPortfolio portfolio = new OptionPortfolio(_startBalance, _fee, _slippage); _balanceChart = new GraphData(_name + " Balance"); for (int i = startIndex; i <= stopIndex; i++) { foreach (OptionTrade trade in tradeList.Trades) { int dateIndex = firstData.FindDateIndex(trade.TradeDate); if (dateIndex == i) { portfolio.MakeTrade(trade, tradeList.Interval); } } DateTime date = firstData.TimeSeries.DataPoints[i].DateTime; GraphDataPoint balanceGraphDataPoint = new GraphDataPoint(date, await portfolio.TotalBalance(date, tradeList.Interval)); _balanceChart.DataPoints.Add(balanceGraphDataPoint); } } }