示例#1
0
 private SpreadTimeBar BuildSpread(
     FinancialInstrumentTimeBarCsv csv,
     decimal spreadAsk,
     decimal spreadBid,
     decimal spreadPrice,
     Volume spreadVolume)
 {
     return(new SpreadTimeBar(
                new Money(spreadAsk, csv.Currency),
                new Money(spreadBid, csv.Currency),
                new Money(spreadPrice, csv.Currency),
                spreadVolume));
 }
示例#2
0
        private IntradayPrices BuildIntradayPrices(
            FinancialInstrumentTimeBarCsv csv,
            decimal open,
            decimal close,
            decimal high,
            decimal low)
        {
            var openPrice = open != 0 ? new Money(open, csv.Currency) : (Money?)null;

            var closePrice = close != 0 ? new Money(close, csv.Currency) : (Money?)null;

            var highPrice = high != 0 ? new Money(high, csv.Currency) : (Money?)null;

            var lowPrice = low != 0 ? new Money(low, csv.Currency) : (Money?)null;

            var intradayPrices = new IntradayPrices(openPrice, closePrice, highPrice, lowPrice);

            return(intradayPrices);
        }
示例#3
0
 private FinancialInstrument BuildSecurity(FinancialInstrumentTimeBarCsv csv)
 {
     return(new FinancialInstrument(
                InstrumentTypes.Equity,
                new InstrumentIdentifiers(
                    string.Empty,
                    string.Empty,
                    null,
                    csv.SecurityClientIdentifier,
                    csv.Sedol,
                    csv.Isin,
                    csv.Figi,
                    csv.Cusip,
                    csv.ExchangeSymbol,
                    csv.Lei,
                    csv.BloombergTicker,
                    csv.Ric),
                csv.SecurityName,
                csv.Cfi,
                csv.Currency,
                csv.IssuerIdentifier));
 }
        public FinancialInstrumentTimeBarCsv Map(EquityInstrumentIntraDayTimeBar equityInstrumentIntraDayTimeBar)
        {
            if (equityInstrumentIntraDayTimeBar == null)
            {
                this.FailedMapTotal += 1;
                this._logger?.LogError(
                    "Failed to map security tick to financial instrument time bar csv due to being passed a null value");
                return(null);
            }

            var financialInstrumentTimeBarCsv = new FinancialInstrumentTimeBarCsv
            {
                Volume =
                    equityInstrumentIntraDayTimeBar.SpreadTimeBar.Volume.Traded
                    .ToString(),
                DailyVolume =
                    equityInstrumentIntraDayTimeBar.DailySummaryTimeBar
                    .DailyVolume.Traded.ToString(),
                Timestamp =
                    equityInstrumentIntraDayTimeBar.TimeStamp.ToString(
                        "yyyy-MM-ddTHH:mm:ss"),
                MarketCap =
                    equityInstrumentIntraDayTimeBar.DailySummaryTimeBar
                    .MarketCap?.ToString(),
                ListedSecurities =
                    equityInstrumentIntraDayTimeBar.DailySummaryTimeBar
                    .ListedSecurities?.ToString(),
                Currency = equityInstrumentIntraDayTimeBar.SpreadTimeBar.Price
                           .Currency.Code,

                // Spread
                Ask = equityInstrumentIntraDayTimeBar.SpreadTimeBar.Ask.Value
                      .ToString(),
                Bid = equityInstrumentIntraDayTimeBar.SpreadTimeBar.Bid.Value
                      .ToString(),
                Price = equityInstrumentIntraDayTimeBar.SpreadTimeBar.Price
                        .Value.ToString()
            };

            // Market
            if (equityInstrumentIntraDayTimeBar.Market != null)
            {
                financialInstrumentTimeBarCsv.MarketIdentifierCode =
                    equityInstrumentIntraDayTimeBar.Market.MarketIdentifierCode;
                financialInstrumentTimeBarCsv.MarketName = equityInstrumentIntraDayTimeBar.Market.Name;
            }

            // Intraday Prices
            if (equityInstrumentIntraDayTimeBar.DailySummaryTimeBar.IntradayPrices != null)
            {
                financialInstrumentTimeBarCsv.Open = equityInstrumentIntraDayTimeBar.DailySummaryTimeBar.IntradayPrices
                                                     .Open?.Value.ToString();
                financialInstrumentTimeBarCsv.Close = equityInstrumentIntraDayTimeBar.DailySummaryTimeBar.IntradayPrices
                                                      .Close?.Value.ToString();
                financialInstrumentTimeBarCsv.Low = equityInstrumentIntraDayTimeBar.DailySummaryTimeBar.IntradayPrices
                                                    .Low?.Value.ToString();
                financialInstrumentTimeBarCsv.High = equityInstrumentIntraDayTimeBar.DailySummaryTimeBar.IntradayPrices
                                                     .High?.Value.ToString();
            }

            // Security Identifiers
            if (equityInstrumentIntraDayTimeBar.Security != null)
            {
                // Security
                financialInstrumentTimeBarCsv.SecurityName     = equityInstrumentIntraDayTimeBar.Security.Name;
                financialInstrumentTimeBarCsv.Cfi              = equityInstrumentIntraDayTimeBar.Security.Cfi;
                financialInstrumentTimeBarCsv.IssuerIdentifier =
                    equityInstrumentIntraDayTimeBar.Security.IssuerIdentifier;

                // Security Identifiers
                financialInstrumentTimeBarCsv.SecurityClientIdentifier =
                    equityInstrumentIntraDayTimeBar.Security.Identifiers.ClientIdentifier;
                financialInstrumentTimeBarCsv.Sedol          = equityInstrumentIntraDayTimeBar.Security.Identifiers.Sedol;
                financialInstrumentTimeBarCsv.Isin           = equityInstrumentIntraDayTimeBar.Security.Identifiers.Isin;
                financialInstrumentTimeBarCsv.Figi           = equityInstrumentIntraDayTimeBar.Security.Identifiers.Figi;
                financialInstrumentTimeBarCsv.Cusip          = equityInstrumentIntraDayTimeBar.Security.Identifiers.Cusip;
                financialInstrumentTimeBarCsv.ExchangeSymbol =
                    equityInstrumentIntraDayTimeBar.Security.Identifiers.ExchangeSymbol;
                financialInstrumentTimeBarCsv.Lei             = equityInstrumentIntraDayTimeBar.Security.Identifiers.Lei;
                financialInstrumentTimeBarCsv.BloombergTicker =
                    equityInstrumentIntraDayTimeBar.Security.Identifiers.BloombergTicker;
            }

            return(financialInstrumentTimeBarCsv);
        }
示例#5
0
        public EquityInstrumentIntraDayTimeBar Map(FinancialInstrumentTimeBarCsv csv)
        {
            if (csv == null)
            {
                this.FailedParseTotal += 1;
                this._logger?.LogError("Failed to parse security tick csv due to being passed a null value");
                return(null);
            }

            var failedRead = false;

            if (!int.TryParse(csv.Volume, out var volume))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable volume {csv.Volume} for row {csv.RowId}");
                failedRead = true;
            }

            if (!int.TryParse(csv.DailyVolume, out var dailyVolume))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable daily volume {csv.DailyVolume} for row {csv.RowId}");
                failedRead = true;
            }

            if (!DateTime.TryParse(csv.Timestamp, out var timeStamp))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable timestamp {csv.Timestamp} for row {csv.RowId}");
                failedRead = true;
            }

            decimal marketCap = 0;

            if (!string.IsNullOrWhiteSpace(csv.MarketCap) && !decimal.TryParse(csv.MarketCap, out marketCap))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable market cap {csv.MarketCap} for row {csv.RowId}");
                failedRead = true;
            }

            decimal spreadAsk = 0;

            if (!string.IsNullOrWhiteSpace(csv.Ask) && !decimal.TryParse(csv.Ask, out spreadAsk))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable spread ask price {csv.Ask} for row {csv.RowId}");
                failedRead = true;
            }

            decimal spreadBid = 0;

            if (!string.IsNullOrWhiteSpace(csv.Bid) && !decimal.TryParse(csv.Bid, out spreadBid))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable spread bid price {csv.Bid} for row {csv.RowId}");
                failedRead = true;
            }

            decimal spreadPrice = 0;

            if (!string.IsNullOrWhiteSpace(csv.Price) && !decimal.TryParse(csv.Price, out spreadPrice))
            {
                this._logger?.LogError(
                    $"Failed to parse security tick csv due to being passed an unparseable spread price {csv.Price} for row {csv.RowId}");
                failedRead = true;
            }

            var listedSecurities = 0;

            if (!string.IsNullOrWhiteSpace(csv.ListedSecurities) &&
                !int.TryParse(csv.ListedSecurities, out listedSecurities))
            {
                this._logger?.LogError(
                    $"Failed to parse listed securities due to being passed an unparseable listed security {csv.ListedSecurities} for row {csv.RowId}");
                failedRead = true;
            }

            decimal open = 0;

            if (!string.IsNullOrWhiteSpace(csv.Open) && !decimal.TryParse(csv.Open, out open))
            {
                this._logger?.LogError(
                    $"Failed to parse open price due to being passed an unparseable price {csv.Open} for row {csv.RowId}");
                failedRead = true;
            }

            decimal close = 0;

            if (!string.IsNullOrWhiteSpace(csv.Close) && !decimal.TryParse(csv.Close, out close))
            {
                this._logger?.LogError(
                    $"Failed to parse close price due to being passed an unparseable price {csv.Close} for row {csv.RowId}");
                failedRead = true;
            }

            decimal high = 0;

            if (!string.IsNullOrWhiteSpace(csv.High) && !decimal.TryParse(csv.High, out high))
            {
                this._logger?.LogError(
                    $"Failed to parse high price due to being passed an unparseable price {csv.High} for row {csv.RowId}");
                failedRead = true;
            }

            decimal low = 0;

            if (!string.IsNullOrWhiteSpace(csv.Low) && !decimal.TryParse(csv.Low, out low))
            {
                this._logger?.LogError(
                    $"Failed to parse low price due to being passed an unparseable price {csv.Low} for row {csv.RowId}");
                failedRead = true;
            }

            if (failedRead)
            {
                this.FailedParseTotal += 1;
                return(null);
            }

            var security       = this.BuildSecurity(csv);
            var spread         = this.BuildSpread(csv, spreadAsk, spreadBid, spreadPrice, new Volume(volume));
            var intradayPrices = this.BuildIntradayPrices(csv, open, close, high, low);
            var dailySummary   = new DailySummaryTimeBar(
                marketCap,
                csv.Currency,
                intradayPrices,
                listedSecurities,
                new Volume(dailyVolume),
                timeStamp);
            var market = new Market(string.Empty, csv.MarketIdentifierCode, csv.MarketName, MarketTypes.STOCKEXCHANGE);

            return(new EquityInstrumentIntraDayTimeBar(security, spread, dailySummary, timeStamp, market));
        }