public void Ctor_AssignsVariables_Correctly() { var fi = new FinancialInstrument(); var prices = new IntradayPrices(null, null, null, null); var dates = DateTime.UtcNow; var dailyTb = new DailySummaryTimeBar(100, "USD", prices, 123, new Volume(123), dates); var market = new Market("1", "XLON", "London Stock Exchange", MarketTypes.DealerBooks); var equityTimeBar = new EquityInstrumentInterDayTimeBar(fi, dailyTb, dates, market); Assert.AreEqual(fi, equityTimeBar.Security); Assert.AreEqual(dailyTb, equityTimeBar.DailySummaryTimeBar); Assert.AreEqual(dates, equityTimeBar.TimeStamp); Assert.AreEqual(market, equityTimeBar.Market); }
private IUniverseEvent MapRowToInterdayMarketDataEvent(InterdayMarketDataParameters marketDataParam) { if (marketDataParam == null) { return(null); } if (string.IsNullOrWhiteSpace(marketDataParam.SecurityName) || !this._securitySelection.Securities.ContainsKey(marketDataParam.SecurityName)) { this._scenarioContext.Pending(); return(null); } var security = this._securitySelection.Securities[marketDataParam.SecurityName]; var open = this.MapToMoney(marketDataParam.Open, marketDataParam.Currency); var close = this.MapToMoney(marketDataParam.Close, marketDataParam.Currency); var high = this.MapToMoney(marketDataParam.High, marketDataParam.Currency); var low = this.MapToMoney(marketDataParam.Low, marketDataParam.Currency); var intradayPrices = new IntradayPrices(open, close, high, low); var dailySummary = new DailySummaryTimeBar( marketDataParam.MarketCap, marketDataParam.Currency, intradayPrices, marketDataParam.ListedSecurities, new Volume(marketDataParam.DailyVolume.GetValueOrDefault(0)), marketDataParam.Epoch); var marketData = new EquityInstrumentInterDayTimeBar( security.Instrument, dailySummary, marketDataParam.Epoch, security.Market); var timeBarCollection = new EquityInterDayTimeBarCollection( security.Market, marketDataParam.Epoch, new[] { marketData }); var universeEvent = new UniverseEvent( UniverseStateEvent.EquityInterDayTick, marketDataParam.Epoch, timeBarCollection); return(universeEvent); }
public void Ctor_AssignsVariables_Correctly() { var date = DateTime.UtcNow; var timeBar = new DailySummaryTimeBar( 100, "USD", new IntradayPrices(null, null, null, null), 123, new Volume(101), date); Assert.AreEqual(100, timeBar.MarketCap.Value.Value); Assert.AreEqual("USD", timeBar.MarketCap.Value.Currency.Code); Assert.AreEqual(101, timeBar.DailyVolume.Traded); Assert.AreEqual(123, timeBar.ListedSecurities); Assert.AreEqual(date, timeBar.TimeStamp); }
public EquityInstrumentIntraDayTimeBar AdvanceFrame( EquityInstrumentIntraDayTimeBar tick, DateTime advanceTick, bool walkIntraday) { if (tick == null) { return(null); } var newBuy = this.CalculateNewBuyValue(tick); var newSell = this.CalculateNewSellValue(tick, newBuy); var newVolume = this.CalculateNewVolume(tick); var newSpread = new SpreadTimeBar( new Money(newBuy, tick.SpreadTimeBar.Bid.Currency), new Money(newSell, tick.SpreadTimeBar.Ask.Currency), new Money(newBuy, tick.SpreadTimeBar.Bid.Currency), newVolume); var newMarketCap = (tick.DailySummaryTimeBar.ListedSecurities ?? tick.DailySummaryTimeBar.DailyVolume.Traded) * newBuy; var newIntraday = walkIntraday ? this.BuildIntraday(tick, newBuy, tick.SpreadTimeBar.Bid.Currency.Code) : tick.DailySummaryTimeBar.IntradayPrices ?? this.BuildIntraday( tick, newBuy, tick.SpreadTimeBar.Bid.Currency.Code); var newDaily = new DailySummaryTimeBar( newMarketCap, "USD", newIntraday, tick.DailySummaryTimeBar.ListedSecurities, tick.DailySummaryTimeBar.DailyVolume, advanceTick); return(new EquityInstrumentIntraDayTimeBar(tick.Security, newSpread, newDaily, advanceTick, tick.Market)); }
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)); }