private void newToolStripButton_Click(object sender, EventArgs e) { univ = new universe(50, 50); generations = 0; gpUniv.Invalidate(); timer1.Stop(); }
private QueryResult QueryProducts(Query query, int publicationId) { query.setThemesDisabled(true); query.setListViewSize(this.maxItems); page fhPage = this.fhClient.getAll(query.toString()); universe universe = this.GetUniverse(fhPage); var modelMappings = this.GetPublicationConfiguration(publicationId).ModelMappings; var result = new QueryResult(); result.Products = new List <Product>(); var itemsSection = universe.itemssection; if (universe.itemssection != null) { result.Total = universe.itemssection.results.total_items; result.NumberOfPages = universe.itemssection.results.total_items / universe.itemssection.results.view_size; if (universe.itemssection.results.total_items % universe.itemssection.results.view_size != 0) { result.NumberOfPages++; } foreach (var item in universe.itemssection.items) { result.Products.Add(new FredhopperProduct(item, modelMappings)); } } return(result); }
public void save(universe universe) { using (var conn = new MySqlConnection(Configuration.quantdb)) { conn.Open(); conn.Execute("DELETE FROM universe WHERE name=@name", new { name = universe.name }); var upserts = universe .codes .Select(p => string.Format("INSERT INTO universe (code,name) VALUES ('{0}','{1}')", p, universe.name)) .ToArray(); if (upserts.Any()) { conn.Execute(string.Join(";", upserts)); } } }
private void openToolStripButton_Click(object sender, EventArgs e) { univ = new universe(50, 50); string line; using (StreamReader sr = new StreamReader("universeSave.txt")) { for (int y = 0; y < univ.Max_Y; y++) { for (int x = 0; x < univ.Max_X; x++) { line = sr.ReadLine(); if (line == "True") { univ.cells[y, x].State = true; } } } } }
public Product GetProduct(string id, int publicationId) { var location = GetLocation(publicationId); Query query = new Query(location); query.addSecondId(id); query.setView(ViewType.DETAIL); page fhPage = this.fhClient.getAll(query.toString()); universe universe = this.GetUniverse(fhPage); var modelMappings = this.GetPublicationConfiguration(publicationId).ModelMappings; var itemsSection = universe.itemssection; if (universe.itemssection != null) { foreach (var item in universe.itemssection.items) { return(new FredhopperProduct(item, modelMappings)); } } return(null); }
private void GetCategories(Category parentCategory, int publicationId) { Location location; if (parentCategory != null && parentCategory.CategoryId != null) { location = GetLocation(publicationId, parentCategory.CategoryId); } else { location = GetLocation(publicationId); } Query query = new Query(location); page fhPage = this.fhClient.getAll(query.toString()); universe universe = this.GetUniverse(fhPage); var facetmap = universe.facetmap[0]; var filters = facetmap.filter; foreach (var filter in filters) { if (filter.basetype == attributeTypeFormat.cat) { foreach (var section in filter.filtersection) { if (parentCategory == null || !CategoryAlreadyExistInStructure(parentCategory, section.value.Value)) { var category = new FredhopperCategory(section.value.Value, section.link.name, parentCategory); if (parentCategory != null) { parentCategory.Categories.Add(category); } } } } } }
public override void exec() { //var a = analytic.hitkeyprices(); //log.Info(a.ToCsv()); //return; log.Info("run strategy " + param.name.ToLower()); log.Info("get codes"); universe universe; if (param.astock) { var codes = param.universe.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); universe = new universe(param.universe, codes); } else if (param.asector) { universe = new universe(param.universe, new Trade.Db.db().codes(param.universe).ToArray()); } else { universe = getUniverse(param.universe); } log.Info("total " + universe.codes.Length); log.Info("get run"); var pool = new StockPool(universe.codes); var orders = !param.backtest ? new IOrder[] { new dbOrder(), new smsOrder() } : new IOrder[] { new dbOrder() }; var portflio = (param.portflio ?? param.name.ToLower()) + (param.backtest ? "-backtest" : ""); var account = new Account(portflio, pool, orders, param.backtest); switch (param.name.ToLower()) { case "macd15min": new strategies.macd15minstrategy().Run(account); break; } if (param.backtest) { log.Info("run back test"); var client = new kdatadb(); log.InfoFormat("total {0}", account.universe.Count); var pnls = new List <pnl>(); foreach (var stock in account.universe.AsParallel()) { log.InfoFormat("run {0}", stock.Code); var k = client.kdata(stock.Code, "D"); if (k == null && !k.Any()) { log.WarnFormat("empty data set for {0}", stock.Code); continue; } var trades = account.Trades .Where(p => p.code == stock.Code) //.Where(p=>p.Date >= new DateTime(2016,9,1)) .OrderBy(p => p.date) .ToArray(); var backtest = new backtesting(stock.Code, k.close(), trades); if (backtest.pnl != null) { pnls.Add(backtest.pnl); } } var format = "{0,-15}{1,-20}{2,10:N0}{3,10:N0}{4,10:N1}"; log.InfoFormat(format, "code", "date", "value", "capital", "ratio%"); foreach (var pnl in pnls) { log.InfoFormat(format, pnl.code, pnl.date, pnl.value, pnl.capital, pnl.ratio); } } log.Info("**********DONE**********"); }