Esempio n. 1
0
        public List <TradeDto> ToOpenCoveredCalls(List <Stock> stocks)
        {
            List <TradeDto> trades     = new List <TradeDto>();
            List <String>   tradeLines = this.Trades.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Replace("tAndroid", String.Empty).Replace("\t", " ").Replace("/", "_")).ToList();

            foreach (String tradeLine in tradeLines)
            {
                var      matches = _regexOpenCoveredCallTrade.Matches(tradeLine);
                TradeDto dto     = new TradeDto();
                dto.TradingAccountId = this.TradingAccountId;
                dto.EntryDate        = DateTime.Parse(matches[0].Groups["Date"].Value.Replace("_", "/"));
                dto.EntryPrice       = Decimal.Parse(matches[0].Groups["Price"].Value);
                dto.Size             = Int32.Parse(matches[0].Groups["Quantity"].Value) * 100;
                dto.Mark             = dto.EntryPrice;
                dto.TradeType        = TradeTypes.CoveredCall;
                dto.Classification   = TradeClassifications.Consistent;
                dto.Commissions      = Decimal.Parse(matches[0].Groups["MiscFees"].Value) + Decimal.Parse(matches[0].Groups["Commissions"].Value);
                dto.StockId          = stocks.Single(x => x.Symbol == (matches[0].Groups["Symbol"].Value)).Id;

                OptionDto optionDto = new OptionDto();
                optionDto.Expiry     = DateTime.Parse(matches[0].Groups["OptionExpiry"].Value);
                optionDto.Strike     = Decimal.Parse(matches[0].Groups["Strike"].Value);
                optionDto.Symbol     = matches[0].Groups["Symbol"].Value;
                optionDto.Name       = String.Format("{0:dd MMM yy} {1:N0}", optionDto.Expiry, optionDto.Strike);
                optionDto.OptionType = OptionTypes.Call;

                dto.CoveredCallOption = optionDto;

                trades.Add(dto);
            }

            return(trades);
        }
Esempio n. 2
0
        public List <TradeDto> ToFutureTradeDto(List <Market> markets)
        {
            List <TradeDto> trades = new List <TradeDto>();

            List <String> tradeLines = this.Trades.Split(new String[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries)
                                       .Select(x => x.Replace("tAndroid", String.Empty).Replace("KEY: Shift 4 ", String.Empty).Replace("KEY: Shift 5 ", String.Empty).Replace("\t", " ")).ToList();

            if (tradeLines == null || tradeLines.Count == 0)
            {
                return(trades);
            }

            int tradeCount = tradeLines.Count / 2;

            while (trades.Count < tradeCount)
            {
                String   openingLine  = tradeLines[0];
                String[] openingParts = openingLine.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                tradeLines.RemoveAt(0);

                int      closingIndex = tradeLines.FindIndex(x => x.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[6] == openingParts[6]);
                String   closingLine  = tradeLines[closingIndex];
                String[] closingParts = closingLine.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                tradeLines.RemoveAt(closingIndex);

                TradeDto tradeDto = new TradeDto();

                tradeDto.EntryDate = DateTime.Parse($"{openingParts[0]} {openingParts[1]}");
                Market market = markets.First(x => x.Symbol == openingParts[6].Substring(1, 2));
                tradeDto.MarketId         = market.Id;
                tradeDto.TradingAccountId = this.TradingAccountId;
                tradeDto.Timeframe        = market.MTT;
                tradeDto.Size             = Math.Abs(Int32.Parse(openingParts[5], System.Globalization.NumberStyles.Any));
                tradeDto.Classification   = TradeClassifications.Consistent;
                tradeDto.TradeType        = openingParts[4] == "BOT" ? TradeTypes.LongFuture : TradeTypes.ShortFuture;
                tradeDto.EntryPrice       = Decimal.Parse(openingParts[7].Replace("@", String.Empty).Replace("'", "."));


                tradeDto.ExitDate   = DateTime.Parse($"{closingParts[0]} {closingParts[1]}");
                tradeDto.ExitPrice  = Decimal.Parse(closingParts[7].Replace("@", String.Empty).Replace("'", "."));
                tradeDto.Mark       = tradeDto.ExitPrice;
                tradeDto.ExitReason = ((tradeDto.TradeType == TradeTypes.LongFuture && tradeDto.EntryPrice < tradeDto.ExitPrice) || (tradeDto.TradeType == TradeTypes.ShortFuture && tradeDto.EntryPrice > tradeDto.ExitPrice)) ? TradeExitReasons.TargetHit : TradeExitReasons.StopLossHit;

                if ((tradeDto.TradeType == TradeTypes.LongFuture && tradeDto.EntryPrice < tradeDto.ExitPrice) || (tradeDto.TradeType == TradeTypes.ShortFuture && tradeDto.EntryPrice > tradeDto.ExitPrice))
                {
                    tradeDto.ProfitTakerPrice = tradeDto.ExitPrice;
                }
                else
                {
                    tradeDto.StopLossPrice = tradeDto.ExitPrice;
                }

                tradeDto.Commissions = Math.Abs(Decimal.Parse(openingParts[8]) + Decimal.Parse(openingParts[9]) + Decimal.Parse(closingParts[8]) + Decimal.Parse(closingParts[9]));
                trades.Add(tradeDto);
            }

            return(trades);
        }
Esempio n. 3
0
        public void ToUpdateBullPutSpreads(List <TradeDto> trades)
        {
            List <String> statementLines = this.Trades.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Replace("tAndroid", String.Empty).Replace("\t", " ").Replace("/", "_")).ToList();

            for (int i = 0; i < statementLines.Count; i += 4)
            {
                TradeDto dto = trades.First(x => x.Stock.Symbol == statementLines[i].Trim());
                dto.ExitReason  = this.ExitReason;
                dto.Stock.Price = Decimal.Parse(statementLines[i + 1]);
                dto.BullPutSpreadLongOption.Price  = Decimal.Parse(statementLines[i + 2]);
                dto.BullPutSpreadShortOption.Price = Decimal.Parse(statementLines[i + 3]);
                dto.Mark = dto.BullPutSpreadShortOption.Price - dto.BullPutSpreadLongOption.Price;
            }
        }
Esempio n. 4
0
        public void ToUpdateCoveredCalls(List <TradeDto> trades)
        {
            List <String> statementLines = this.Trades.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Replace("tAndroid", String.Empty).Replace("\t", " ").Replace("/", "_")).ToList();

            for (int i = 0; i < statementLines.Count; i += 3)
            {
                TradeDto dto = trades.First(x => x.Stock.Symbol == statementLines[i].Trim());
                dto.ExitReason              = this.ExitReason;
                dto.Stock.Price             = Decimal.Parse(statementLines[i + 1]);
                dto.CoveredCallOption.Price = Decimal.Parse(statementLines[i + 2]);
                dto.Mark = dto.Stock.Price - dto.CoveredCallOption.Price;
                if (this.ExitCommissions > 0m)
                {
                    dto.Commissions += this.ExitCommissions;
                }
            }
        }