public virtual ICollection <ShoutedStory> GetPostedByTag(string tag, int start, int max) { Check.Argument.IsNotEmpty(tag, "tag"); Check.Argument.IsNotNegative(start, "start"); Check.Argument.IsNotNegative(max, "max"); return(CurrentDataSource.GetStoriesByTag(tag, start, max)); }
public override object Clone() { var p = new BacktestingProject() { Name = Name, Memo = Memo, IsUnlimited = IsUnlimited, AnalyseGrade = AnalyseGrade, AnalyseStartTime = AnalyseStartTime, CurrentDataSource = CurrentDataSource.Clone() as IDataSource, CurrentTradeGate = CurrentTradeGate, Fine = Fine, Grade = Grade, ProjectStartTime = ProjectStartTime, RiskPolicy = RiskPolicy.Clone() as IRiskControl, Status = Status, TargetPortfolio = TargetPortfolio.Clone() as IPortfolio, TestStrategy = TestStrategy.Clone() as IStrategy, TestCurrentTime = TestCurrentTime, TestEndTime = TestEndTime, TestStartTime = TestStartTime, TestStepDelayMS = TestStepDelayMS, }; ConditionList.ForEach(v => p.ConditionList.Add(v.Clone() as ICondition)); InstrumentList.ForEach(v => p.InstrumentList.Add(v.Clone() as IInstrument)); return(p); }
public virtual ICollection <ShoutedStory> GetPublishedByCategory(string category, int start, int max) { Check.Argument.IsNotEmpty(category, "category"); Check.Argument.IsNotNegative(start, "start"); Check.Argument.IsNotNegative(max, "max"); return(CurrentDataSource.GetStoriesByCategory(category, start, max)); }
public override object Clone() { var p = new AnalyseProject() { AnalyseEndTime = AnalyseEndTime, AnalyseStartTime = AnalyseStartTime, ProjectStartTime = ProjectStartTime, CurrentDataSource = CurrentDataSource.Clone() as IDataSource, DefaultFilterNumber = DefaultFilterNumber, Fine = Fine, Grade = Grade, Memo = Memo, Name = Name, TestStepDelayMS = TestStepDelayMS, Status = Status }; InstrumentList.ForEach(v => p.InstrumentList.Add(v.Clone() as IInstrument)); ResultList.ForEach(v => p.ResultList.Add(v.Clone() as IInstrument)); BlockList.ForEach(v => p.BlockList.Add(v.Clone() as IInstrument)); ConditionList.ForEach(v => p.ConditionList.Add(v.Clone() as ICondition)); PredicateList.ForEach(v => p.PredicateList.Add(v.Clone() as ICondition)); return(p); }
public void AddToVertexGraveyard(int buildingId, int vertexId) { //string errorMsg = "ERROR: Could not delete Vertex w. ID = " + vertexId + " from building w. ID = " + buildingId; //string succesMsg = "SUCCES: Deleted Vertex w. ID = " + vertexId + " from building w. ID = " + buildingId; //Check buildings exist Building graveyardBuilding = CurrentDataSource.Buildings.SingleOrDefault(b => b.ID == 18); //graveyard Building sourceBuilding = CurrentDataSource.Buildings.SingleOrDefault(b => b.ID == buildingId); if (graveyardBuilding == null || sourceBuilding == null) { return; // errorMsg; } //Check vertex exists Vertex targetVertex = CurrentDataSource.Vertices.SingleOrDefault(v => v.ID == vertexId && v.Building_ID == buildingId); if (targetVertex == null) { return; // errorMsg; } //delete the vertex's edges IQueryable <Edge> targetEdges = CurrentDataSource.Edges.Where(e => e.vertexOrigin == vertexId || e.vertexDestination == vertexId); foreach (Edge e in targetEdges) { CurrentDataSource.Edges.DeleteObject(e); } //move the vertex from the original building to the VertexGraveyard building (the one with ID = 18) graveyardBuilding.Vertices.Add(targetVertex); sourceBuilding.Vertices.Remove(targetVertex); CurrentDataSource.SaveChanges(); }
public virtual ICollection <ShoutedStory> GetShoutedByUser(string userName, int start, int max) { Check.Argument.IsNotEmpty(userName, "userName"); Check.Argument.IsNotNegative(start, "start"); Check.Argument.IsNotNegative(max, "max"); return(CurrentDataSource.GetStoriesShoutedByUser(userName, start, max)); }
private void RefreshDataSource() { if (null != CurrentDataSource) { CurrentDataSource.Refresh(); } }
private void RefreshDataSource() { if (null != CurrentDataSource) { CurrentDataSource.RefreshAsync(DataSourceRefreshComplete, this); } }
public bool RatePolicy(int policyID) { IPolicyRater rater = AIMS.Services.IoC.Container.Resolve <IPolicyRater>(); var policy = CurrentDataSource.Policies.Find(policyID); var result = rater.Rate(policy, CurrentDataSource); CurrentDataSource.SaveChanges(); return(result.Success); }
public override void SaveOriginalStatus() { CurrentDataSource.SaveOriginalStatus(); ConditionList.ForEach(v => v.SaveOriginalStatus()); TargetPortfolio.SaveOriginalStatus(); TestStrategy.SaveOriginalStatus(); CurrentTradeGate.SaveOriginalStatus(); RiskPolicy.SaveOriginalStatus(); }
public override void LoadOriginalStatus() { if (Status != ProjectStatus.Stopped) { Stop(); } CurrentDataSource.LoadOriginalStatus(); ConditionList.ForEach(v => v.LoadOriginalStatus()); PredicateList.ForEach(v => v.LoadOriginalStatus()); }
public override void PrepareWork() { CurrentDataSource.PrepareWork(); ProjectStartTime = DateTime.Now; ResultList.Clear(); ConditionList.ForEach(v => v.PrepareWork()); PredicateList.ForEach(v => v.PrepareWork()); current = 0; CurrentDataSource.CacheSize = 5; }
public override void FinishWork() { TestCurrentTime = TestEndTime; TargetPortfolio.FinishWork(); ConditionList.ForEach(v => v.FinishWork()); //SensorList.ForEach(v => v.FinishWork()); CurrentTradeGate.FinishWork(); CurrentDataSource.FinishWork(); TestStrategy.FinishWork(); RiskPolicy.FinishWork(); }
public void UpdatePerson(Person person, UpdateOperations op) { if (op.HasFlag(UpdateOperations.Delete)) { CurrentDataSource.AddToDeletedItems(new DeletedItem { Id = person.Id, EntitySet = "People", Ts = DateTime.Now }); } else { person.Ts = DateTime.Now; } }
public void UpdateCompany(Company company, UpdateOperations op) { if (op.HasFlag(UpdateOperations.Delete)) { CurrentDataSource.AddToDeletedItems(new DeletedItem { Id = company.Id, EntitySet = "Companies", Ts = DateTime.Now }); } else { company.Ts = DateTime.Now; } }
public override void LoadOriginalStatus() { if (Status != ProjectStatus.Stopped) { Stop(); } CurrentDataSource.LoadOriginalStatus(); ConditionList.ForEach(v => v.LoadOriginalStatus()); TargetPortfolio.LoadOriginalStatus(); TestStrategy.LoadOriginalStatus(); CurrentTradeGate.LoadOriginalStatus(); RiskPolicy.LoadOriginalStatus(); }
void Save() { TargetObject.InstrumentList.Clear(); foreach (var inst in InstrumentList) { TargetObject.InstrumentList.Add(inst); } TargetObject.SectorList.Clear(); foreach (var v in SectorList) { TargetObject.SectorList.Add(v); } TargetObject.CurrentDataSource = CurrentDataSource.Clone() as IDataSource; }
public void RemoveFromGroup(string pid, string gid) { var _pid = Int32.Parse(pid); var _gid = Int32.Parse(gid); var _person = CurrentDataSource.GoupMail_Person.Where(x => x.ItemID == _pid).FirstOrDefault(); var _group = CurrentDataSource.GroupMail_Groups.Where(x => x.ItemID == _gid).FirstOrDefault(); if (_person != null && _group != null) { _person.Lists.Remove(_group); CurrentDataSource.SaveChanges(); } }
/// <summary> /// 加载完成时 /// </summary> protected void LoadComplete() { State = LoaderState.complete; if (debug) { DebugConsole.Info("Loader", "加载完成", this.url, CurrentDataSource.ToString()); } OnLoadCompleteHandler(); onLoadComplete.Dispatch(this); onLoadComplete.Clear(); if (CurrentDataSource.source != DownLoadAgent.DataSourceType.Cache) { SaveToLocal(); } }
public void LoadCurrentInstrumentMarketData(DateTime start, DateTime end) { if (CurrentInstrument == null) { return; } else { MarketDataList.Clear(); var ml = CurrentDataSource.GetDataList(new List <IInstrument>() { CurrentInstrument }, start, end, Grade); ml.ForEach(v => MarketDataList.Add(v)); } }
public List <IMarketData> GetMarketDataList() { if (CurrentDataSource == null) { return(null); } if (AnalyseType != DistributeAnalyseType.Instrument) { InstrumentList.Clear(); SectorList.ForEach(s => { InstrumentList.AddRange(Instrument.GetInstrumentBySector(s, AnalyseType)); }); } return(CurrentDataSource.GetDataList(InstrumentList, StartTime, EndTime, Grade)); }
public bool AddAttendee(string name, string email, string company, string registrationCode, int eventId) { if (!(from rc in this.CurrentDataSource.RegistrationCodes where rc.RegistrationCode1 == registrationCode select rc).Any()) { return(false); } var attendee = new Attendee { Name = name, Email = email, Company = company, RegistrationCode = registrationCode, EventId = eventId }; CurrentDataSource.Attendees.AddObject(attendee); return(!(CurrentDataSource.SaveChanges() < 1)); }
protected virtual void InterceptChange(TenantEntity entity, UpdateOperations operations) { if (TenantFilter.AppTenantID == 0) { throw new HttpRequestValidationException(); } if (operations == UpdateOperations.Add) { entity.AppTenantID = TenantFilter.AppTenantID; } if (operations == UpdateOperations.Change) { int originalTenant = CurrentDataSource.Entry(entity).OriginalValues.GetValue <int>("AppTenantID"); if (originalTenant != TenantFilter.AppTenantID) { throw new HttpRequestValidationException(); } if (originalTenant != entity.AppTenantID) { throw new Exception("Entity cannot move across tenants"); } } if (operations == UpdateOperations.Delete) { int originalTenant = CurrentDataSource.Entry(entity).OriginalValues.GetValue <int>("AppTenantID"); if (originalTenant != TenantFilter.AppTenantID) { throw new HttpRequestValidationException(); } } }
public List <Tuple <double, double> > GetDimentionAnalyse(IInstrument inst, bool isAbsolute = false, int n = 20) { var ml = CurrentDataSource.GetDataList(inst, StartTime, EndTime, Grade); return(GetDimentionAnalyse(GetDistributeDataList(ml), isAbsolute, n)); }
public List <Tuple <double, double, double> > Get3DCurve(IInstrument inst) { var ml = CurrentDataSource.GetDataList(inst, StartTime, EndTime, Grade); return(Get3DCurve(GetDistributeDataList(ml))); }
public override void FinishWork() { CurrentDataSource.FinishWork(); ConditionList.ForEach(v => v.FinishWork()); PredicateList.ForEach(v => v.FinishWork()); }
IEnumerator LoadingSequence() { int i = 0; while (i < config.dataSources.Count) { CurrentDataSource = config.dataSources[i]; if (debug) { DebugConsole.Info("Loader", "加载URl", url, CurrentDataSource.ToString() + id.ToString()); } switch (CurrentDataSource.source) { case DownLoadAgent.DataSourceType.Cache: if (this.HasLocal()) { Coroutine async = this.LoadFromLocal(); if (debug) { DebugConsole.Info("Loader", "本地缓存", (async == null).ToString(), id.ToString()); } //异步加载中 if (async != null) { yield return(async); } if (this.State == LoaderState.complete) { this.LoadComplete(); yield break; } else { i++; continue; } } else { i++; continue; } case DownLoadAgent.DataSourceType.Resource: Coroutine Resasync = this.LoadFromResource(); if (debug) { DebugConsole.Info("Loader", "资源文件", (Resasync == null).ToString(), id.ToString()); } //异步加载中 if (Resasync != null) { yield return(Resasync); } if (this.State == LoaderState.complete) { this.LoadComplete(); yield break; } else { i++; continue; } case DownLoadAgent.DataSourceType.StreamAsset: try { www = new WWW(url); } catch (Exception e) { if (debug) { DebugConsole.Info("Loader", "StreamAsset", "加载失败", id.ToString()); } i++; continue; } yield return(www); if (!String.IsNullOrEmpty(www.error)) //出错 { DebugConsole.Warning("Loader", "Server", this.url, www.error); www = null; //直接释放 i++; continue; } else if (www.isDone) { LoadComplete(); yield break; } i++; continue; case DownLoadAgent.DataSourceType.Server: if (this.HasNewVersion()) { try { www = new WWW(url); } catch (Exception e) { if (debug) { DebugConsole.Info("Loader", "Server", "加载失败", id.ToString()); } i++; continue; } yield return(www); if (!String.IsNullOrEmpty(www.error)) //出错 { DebugConsole.Warning("Loader", "Server", this.url, www.error); www = null; //直接释放 i++; continue; } else if (www.isDone) { LoadComplete(); yield break; } } i++; continue; } } this.LoadError(); }
public virtual ICollection <ShoutedStory> GetUpcoming(int start, int max) { Check.Argument.IsNotNegative(start, "start"); Check.Argument.IsNotNegative(max, "max"); return(CurrentDataSource.GetUpcomingStories(start, max)); }
void TestStep(DateTime start, DateTime end) { TestStrategy.CurrentTime = end; AddInfo("test step, start:" + start.ToString() + ",end:" + end.ToString()); var dl = CurrentDataSource.GetDataList(InstrumentList, start, end, Grade); AddInfo("got market data ,count is:" + dl.Count.ToString()); if (dl == null || dl.Count == 0) { return; } TestStrategy.CurrentTime = dl.Max(d => d.Time); dl.ForEach(v => { var inst = InstrumentList.FirstOrDefault(i => i.Ticker == v.InstrumentTicker); if (inst != null) { AddInfo("update " + inst.Name + " price, value is:" + v.Close.ToString() + "(" + v.Time.ToString() + ")"); inst.CurrentPrice = v.Close; } }); MarketDataList.AddRange(dl); AddInfo("portfolio process market data!"); TargetPortfolio.ProcessMarketData(dl); AddInfo("standard portfolio process market data!"); standardPortfolio.ProcessMarketData(dl); AddInfo("strategy process market data!"); TestStrategy.ProcessMarketData(dl); if (analyseTime <= end) { AddInfo("prepare analyse, analyse time is:" + analyseTime.ToString()); AnalyseStep(); analyseTime = MarketData.GetNextTime(end, AnalyseGrade); var cl = new List <ISignal>(); foreach (var condition in ConditionList) { var rl = condition.GetResult(); if (rl != null && rl.Count > 0) { cl.AddRange(rl); } } if (cl.Count > 0) { AddInfo("got signal, count is " + cl.Count.ToString()); TestStrategy.ProcessSignal(cl); } } AddInfo("strategy process portfolio"); TestStrategy.ProcessPortfolio(); var ol = TestStrategy.GetOrderList(); if (ol.Count > 0) { AddInfo("strategy generate order, count is :" + ol.Count.ToString()); List <IOrder> col = new List <IOrder>(); foreach (var o in ol) { if (o != null && RiskPolicy.PredictOrder(o, TargetPortfolio)) { col.Add(o); } } OrderList.AddRange(col); AddInfo("trade gate process order"); CurrentTradeGate.ProcessorOrder(col); AddInfo("portfolio info before process order is" + GetPortfolioMemo(TargetPortfolio)); TargetPortfolio.ProcessOrderList(col); AddInfo("portfolio info after process order is" + GetPortfolioMemo(TargetPortfolio)); } if (!IsUnlimited)//adjust risk { AddInfo("adjust risk"); ol = RiskPolicy.AdjustRisk(TargetPortfolio); if (ol.Count > 0) { AddInfo("risk order generate, count is:" + ol.Count.ToString()); OrderList.AddRange(ol); List <IOrder> col = ol.Where(v => v != null).ToList(); CurrentTradeGate.ProcessorOrder(col); TargetPortfolio.ProcessOrderList(col); } } CurrentValueList.Add(new TimeValueObject() { Time = dl.Max(v => v.Time), Value = CurrentValue, Memo = GetPortfolioMemo(TargetPortfolio) }); StandardValueList.Add(new TimeValueObject() { Time = dl.Max(v => v.Time), Value = StandardValue, Memo = GetPortfolioMemo(standardPortfolio) }); if (_MaxLost.Number > Pnl.Number) { _MaxLost.Number = Pnl.Number; } if (TestStepDelayMS > 0) { Thread.Sleep(TestStepDelayMS); } }
public override void PrepareWork() { TargetPortfolio.PrepareWork(); MarketDataList.Clear(); CurrentDataSource.DataList.Clear(); CurrentValueList.Clear(); StandardValueList.Clear(); OrderList.Clear(); DateTime st = TestStartTime; if (TestStartTime > AnalyseStartTime) { st = AnalyseStartTime; } CurrentDataSource.CacheStartTime = st; CurrentDataSource.CacheEndTime = TestEndTime; TestCurrentTime = TestStartTime; analyseTime = MarketData.GetNextTime(TestCurrentTime, AnalyseGrade); _MaxLost = new Money() { FxCode = Pnl.FxCode, Number = 0 }; if (UseFirstMarketDataInit) { var fdl = new List <IMarketData>(); InstrumentList.ForEach(v => { var d = CurrentDataSource.GetFirstData(v, TestStartTime, TestEndTime, Grade); if (d != null) { fdl.Add(d); } }); TargetPortfolio.ProcessMarketData(fdl); TargetPortfolio.PositionList.ForEach(v => { var d = fdl.FirstOrDefault(m => m.InstrumentTicker == v.InstrumentTicker); if (d != null) { v.Cost = d.Close; } }); } if (IsUnlimited) { TargetPortfolio.IsUnlimited = true; } standardPortfolio = TargetPortfolio.Clone() as IPortfolio; testStartValue = TargetPortfolio.CurrentValue; CurrentDataSource.PrepareWork(); CurrentTradeGate.PrepareWork(); foreach (var condition in ConditionList) { condition.PrepareWork(); condition.GetInstrumentList = () => { return(InstrumentList); }; condition.AnalyseDataSource = CurrentDataSource; } TestStrategy.CurrentPortfolio = TargetPortfolio; TestStrategy.PrepareWork(); RiskPolicy.PrepareWork(); }