static void Main(string[] args) { string sourceFilePath = @"..\..\..\..\Files\StockPositions1.csv"; string destinationFilePath = @"..\..\..\..\Files\Result.csv"; StockAnalyzer analyzer = new StockAnalyzer(); analyzer.Process(sourceFilePath, destinationFilePath); }
public void TestMethod1() { IStockFeed feed = new ClassLibrary1.Fakes.StubIStockFeed() { GetStockPriceString = (code) => { return(100); } }; var price = new StockAnalyzer().GetMsftStockPrice(feed); Assert.AreEqual(100, price, "price is expected 100"); }
private StockAnalyzer GetStockAnalyzer(string symbol) { StockAnalyzer stAny = stAnalyzerList.Find(item => item.Symbol == symbol); if (stAny == null) { stAny = new StockAnalyzer(symbol); stAnalyzerList.Add(stAny); } return(stAny); }
public void SimpleStubTestingNotEssential() { IStockFeed stockFeed = new Library.Fakes.StubIStockFeed() { GetSharePriceString = (company) => { return(1234); } }; var componentUnderTest = new StockAnalyzer(stockFeed); int actualValue = componentUnderTest.GetContosoPrice(); Assert.AreEqual(1234, actualValue); }
static void Main(string[] args) { //Inizializza interprete e imposta la teoria SolveInfo si; InputStream ins = new FileInputStream("../../../prolog/adapterTheory.pl"); Theory t = new Theory(ins); Prolog engine = new Prolog(); engine.setTheory(t); engine.addExceptionListener(new MyExcptioListener()); engine.addOutputListener(new MyOutputListener()); engine.addSpyListener(new MySpyListener()); //Richiede all'utente quale azioni analizzare List <String> stocks = new List <string>(); String str; System.Console.WriteLine("The program downloads the history of prices of a bunch of stocks, then upload an analysis on a MySQL database");//TODO do { System.Console.WriteLine("Write a stock name(e.g. msft, goog) to add a stock to analyze or return to finish"); str = System.Console.ReadLine(); if (str.Length != 0) { stocks.Add(str); } } while (str.Length != 0); //Richoede il periodo d'analisi System.Console.WriteLine("Insert Days of the Analysis"); str = System.Console.ReadLine(); int days = Int32.Parse(str); System.Console.WriteLine("Wait please..."); //Usa il metodo factory (F#) per ottenere gli StockAnalyzer var analyzers = StockAnalyzer.GetAnalyzers(stocks, days); IEnumerator <StockAnalyzer> ie = analyzers.GetEnumerator(); //Inserisce nel database gli StockAnalyzer usando l'inteprete tuProlog.NET for (int i = 0; i < stocks.Count; i++) { ie.MoveNext(); str = stocks[i] + ";" + ie.Current.ToString; System.Console.WriteLine(str); si = engine.solve("addStockAnalysis('" + str + "',RS)."); if (("" + si.getVarValue("RS")) == "0") { System.Console.WriteLine("Tuple added"); } else if (("" + si.getVarValue("RS")) == "1") { System.Console.WriteLine("Tuple already presents"); } } }
static void Main(string[] args) { //string sourceFilePath = @"..\..\..\..\Files\StockPositions1.csv"; //string sourceFilePath = @"..\..\..\..\Files\StockPositions2.json"; string sourceFilePath = @"http://solid.wincubate.net/stockpositions.json"; //string destinationFilePath = @"..\..\..\..\Files\Result.csv"; string destinationFilePath = @"..\..\..\..\Files\Result.json"; StockAnalyzer analyzer = new StockAnalyzer(); analyzer.Process(); }
public void TestContosoStockPrice() { //Arrange: //Create the fake stockFeed: IStockFeed stockFeed = new frame1.Fakes.StubIStockFeed() { GetSharePriceString = (company) => { return(1234); } }; var componentUnderTest = new StockAnalyzer(stockFeed); int actualValue = componentUnderTest.GetContosoPrice(); Assert.AreEqual(1234, actualValue); }
private void ProcessOffsetTrade() { this.StockObject.TradeList = ExchangeObject.GetOpenTrades(this.StockObject.Symbol, CurrentAccount.Id).ToList(); thisAnalyzer = GetStockAnalyzer(this.StockObject.Symbol); if (this.StockObject.TradeList.Count > 1) { if (thisAnalyzer.OffSetAnalyzer.IsSellOffsetMet) { int previousIndex = thisAnalyzer.OffSetAnalyzer.LastOffsetMetIndex; int currentIndex = GetOffsetIndexStatus(thisAnalyzer.OffSetAnalyzer.LastOffsetMetIndex); if (currentIndex < previousIndex) { this.FxStock = (ForexData)this.StockObject.TradeList[previousIndex]; if (this.FxStock.UnrealizedPL < 0.15m) { CloseTrades(thisAnalyzer.OffSetAnalyzer.LastOffsetMetIndex); } } } else { GetOffsetIndexStatus(0); } this.FxStock = (ForexData)this.StockObject.TradeList[0]; if (thisAnalyzer.OffSetAnalyzer.LastProfitValue > 0.10m) { if (this.FxStock.UnrealizedPL > 0.10m) { decimal diffIndex = thisAnalyzer.OffSetAnalyzer.LastProfitValue - this.FxStock.UnrealizedPL; if (diffIndex > 0.03m) { if (thisAnalyzer.OffSetAnalyzer.OffsetMetDiffIndex > 2 || thisAnalyzer.OffSetAnalyzer.LastTradeTimeDiff.Minutes > 30 || thisAnalyzer.OffSetAnalyzer.LastTradeTimeDiff.Hours >= 1) { CloseTrade(0); } else { thisAnalyzer.OffSetAnalyzer.OffsetMetDiffIndex++; } } } } thisAnalyzer.OffSetAnalyzer.LastProfitValue = this.FxStock.UnrealizedPL; } }
public void TestVariableContosoPrice() { //Arrange: int priceToReturn = 345; string companyCodeUsed = string.Empty; var componentUnderTest = new StockAnalyzer(new frame1.Fakes.StubIStockFeed() { GetSharePriceString = (company) => { companyCodeUsed = company; return(priceToReturn); } }); int actualResult = componentUnderTest.GetContosoPrice(); Assert.AreEqual(priceToReturn, actualResult); Assert.AreEqual("C000", companyCodeUsed); }
static void Main(string[] args) { //string sourceFilePath = @"..\..\..\..\Files\StockPositions1.csv"; //string sourceFilePath = @"..\..\..\..\Files\StockPositions2.json"; //string sourceFilePath = @"http://solid.wincubate.net/stockpositions.json"; //string destinationFilePath = @"..\..\..\..\Files\Result.csv"; //string destinationFilePath = @"..\..\..\..\Files\Result.json"; //_writeStorage = new FileStorage( @"..\..\..\..\Files\StockPositions1.csv",@"..\..\..\..\Files\Result.json" ); //_storage = new FileStorage(); //_parser = new Parser(); //_serializer = new CsvSerializer(); IReadStorage readStorage = new WebStorage(@"http://solid.wincubate.net/stockpositions.json"); IWriteStorage writeStorage = new ConsoleStorage(); Parser parser = new JsonParser(); ISerializer serializer = new JsonSerializer(); StockAnalyzer analyzer = new StockAnalyzer( readStorage, writeStorage, parser, serializer ); analyzer.Process(); }
public static void ScanStocks() { //Log.Error(typeof(CollectDataManager), "Test 1"); //Log.Error(typeof(CollectDataManager),"Test tets"); //Log.Error(typeof(CollectDataManager), "Test tets 123", new Exception("Failed to test")); var engine = new YahooStockEngine(); var quoteList = new ObservableCollection <Quote>(); var boList = new List <CompanyList>(); using (var db = new TheFishEntities()) { boList = db.CompanyLists.Where(x => x.Sector.Equals("Health care", StringComparison.OrdinalIgnoreCase) && x.Symbol.Length < 5).ToList(); } int i = 1; var quoteSingleCollectionChunk = new List <Quote>(); foreach (var item in boList) { //if (i > 2) // break; try { var quote = new Quote(item.Symbol.Trim()); quoteSingleCollectionChunk.Add(quote); if (i == StockFetchTrunk) { YahooStockEngine.Fetch(quoteSingleCollectionChunk); //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk); foreach (var stockInfo in quoteSingleCollectionChunk) { quoteList.Add(stockInfo); } quoteSingleCollectionChunk = new List <Quote>(); i = 1; } i++; }catch (Exception ex) { var message = ex.Message; } //i++; } try { if (quoteSingleCollectionChunk.Count > 0) { YahooStockEngine.Fetch(quoteSingleCollectionChunk); //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk); foreach (var stockInfo in quoteSingleCollectionChunk) { quoteList.Add(stockInfo); } } }catch (Exception ex) { var message = ex.Message; } DateTime today = DateTime.Today; // earliest time today DateTime tomorrow = DateTime.Today.AddDays(1); // earliest time tomorrow using (var db = new TheFishEntities()) { foreach (var item in quoteList.ToList()) { try { var result = StockAnalyzer.AnalyzeStock(item); var isPriceChangeFish = result.IsPriceChangedDramatically; var isVolumeChangeFish = result.IsVolumeAbnormal; var isPrice52WeeksLow = result.IsPrice52WeeksLow; if (!(isPriceChangeFish || isVolumeChangeFish || isPrice52WeeksLow)) { continue; } if ( db.CaughtFish.Where( x => x.Symbol.Equals(item.Symbol) && x.WhenCreated > today && x.WhenCreated < tomorrow) .Any()) { continue; } var caughtFish = new CaughtFish(); caughtFish.Symbol = item.Symbol; caughtFish.WhenCreated = DateTime.Now; caughtFish.Price = item.LastTradePrice; caughtFish.PriceChangePercentage = item.ChangeInPercent; caughtFish.Volume = item.Volume; if (item.AverageDailyVolume > 0 && item.Volume > 0) { caughtFish.VolumeChangePercentage = (int)(0.5M + 100M * (item.Volume - item.AverageDailyVolume) / item.AverageDailyVolume); } var message = ""; var subject = ""; if (isPriceChangeFish) { caughtFish.FishType = 0; message = string.Format(MessageText, "Price Change Alert -- ", caughtFish.Symbol, caughtFish.Price.ToString(), caughtFish.PriceChangePercentage.ToString(), caughtFish.Volume.ToString(), caughtFish.VolumeChangePercentage); subject = " Price Drop Alert -- " + caughtFish.Symbol; } else if (isVolumeChangeFish) { caughtFish.FishType = 1; message = string.Format(MessageText, "Volume Change Alert -- ", caughtFish.Symbol, caughtFish.Price.ToString(), caughtFish.PriceChangePercentage.ToString(), caughtFish.Volume.ToString(), caughtFish.VolumeChangePercentage.ToString()); subject = " Volumne Change Alert -- " + caughtFish.Symbol; } else if (isPrice52WeeksLow) { caughtFish.FishType = 1; message = string.Format(MessageText, "52 Weeks low price Alert -- ", caughtFish.Symbol, caughtFish.Price.ToString(), caughtFish.PriceChangePercentage.ToString(), caughtFish.Volume.ToString(), caughtFish.VolumeChangePercentage.ToString()); subject = " 52 Weeks Low Alert -- " + caughtFish.Symbol; } db.CaughtFish.Add(caughtFish); db.SaveChanges(); Messaging.SendEmailGmail(subject, MessageDetail.GetMessageDetail(item)); } catch (Exception ex) { StaticLog.Error(ex); } } } }