static void Main(string[] args) { var socks = Provider.GetStocks(); socks.ForEach(stock => { stock.Update(); var symbol = stock.Symbol; var begin = new DateTime(2014, 12, 1); var end = new DateTime(2014, 12, 31); var asset = new Asset(symbol, AssetType.Stock); try { ISamplePackage samplePackage = new YSQProvider().GetHistory(asset, begin, end, null); IBarPackage barPackage = (IBarPackage)samplePackage; stock.Update(barPackage); var samples = barPackage.Samples; int samplesCount = samples.Count; if (samplesCount > 0) { var lastValue = samples.Last().Close; Console.WriteLine("Stock: {0} - Samples: {1} - LastValue: {2}", symbol, samplesCount, lastValue); } else { Console.WriteLine("Stock: {0} - Samples: {1}", symbol, samplesCount); } } catch { Console.WriteLine("Stock: {0} - NO DATA FOUND", symbol); } stock.Save(); }); Console.ReadKey(true); }
static void Main(string[] args) { string symbol = YSQSymbol.YSQIndex.SNP; DateTime begin = new DateTime(2003, 12, 1); DateTime end = new DateTime(2004, 2, 1); ISamplePackage samplePackage = new YSQProvider().GetHistory(new Asset(symbol, AssetType.Index), begin, end, null); IBarPackage barPackage = (IBarPackage)samplePackage; List <IBar> bars = barPackage.Samples; TaResult ema13 = bars.EMA(13); BullPower bullPower = new BullPower(bars, 13); //var sampleValues = new List<IInstantValue<double>>(); //sampleValues.Add(new InstantValue<double>(new DateTime(2004, 1, 1), 1.0)); //sampleValues.Add(new InstantValue<double>(new DateTime(2004, 1, 2), -1.0)); //sampleValues.Add(new InstantValue<double>(new DateTime(2004, 1, 3), 1.0)); //sampleValues.Add(new InstantValue<double>(new DateTime(2004, 1, 4), -1.0)); ChartPool.CreateChart(); ChartPool.ClearSeries(); ChartPool.AddSeries( new List <Series> { new Series("Prices", ChartType.Lines, Colors.Black, bars.Select(x => new Sample(x.DateTime, (double)x.Close))), new Series("EMA(13)", ChartType.Lines, Colors.Red, ema13.InstantValues.Select(x => new Sample(x.DateTime, x.Value))), new Series("BullPower(13)", ChartType.Columns, Colors.Blue, bullPower.InstantValues.Select(x => new Sample(x.DateTime, x.Value))), } ); Console.WriteLine("Press a key to exit..."); Console.ReadKey(true); }
static void Main(string[] args) { string symbol = YSQSymbol.YSQIndex.SNP; DateTime begin = new DateTime(2013, 1, 1); DateTime end = new DateTime(2014, 1, 1); ISamplePackage samplePackage = new YSQProvider().GetHistory(new Asset(symbol, AssetType.Index), begin, end, null); IBarPackage barPackage = (IBarPackage)samplePackage; List <IBar> bars = barPackage.Samples; // simulation ISimulation bestSimulation = default(ISimulation); TaResult bestSimulationSmallEma = default(TaResult); TaResult bestSimulationBigEma = default(TaResult); ChartPool.CreateChart(); int configurationsCount = 0; DateTime simulationsBegin = DateTime.Now; for (int small = 2; small < 14; small += 1) { for (int big = 30; big < 80; big += 1) { for (int take = 10; take < 50; take += 2) { for (int stop = 10; stop < 50; stop += 2) { configurationsCount++; var simulation = SmaSimulation.CreateLongOnly(2, take, stop); simulation.SimulationInfo = string .Format("EMA_SMALL: {0}, EMA_BIG: {1}, TakeProfit: {2}, StopLoss: {3}", small, big, take, stop); SimulationRunner simulationRunner = new SimulationRunner(bars, simulation); var smallEma = bars.EMA(small); var bigEma = bars.EMA(big); simulationRunner.AddSerie("EMA_SMALL", smallEma); simulationRunner.AddSerie("EMA_BIG", bigEma); simulationRunner.Execute(); Console.WriteLine(simulation.GetReport()); if (bestSimulation == default(ISimulation) || simulation.Earnings > bestSimulation.Earnings) { bestSimulation = simulation; bestSimulationSmallEma = smallEma; bestSimulationBigEma = bigEma; } //ShowSimulation(simulation, bars, smallEma, bigEma); //Console.ReadKey(true); } } } } Console.WriteLine("{0} configurations tested in {1}", configurationsCount, DateTime.Now - simulationsBegin); Console.WriteLine("Best simulation"); ShowSimulation(bestSimulation, bars, bestSimulationSmallEma, bestSimulationBigEma); Console.ReadKey(true); }
public void TestHistoricalPrices() { ISamplePackage samplePackage = new YSQProvider().GetHistory(new Asset("MSFT", AssetType.Stock), new DateTime(2014, 1, 1), new DateTime(2014, 7, 1), null); Assert.IsTrue(samplePackage is ISamplePackage <IBar>, "samplePackage no es instancia de ISamplePackage<IBar>"); IBarPackage barPackage = (IBarPackage)samplePackage; Assert.IsNotNull(barPackage.Samples); Assert.IsTrue(barPackage.Samples.Count > 0); Assert.IsNotNull(barPackage.Asset); Assert.IsNotNull(barPackage.Source); Assert.IsNotNull(barPackage.Period); }
public void Update(IBarPackage barPackage) { barPackage.Samples.ForEach(bar => { var last = Bars.Samples.Last(); if (bar.DateTime > last.DateTime) { Bars.Samples.Add(bar); } else if (bar.DateTime < last.DateTime) { Bars.Samples.Insert(0, bar); } else { throw new InvalidOperationException("Implementar..."); } }); }
public void TestMethod() { // data string symbol = YSQSymbol.YSQIndex.SNP; DateTime begin = new DateTime(2000, 1, 1); DateTime end = new DateTime(2015, 1, 1); ISamplePackage samplePackage = new YSQProvider() .GetHistory(new Asset(symbol, AssetType.Index), begin, end, null); IBarPackage barPackage = (IBarPackage)samplePackage; List <IBar> bars = barPackage.Samples; // simulation var simulation = new TestSimulation(10, 5, true); SimulationRunner simulationRunner = new SimulationRunner(bars, simulation); simulationRunner.AddSerie("EMA_SMALL", bars.EMA(10)); simulationRunner.AddSerie("EMA_BIG", bars.EMA(20)); simulationRunner.Execute(); Debug.WriteLine(simulation.GetReport()); }
public void TestHistoricalPrices() { ISamplePackage samplePackage = DukascopyOfflineProvider.Instance .GetHistory( new Asset("EUR/USD", AssetType.Currency), new DateTime(2014, 1, 1), new DateTime(2014, 1, 31), new DukascopyOfflineContext( @"C:\storage\USDCAD_Candlestick_1_m_BID_01.01.2014-31.01.2014.csv", SampleType.Bar, TimeSpan.FromMinutes(1))); Assert.IsTrue(samplePackage is ISamplePackage <IBar>, "samplePackage no es instancia de ISamplePackage<IBar>"); IBarPackage barPackage = (IBarPackage)samplePackage; Assert.IsNotNull(barPackage.Samples); Assert.IsTrue(barPackage.Samples.Count > 0); Assert.IsNotNull(barPackage.Asset); Assert.IsNotNull(barPackage.Source); Assert.IsNotNull(barPackage.Period); }
public void Update(YahooStock stock) { Name = stock.Name; Symbol = stock.Symbol; Bars = stock.Bars; }