static void Main(string[] args) { StockPrices stockPrices = new StockPrices(API_KEY); stockPrices.ChangeSymbol("MSLT"); stockPrices.GetPrices(); }
public FinancialChartViewModel() { StockPrices = StockData.GetStockPrices(); visualRange = new DateTimeRange() { VisualMin = new System.DateTime(2016, 05, 16), VisualMax = new System.DateTime(2016, 08, 7) }; }
/// <summary> /// Suspends the data updates while a given action occurs. /// </summary> /// <param name="action">The action.</param> private void SuspendDataUpdatesWhile(Action action) { StockPrices.BeginUpdate(); try { action(); } finally { StockPrices.EndUpdate(); } }
public void TestFIndMaxStockPrices() { double[] array = new double[20]; for (int i = 0; i < array.Length; i++) { array[i] = i; } array[18] = 21; StockPrices.FindMaxStockPrices(array); }
public MainViewModel(ChartView chart) { StockPrices stockPrices = StockData.GetStockPrices(); calculatedSeriesData = new CalculatedSeriesData(chart); stockSeriesData = new XYSeriesData(stockPrices, DevExpress.XamarinForms.Charts.SeriesDataType.Financial); volumeSeriesData = new XYSeriesData(stockPrices, DevExpress.XamarinForms.Charts.SeriesDataType.DateTime); visualRange = new DateTimeRange() { VisualMin = new System.DateTime(2016, 7, 29), VisualMax = new System.DateTime(2016, 10, 15) }; }
private void UpdateStockItem(StockPrice stock) { var addedStock = StockPrices.FirstOrDefault(item => item.Symbol == stock.Symbol); if (addedStock != null) { addedStock.Ask = stock.Ask; addedStock.Bid = stock.Bid; addedStock.LastTradedPrice = stock.LastTradedPrice; addedStock.TradedVolume = stock.TradedVolume; addedStock.OpenPrice = stock.OpenPrice; } }
//update stock item if exists private void UpdateStockItem(StockPrice stock) { var addedStock = StockPrices.FirstOrDefault(item => item.Symbol == stock.Symbol); if (addedStock != null) { int index = StockPrices.IndexOf(addedStock); StockPrices[index].Ask = stock.Ask; StockPrices[index].Bid = stock.Bid; StockPrices[index].LastTradedPrice = stock.LastTradedPrice; StockPrices[index].TradedVolume = stock.TradedVolume; StockPrices[index].OpenPrice = stock.OpenPrice; StockPrices[index].TimeStamp = DateTime.Now; } }
//Add stock to collection if exists else update the collection private void AddOrUpdateStockPriceCollection(List <StockPrice> stockPriceList) { if (stockPriceList.Any()) { foreach (var stock in stockPriceList) { if (StockPrices.Any(item => item.Symbol == stock.Symbol)) { UpdateStockItem(stock); } else { StockPrices.Add(stock); } } } }
public void BuildPortfolio_MissingPriceForTargetSymbol_ThrowsArgumentException() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var targetWeights = new StockWeights { { "TLV", 0.21m }, { "FP", 0.3m } }; var builder = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(100); Assert.Throws <ArgumentException>(() => builder.Build()); }
public void BuildPortfolio_SumOfTargetWeightApproxEqualWithOneHundredPercent_DoesNotThrow() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var targetWeights = new StockWeights { { "TLV", 0.21m }, { "FP", 0.3m }, { "EL", 0.5m } }; var builder = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(100); Assert.DoesNotThrow(() => builder.Build()); }
public void BuildPortfolio_AtLeastOneTargetWeightAboveAboveOneHundredPercent_ThrowsArgumentException() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var targetWeights = new StockWeights { { "TLV", 1.2m }, { "FP", 0.3m }, { "EL", 0.5m } }; var builder = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(100); Assert.Throws <ArgumentException>(() => builder.Build()); }
public void BuildPortfolio_InitialStocks_EnoughAvailableAmount_NewStocksAreAdded() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var stocks = new[] { new Stock("TLV") { Count = 2, Price = 10, Weight = 0.2m }, // should add 2 new Stock("FP") { Count = 1, Price = 20, Weight = 0.2m }, // should add 3 new Stock("EL") { Count = 2, Price = 30, Weight = 0.6m } // should add 2 }; var targetWeights = new StockWeights { { "TLV", 0.2m }, { "FP", 0.3m }, { "EL", 0.5m } }; // target stock 4 * TLV + 4 * FP + 4 * EL = 240 var portfolio = new PortfolioBuilder() .UsePrices(prices) .UseStocks(stocks) .UseWeightAdjustmentStrategy(new FollowTargetAdjustmentStrategy()) .UseTargetWeights(targetWeights) .UseToBuyAmount(140) .Build(); Assert.AreEqual(4, portfolio["EL"].Count); Assert.AreEqual(4, portfolio["FP"].Count); Assert.AreEqual(4, portfolio["TLV"].Count); Assert.AreEqual(240, portfolio.TotalValue); }
public void BuildPortfolio_NotEnoughForAny_PortfolioValueIsZero() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 } }; var targetWeights = new StockWeights { { "TLV", 0.5m }, { "FP", 0.5m } }; var portfolio = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(9) .Build(); Assert.Zero(portfolio.TotalValue); }
/// <summary> /// Updates the live data. /// </summary> private void UpdateLiveData() { SuspendDataUpdatesWhile(() => { for (int i = 0; i < 6; i++) { StockPrices.RemoveAt(0); } PriceData lastStockData; for (int i = 0; i < 6; i++) { lastStockData = StockPrices.Last(); DateTime stockDate = lastStockData.Date.Add(StockUpdateTimeSpan); decimal stockPrice = GetRandomStockPriceNear(lastStockData.Price); StockPrices.Add(new PriceData(stockPrice, stockDate)); } CurrentPrice = StockPrices.Last(); }); }
public void BuildPortfolio_NotEnoughForAll_PortfolioValueIsCorrect() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 } }; var targetWeights = new StockWeights { { "TLV", 0.5m }, { "FP", 0.5m } }; var portfolio = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(20) .Build(); Assert.AreEqual(10, portfolio.TotalValue); }
public void BuildPortfolio_MinOrderValueIsSet_StockTotalValueLessThanMinimal_StockIsNotAddedToPortfolio() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var targetWeights = new StockWeights { { "TLV", 0.2m }, { "FP", 0.3m }, { "EL", 0.5m } }; var portfolio = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(140) .UseMinOrderValue(31) .Build(); Assert.IsFalse(portfolio.Any(s => s.Symbol == "TLV")); }
/// <summary> /// Initializes the sample data. /// </summary> protected void InitializeSampleData() { StockPrices.Clear(); DateTime now = DateTime.Now; now = now.AddMinutes(-(now.Minute % 30)); DateTime lastStockDate = now; decimal lastStockValue = GetRandomStockPrice(); var lastStockData = new PriceData(lastStockValue, lastStockDate); for (int i = 0; i < 61; i++) { StockPrices.Insert(0, lastStockData); lastStockDate = lastStockDate.Subtract(StockUpdateTimeSpan); lastStockValue = GetRandomStockPriceNear(lastStockValue); lastStockData = new PriceData(lastStockValue, lastStockDate); } YesterdayPrice = StockPrices.First(); CurrentPrice = StockPrices.Last(); CalculateChange(); }
public void BuildPortfolio_AlmostEnoughForAll_SmallestEligibleStockIsDecreased() { var prices = new StockPrices { { "TLV", 10 }, { "FP", 20 }, { "EL", 30 } }; var targetWeights = new StockWeights { { "TLV", 0.2m }, { "FP", 0.3m }, { "EL", 0.5m } }; var portfolio = new PortfolioBuilder() .UsePrices(prices) .UseTargetWeights(targetWeights) .UseToBuyAmount(119) .Build(); Assert.AreEqual(2, portfolio["EL"].Count); Assert.AreEqual(2, portfolio["FP"].Count); Assert.AreEqual(1, portfolio["TLV"].Count); Assert.AreEqual(110, portfolio.TotalValue); }
public GetStockPriceForAsync_StateMachine(StockPrices @this, string companyId) { this.@this = @this; _companyId = companyId; }
public XYSeriesData(StockPrices stockPrices, SeriesDataType seriesDataType) { this.stockPrices = stockPrices; this.seriesDataType = seriesDataType; }