public ActionResult Create() { ViewBag.Tooltips = toolTips; //Utils.Utility gets the ID of the user that's logged in Utils.Utility userUtil = new Utils.Utility(); int entityID = db.users.Find(userUtil.UserID(User)).entity.ID; //Uses InvestmentViewModel which is at the bottom of this file InvestmentViewModel ivm = new InvestmentViewModel(); //pulling in all the entities in the system ivm.Entities = db.entities.ToList(); //new investment because we're creating one ivm.Investment = new Models.Investment(); //sets the default investment date to the current date ivm.Investment.date = DateTime.Now; //pulling all of the current entity's categories ivm.Categories = new List<Category>(); foreach (var category in db.categories) { if (category.entityID == entityID) { ivm.Categories.Add(category); } } //entityFrom is retrieved based on the user that's logged in ivm.Investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity; //projectsFrom is populated based on entityFrom's projects ivm.Projects = db.projects.Where(i => i.entity.ID == ivm.Investment.entityFrom.ID).ToList(); return View(ivm); }
public ActionResult Edit(int? id) { ViewBag.Tooltips = toolTips; if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } InvestmentViewModel ivm = new InvestmentViewModel(); Utils.Utility userUtil = new Utils.Utility(); ivm.Investment = db.investments.Find(id); ivm.Entities = db.entities.ToList(); ivm.Categories = db.categories.ToList(); ivm.Investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity; ivm.Projects = db.projects.Where(i => i.entity.ID == ivm.Investment.entityFrom.ID).ToList(); ViewBag.InvestmentCategories = string.Join(",", ivm.Investment.categories.Select(c => c.ID)); if (ivm.Investment == null) { return HttpNotFound(); } return View(ivm); }
//For Investments/Edity, gets categories NOT attached to current investment public ActionResult NonCurrInvestmentCategories(int investmentID) { Utils.Utility userUtil = new Utils.Utility(); List <Category> currentCategories = new List <Category>(); foreach (var category in db.investments.Find(investmentID).categories) { currentCategories.Add(category); } List <Category> nonCurrentCategories = new List <Category>(); foreach (var category in db.categories) { if (category.entityID == db.users.Find(userUtil.UserID(User)).entity.ID&& !currentCategories.Contains(category)) { nonCurrentCategories.Add(category); } } var result = JsonConvert.SerializeObject(nonCurrentCategories, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Content(result, "application/json")); }
private async Task <RealTimeData> Filter(string stockId) { using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <BlogContext>(); var helper = new Utils.Utility(db); float marketLow = _arg.MarketLow; float marketHigh = _arg.MarketHigh; RealTimeData ret = null; var realData = await helper.GetRealTimeDataWithDate(stockId, _arg.BaseDate); if (realData != null && realData.ZongShiZhi != null) { if (marketLow * 1e8 <= realData.LiuTongShiZhi && realData.LiuTongShiZhi <= marketHigh * 1e8) { ret = realData; } } //如果是null,表示不符合筛选条件 return(ret);; } }
public ActionResult Index() { //DashboardViewModel dvm = new DashboardViewModel(); //Utils.Utility userUtil = new Utils.Utility(); //var currEntity = db.users.Find(userUtil.UserID(User)); //dvm.investmentsOut = currEntity.entity.investmentsOut.ToList(); //dvm.projects = currEntity.entity.projects.ToList(); //dvm.entity = currEntity.entity; //dvm.investment = new Investment(); //dvm.project = new Project(); Utils.Utility uu = new Utils.Utility(); List <Category> categoriesList = db.categories.ToList(); //Redirects to Categories/CreateBase if there are no categories (aka a base category is needed) if (categoriesList.Count < 1) { return(RedirectToAction("CreateBase", "Categories")); } //Redirects to Dashboard if there is an entity attached to the currently logged in user if (db.users.Find(uu.UserID(User)).entity != null) { var entity = db.users.Find(uu.UserID(User)).entity; return(View(entity)); } //If not, redirect to create an entity return(RedirectToAction("Create", "Entities")); }
public ActionResult Create([Bind(Include = "ID,name")] Category category, Metric metric, string newMetrics, int baseID) { if (ModelState.IsValid) { Utils.Utility userUtil = new Utils.Utility(); category.entityID = db.users.Find(userUtil.UserID(User)).entity.ID; category.isBase = false; category.baseID = baseID; db.categories.Add(category); db.SaveChanges(); var catID = category.ID; if (newMetrics != "") { foreach (var metricName in newMetrics.Split(',')) { metric.name = metricName; metric.categoryID = catID; db.metrics.Add(metric); db.SaveChanges(); Category currentCategory = db.categories.Find(catID); currentCategory.metrics.Add(metric); db.SaveChanges(); } } return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Index() { ViewBag.Tooltips = toolTips; //return View(db.investments.ToList()); Utils.Utility uu = new Utils.Utility(); var entity = db.users.Find(uu.UserID(User)).entity; return View(entity); }
// GET: Map public ActionResult Index() { Utils.Utility userUtil = new Utils.Utility(); //MapViewModel mvm = new MapViewModel(); Entity currentEntity = db.users.Find(userUtil.UserID(User)).entity; return(View(currentEntity)); }
public ActionResult Index() { ViewBag.Tooltips = toolTips; Utils.Utility uu = new Utils.Utility(); var entity = db.users.Find(uu.UserID(User)).entity; return(View(entity.projects.ToList())); }
private double GetDistanceInMeters() { if (_distance == null) { var u = new Utils.Utility(); _distance = u.GetDistanceInMeters(GetPings().OrderBy(p => p.Time).ToList()); } return(_distance ?? 0); }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int nearestDayNum = _arg.NearDaysNum; int riseNum = _arg.NRiseNum; var dayDataList = await helper.GetDayData(stockId, nearestDayNum, _arg.BaseDate); if (dayDataList.Count > 0) { //对数据进行处理 for (int i = 0; i < dayDataList.Count - riseNum + 1; i++) { int j = 0; for (; j < riseNum; j++) { if (dayDataList[dayDataList.Count - 1 - (i + j)].Close <= dayDataList[dayDataList.Count - 1 - (i + j)].Open) { //不符合连涨条件 break; } } if (j == riseNum) { //符合条件,不需要再检索 //加入 dayData = dayDataList[dayDataList.Count - 1 - i]; break; } } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
public ActionResult GetCurrEntity() { Utils.Utility userUtil = new Utils.Utility(); Entity currEntity = db.entities.Find(userUtil.UserID(User)); var result = JsonConvert.SerializeObject(currEntity, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Content(result, "application/json")); }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); bool fitFlag = false; int objIndex = _arg.StockIdList.IndexOf(stockId); DateTime startDate = _arg.DateList[objIndex]; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, startDate, _arg.BaseDate); if (dayDataList.Count > 0) { //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); // //获取均线数据 var closePrice = (from ii in dayDataList select ii.Close).Max(); if (closePrice != 0) { var startItem = dayDataList.LastOrDefault(); dayData = startItem; dayData.ZhangDieFu = (closePrice - startItem.Close) / startItem.Close * 100; fitFlag = true; } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (fitFlag) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <BlogContext>(); var helper = new Utils.Utility(db); float low = _arg.ZhangFuLow; float high = _arg.ZhangFuHigh; int numcnt = _arg.CircleDaysNum; DayData dayData = null; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //单独只使用涨跌幅,不需要复权 if (dayDataList.Count == numcnt) { float mul = 1; for (int i = 0; i < dayDataList.Count; i++) { var fudu = dayDataList[i].ZhangDieFu; if (fudu != null) { mul *= (1 + fudu.Value / 100f); } } if (low / 100f <= mul - 1 && mul - 1 <= high / 100f) { dayData = dayDataList[0]; } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
public ActionResult Create([Bind(Include = "ID,name,description")] Project project) { if (ModelState.IsValid) { Utils.Utility userUtil = new Utils.Utility(); project.entity = db.users.Find(userUtil.UserID(User)).entity; db.projects.Add(project); db.SaveChanges(); return(RedirectToAction("Index", "Dashboard")); } return(View(project)); }
public ActionResult Create() { Utils.Utility userUtil = new Utils.Utility(); User user = db.users.Find(userUtil.UserID(User)); if (user.entity != null) { return(RedirectToAction("Index", "Dashboard")); } else { return(View()); } }
public ActionResult Create([Bind(Include = "ID,name,description,address1,address2,city,state,zip,lat,lng")] Entity entity) { if (ModelState.IsValid) { //Instantiating userUtil to get the ID of currently logged in user Utils.Utility userUtil = new Utils.Utility(); //Using geocoder from Google to get latitude and longitude from entity address IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "AIzaSyDOH51wduQKexTyFXGy0tdDqfXw47XIrjA" }; IEnumerable <Address> addresses = geocoder.Geocode(entity.address1 + " " + entity.address2 + " " + entity.city + " " + entity.state + " " + entity.zip); entity.lat = Convert.ToString(addresses.First().Coordinates.Latitude); entity.lng = Convert.ToString(addresses.First().Coordinates.Longitude); //user is the currently logged in user; attach the entity we're making to the user var user = db.users.Find(userUtil.UserID(User)); db.entities.Add(entity); db.SaveChanges(); user.entity = entity; db.SaveChanges(); //Creating a default project each time that an entity is created Project project = new Project(); project.name = "General Fund"; project.description = "General Pool of Funds - unassigned to a project"; project.entity = entity; db.projects.Add(project); db.SaveChanges(); //Add the project to this entity's list of projects entity.projects.Add(project); db.SaveChanges(); //Once the entity is created, redirect to the dashboard IF there are categories in the system //If there aren't, that means no base categories exist and the user will be redirected to make one List <Category> categoriesList = db.categories.ToList(); if (categoriesList.Count > 0) { return(RedirectToAction("Index", "Dashboard")); } else { return(RedirectToAction("CreateBase", "Categories")); } } return(View(entity)); }
public ActionResult Index() { Utils.Utility userUtil = new Utils.Utility(); int entityID = db.users.Find(userUtil.UserID(User)).entity.ID; CategoryViewModel cvm = new CategoryViewModel(); cvm.UserCategories = new List <Category>(); //List<Category> userCategories = new List<Category>(); foreach (var category in db.categories) { if (category.entityID == entityID) { cvm.UserCategories.Add(category); } } cvm.BaseCategories = db.categories.Where(bcat => bcat.isBase == true).ToList(); //List<Category> categories = db.categories.ToList(); return(View(cvm)); }
public ActionResult UserCategories() { Utils.Utility userUtil = new Utils.Utility(); List <Category> userCategories = new List <Category>(); int currEntityId = db.users.Find(userUtil.UserID(User)).entity.ID; foreach (var category in db.categories) { if (category.entityID == currEntityId) { userCategories.Add(category); } } var result = JsonConvert.SerializeObject(userCategories, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Content(result, "application/json")); }
public ActionResult Edit([Bind(Include = "ID,name,description,address1,address2,city,state,zip,lat,lng")] Entity entity) { Utils.Utility userUtil = new Utils.Utility(); IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "AIzaSyDOH51wduQKexTyFXGy0tdDqfXw47XIrjA" }; IEnumerable <Address> addresses = geocoder.Geocode(entity.address1 + " " + entity.address2 + " " + entity.city + " " + entity.state + " " + entity.zip); if (ModelState.IsValid) { entity.lat = Convert.ToString(addresses.First().Coordinates.Latitude); entity.lng = Convert.ToString(addresses.First().Coordinates.Longitude); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Dashboard")); } return(View(entity)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategoryViewModel cvm = new CategoryViewModel(); Utils.Utility userUtil = new Utils.Utility(); cvm.Category = db.categories.Find(id); cvm.BaseCategories = db.categories.Where(bcat => bcat.isBase == true).ToList(); if (cvm.Category == null) { return(HttpNotFound()); } return(View(cvm)); }
private async Task <RealTimeData> Filter(string stockId) { using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); float low = _arg.TurnOverRateLow; float high = _arg.TurnOverRateHigh; RealTimeData ret = null; var realData = await helper.GetRealTimeDataWithDate(stockId, _arg.BaseDate); if (realData != null) { var zhibiao = realData.HuanShouLiu; if (zhibiao != null) { if (low <= zhibiao && zhibiao <= high) { ret = realData; } } } //如果是null,表示不符合筛选条件 return(ret);; } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int numcnt = _arg.CircleDaysNum + _arg.NearDaysNum; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); bool fitFlag = false; if (dayDataList.Count == numcnt) { for (int j = 0; j < _arg.NearDaysNum; j++) { DayData current = dayDataList[_arg.NearDaysNum - 1 - j]; if (current.ZhangDieFu >= _arg.ZhangFu) { float sum = 0; //对数据进行处理,当日的不处理 for (int i = 0; i < _arg.CircleDaysNum; i++) { sum += dayDataList[dayDataList.Count - 1 - (i + j)].Volume; } float avrage = sum / _arg.CircleDaysNum; //判断突破的时间 if (current.Volume >= avrage * _arg.VolTimesNum) { dayData = current;//满足要求 fitFlag = true; break; } } } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (fitFlag) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int numcnt = _arg.UpDaysNum + _arg.NearDaysNum + _arg.AvgDays; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); bool fitFlag = false; if (dayDataList.Count == numcnt) { // //获取均线数据 var closeList = (from ii in dayDataList select ii.Close).ToList(); var maArray = Utils.CalcData.Average(closeList, _arg.AvgDays); //满足条件的flag //对数据进行处理,当日的不处理 for (int i = 0; i < _arg.UpDaysNum; i++) { var current = dayDataList[i]; if (current.Close > maArray[i]) { //不满足条件 fitFlag = true; dayData = current; break; } } if (fitFlag) { int exceptCnt = 0; for (int j = 0; j < _arg.NearDaysNum; j++) { //进一步判读之前的是否是在均线之下 var temp = dayDataList[j + _arg.UpDaysNum]; if (temp.Close >= maArray[j + _arg.UpDaysNum]) { //不满足条件 exceptCnt++; if (exceptCnt > _arg.ExceptionNum) { fitFlag = false; break; } } } } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (fitFlag) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, _arg.CircleDaysNum + _arg.NearDaysNum, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); int breakIndex = 0; if (dayDataList.Count == _arg.CircleDaysNum + _arg.NearDaysNum) { //求出最近的最高价格,收盘 int i = 0; float maxClosePrice = 0; for (; i < _arg.NearDaysNum; i++) { float current = dayDataList[i].Close; if (current > maxClosePrice) { maxClosePrice = current; breakIndex = i; } } //如果不是严格模式 if (!_arg.StrictMode) { //如果收盘价高于收盘价,最高价高于最高价,就排除邻近的一根日线 var nearItem = dayDataList[breakIndex + 1]; if (dayDataList[breakIndex].Close >= nearItem.Close && dayDataList[breakIndex].High > nearItem.High) { bool allMatch = false; for (int tempj = i + 1; tempj < dayDataList.Count; tempj++) { if (dayDataList[tempj].High > nearItem.Close) { allMatch = true; break; } } if (allMatch) { i++; } } } //求出之前的最高的盘中最高价格 float previousMaxHigh = 0; for (; i < dayDataList.Count - _arg.NearDaysNum; i++) { float current = dayDataList[i].High; if (current > previousMaxHigh) { previousMaxHigh = current; } } //符合回调条件的点 bool match = false; if (maxClosePrice > previousMaxHigh) { for (i = 0; i < _arg.CircleDaysNum; i++) { //从最早的数据开始遍历 var listItem = dayDataList[dayDataList.Count - 1 - i]; if (listItem.High >= previousMaxHigh) { //寻找到高点 //后面的最低价格 float suffixMinLow = float.MaxValue; //寻找后续最低点 for (int j = i + 1; j < _arg.CircleDaysNum; j++) { float current = dayDataList[dayDataList.Count - 1 - j].Low; if (current < suffixMinLow) { suffixMinLow = current; } } float fudu = (listItem.High - suffixMinLow) / listItem.High; if (fudu >= _arg.HuiTiaoFuDuLow / 100f && fudu <= _arg.HuiTiaoFuDuHigh / 100f) { //符合回调幅度的高点 match = true; break; } } } } if (match) { //符合条件 dayData = dayDataList[breakIndex]; } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int numcnt = 1 + _arg.NearDaysNum; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); if (dayDataList.Count == numcnt) { //符合回调条件的点 bool match = false; int matchIndex = -1; for (int i = 0; i < _arg.NearDaysNum; i++) { //从最早的数据开始遍历 int currentIndex = dayDataList.Count - 1 - i - 1; //要跳过第一个数据 var currentListItem = dayDataList[currentIndex]; var previousListItem = dayDataList[currentIndex + 1]; //是倒序。 if (currentListItem.Low > previousListItem.High && (currentListItem.Low - previousListItem.Close) / previousListItem.Close > _arg.GapPercent / 100.0 && currentListItem.Close > currentListItem.Open && //真阳线 currentListItem.ZhangDieFu <= _arg.LimitPercent ) { //满足跳空条件 //后面的最低价格 float suffixMinLow = float.MaxValue; //寻找后续最低点 for (int j = i; j < _arg.NearDaysNum; j++) { var temp = dayDataList[dayDataList.Count - 1 - j - 1]; float current = temp.Low; if (current < suffixMinLow) { suffixMinLow = current; } } if (suffixMinLow > previousListItem.High) { //符合回调幅度的高点 match = true; matchIndex = currentIndex; break; } } } if (match) { //符合条件 dayData = dayDataList[matchIndex]; } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int numcnt = _arg.RecentDaysNum + _arg.MaxDaysNumDownAvgBeforeTwice + +_arg.MaxDaysNumUpAvgAfterFirst + _arg.MinDaysNumDownAvgBeforeFirst + _arg.AvgDays; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); bool fitFlag = false; if (dayDataList.Count == numcnt) { // //获取均线数据 var closeList = (from ii in dayDataList select ii.Close).ToList(); var maArray = Utils.CalcData.Average(closeList, _arg.AvgDays); int gobleIndex = 0; //满足条件的flag for (; gobleIndex < _arg.RecentDaysNum; gobleIndex++) { var current = dayDataList[gobleIndex]; if (current.Close >= maArray[gobleIndex] && dayDataList[gobleIndex + 1].Close < maArray[gobleIndex + 1]) { //满足本阶段条件 fitFlag = true; dayData = current; break; } } if (fitFlag) { //重新设置标记 //检查在均线之下是否超过最大天数 fitFlag = false; int startIndex = gobleIndex + 1; //之前的处理前一个数据时,并没有移动索引 int bianjie = startIndex + _arg.MaxDaysNumDownAvgBeforeTwice + 1; //往前再弄一天 for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++) { var current = dayDataList[gobleIndex]; if (current.Close >= maArray[gobleIndex]) { fitFlag = true; break; } } } if (fitFlag) { //重新设置标记 //检查在均线之上是否超过最大天数 fitFlag = false; int startIndex = gobleIndex; // //之前的处理前一个数据时,移动了索引 int bianjie = startIndex + _arg.MaxDaysNumUpAvgAfterFirst + 1; //刚好全部都在均线上,然后再往前一天在均线下了 for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++) { var current = dayDataList[gobleIndex]; if (current.Close < maArray[gobleIndex]) { //在指定数量内逆序后,第一次出现低于均线 //满足本阶段条件 fitFlag = true; break; } } if (gobleIndex - startIndex < _arg.MinDaysNumUpAvgAfterFirst) { //在均线之上的天数少于要求。 fitFlag = false; } } if (fitFlag) { int exceptCnt = 0; fitFlag = false; int startIndex = gobleIndex; //之前的处理前一个数据时,移动了索引 int bianjie = startIndex + _arg.MinDaysNumDownAvgBeforeFirst - 1; //这里是满足性检查,不是数据变化检查,上一个检查必定有一个处于均线之下 for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++) { //进一步判读之前的是否是在均线之下 var current = dayDataList[gobleIndex]; if (current.Close >= maArray[gobleIndex]) { //不满足条件 exceptCnt++; if (exceptCnt > _arg.MaxDaysNumUpAvgBeforeFirst) { fitFlag = false; break; } } } if (exceptCnt <= _arg.MaxDaysNumUpAvgBeforeFirst) { fitFlag = true; } } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (fitFlag) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <StockContext>(); var helper = new Utils.Utility(db); int numcnt = _arg.CircleDaysNum + _arg.NearDaysNum; //当天的数据算一个 var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate); //使用成交量,需要复权 //复权,会改变dayDataList中的数据 await Utils.CalcData.FuQuan(db, stockId, dayDataList); if (dayDataList.Count == numcnt) { //求出最近的最高价格,收盘 int i = 0; float maxClosePriceInNearDays = 0; for (; i < _arg.NearDaysNum; i++) { float current = dayDataList[i].Close; if (current > maxClosePriceInNearDays) { maxClosePriceInNearDays = current; } } //求出之前的最高的盘中最高价格 float maxHighInPreviousDays = 0; for (; i < dayDataList.Count - _arg.NearDaysNum; i++) { float current = dayDataList[i].High; if (current > maxHighInPreviousDays) { maxHighInPreviousDays = current; } } //符合回调条件的点 bool match = false; if (maxClosePriceInNearDays <= maxHighInPreviousDays && (maxHighInPreviousDays - maxClosePriceInNearDays) / maxClosePriceInNearDays * 100 < _arg.XiangchaLv ) { for (i = 0; i < _arg.CircleDaysNum; i++) { //从最早的数据开始遍历 var listItem = dayDataList[dayDataList.Count - 1 - i]; if (listItem.High >= maxHighInPreviousDays) { //寻找到高点 //后面的最低价格 float suffixMinLow = float.MaxValue; //寻找后续最低点 for (int j = i + 1; j < _arg.CircleDaysNum; j++) { float current = dayDataList[dayDataList.Count - 1 - j].Low; if (current < suffixMinLow) { suffixMinLow = current; } } float fudu = (listItem.High - suffixMinLow) / listItem.High; if (fudu >= _arg.HuiTiaoFuDuLow / 100f && fudu <= _arg.HuiTiaoFuDuHigh / 100f) { //符合回调幅度的高点 match = true; break; } } } } if (match) { //符合条件 dayData = dayDataList[0]; } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }
public ActionResult Create([Bind(Include = "ID,amount,entityFrom_ID,entityTo_ID,description,date,isInKind, projectFrom_ID,projectTo_ID")] Investment investment, int entityTo_ID, int projectTo_ID, int projectFrom_ID, string categories, string investmentMetrics) { if (ModelState.IsValid) { //Utils.Utility gets currently logged in user's ID Utils.Utility userUtil = new Utils.Utility(); //entityTo_ID gets sent in via the forms and then attached to the investment here investment.entityTo = db.entities.Find(entityTo_ID); //entityFrom uses UserID() from Utils/Utility.cs to get the entity linked to the currently logged in User investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity; //projectTo_ID and projectFrom_ID get sent in via the forms and then attached to the investment here investment.projectTo = db.projects.Find(projectTo_ID); investment.projectFrom = db.projects.Find(projectFrom_ID); //"selectedCategories" is a comma-separated string of categories sent in via the forms //(a hidden input) //the string is split into an array, and then each one is added to the new investment's category list if (categories != "" && categories != null) { investment.categories = new List<Category>(); foreach (var id in categories.Split(',')) { investment.categories.Add(db.categories.Find(Convert.ToInt32(id))); } } //"selectedMetrics" is a comma-separated string of categories sent in via the forms //(a hidden input) //the string is split into an array, and then each one is added to the new investment's category list if (investmentMetrics != "" && investmentMetrics != null) { investment.metrics = new List<Metric>(); foreach (var id in investmentMetrics.Split(',')) { investment.metrics.Add(db.metrics.Find(Convert.ToInt32(id))); } } //finally we add the investment to the database and save the changes db.investments.Add(investment); db.SaveChanges(); //These if statements are analogous to if projectTo != null / if projectFrom != null //If the investment has a projectTo, add this investment to that project's investmentsIn list if (projectTo_ID != 0) { Project newProject = new Project(); newProject = db.projects.Find(projectTo_ID); newProject.investmentsIn.Add(db.investments.Find(investment.ID)); db.SaveChanges(); } //If the investment has a projectFrom, add this investment to that project's investmentsOut list if (projectFrom_ID != 0) { Project newProject = new Project(); newProject = db.projects.Find(projectFrom_ID); newProject.investmentsOut.Add(db.investments.Find(investment.ID)); db.SaveChanges(); } //Now redirect to the dashboard return RedirectToAction("Index", "Dashboard"); } return View(investment); }
private async Task <RealTimeData> Filter(string stockId) { DayData dayData = null; using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <BlogContext>(); var helper = new Utils.Utility(db); int nearestDayNum = _arg.NearDaysNum; int riseNum = _arg.NRiseNum; float volumePercent = _arg.VolumePercent; var dayDataList = await helper.GetDayData(stockId, nearestDayNum, _arg.BaseDate); if (dayDataList.Count > 0) { //对数据进行处理 for (int i = 0; i < dayDataList.Count - riseNum + 1; i++) { int j = 0; for (; j < riseNum - 1; j++) { int index = dayDataList.Count - 1 - (i + j); if (dayDataList[index].Volume < dayDataList[index - 1].Volume) { //不符合连续缩量 break; } } if (j == riseNum - 1) { //符合条件 //再判断成交量 int index = dayDataList.Count - 1 - (i + j); if (dayDataList[index].Volume <= dayDataList[index + riseNum - 1].Volume * volumePercent / 100f) { //加入 dayData = dayDataList[dayDataList.Count - 1 - i]; break; } } } } //如果是null,表示不符合筛选条件 RealTimeData real = null; if (dayData != null) { real = await helper.ConvertDayToReal(dayData); } return(real); } }