Ejemplo n.º 1
0
 public OptionPortfolio(OptionPortfolio original)
 {
     Cash = original.Cash;
     CopyPositions(original);
     Fee       = original.Fee;
     Slippage  = original.Slippage;
     TradeMade = original.TradeMade;
 }
Ejemplo n.º 2
0
 public void Start(double cash, DateTime startDate, Stock stock)
 {
     _simDate = startDate;
     ChangeStock(stock);
     _portfolio            = new OptionPortfolio(cash, 1.1, 0.04);
     _portfolio.TradeMade += new EventHandler(FireTradeMade);
     _portofolioHistory    = new List <OptionPortfolio>();
 }
Ejemplo n.º 3
0
 private void CopyPositions(OptionPortfolio original)
 {
     Positions = new List <OptionPosition>();
     foreach (OptionPosition pos in original.Positions)
     {
         OptionPosition newPos = new OptionPosition()
         {
             Amount    = pos.Amount,
             Spread    = pos.Spread,
             EntryDate = pos.EntryDate
         };
         Positions.Add(newPos);
     }
 }
Ejemplo n.º 4
0
        public async void RollBackOneDay()
        {
            if (_portofolioHistory.Count > 0)
            {
                _dataIndex--;
                TimeSpan  updateSpan = DateTime.UtcNow - _simDate;
                StockData stockData  = await StockDataBase.Get(Stock, Api.Interval.Daily, updateSpan);

                if (_dataIndex >= 0)
                {
                    _simDate = stockData.TimeSeries.DataPoints[_dataIndex].DateTime;

                    ChangeStock(Stock);
                    _portfolio = new OptionPortfolio(_portofolioHistory[_portofolioHistory.Count - 1]);
                    _portofolioHistory.RemoveAt(_portofolioHistory.Count - 1);
                    NextDaySimulated?.Invoke(this, new EventArgs());
                }
            }
        }
Ejemplo n.º 5
0
        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);
                }
            }
        }