Пример #1
0
        public override void Run()
        {
            MulticoreOptimizer optimizer = new MulticoreOptimizer();

            OptimizationUniverse universe = new OptimizationUniverse();

            for (int length1 = 2; length1 < 14; length1++)
            {
                for (int length2 = length1 + 1; length2 < 28; length2++)
                {
                    OptimizationParameterSet parameter = new OptimizationParameterSet();

                    parameter.Add("Length1", length1);
                    parameter.Add("Length2", length2);
                    parameter.Add("Bar", (long)60);

                    universe.Add(parameter);
                }
            }

            strategy = new SMACrossover(framework, "strategy ");

            Instrument instrument1 = InstrumentManager.Instruments["AAPL"];
            Instrument instrument2 = InstrumentManager.Instruments["MSFT"];

            InstrumentList instruments = new InstrumentList();

            instruments.Add(instrument1);
            instruments.Add(instrument2);

            DataSimulator.DateTime1 = new DateTime(2013, 12, 01);
            DataSimulator.DateTime2 = new DateTime(2013, 12, 31);

            optimizer.Optimize(strategy, instruments, universe, 100);
        }
Пример #2
0
        private void ctxPanel_Remove_Click(object sender, EventArgs e)
        {
            InstrumentList instrumentList = new InstrumentList();

            foreach (InstrumentRow instrumentRow in (BaseCollection)this.dgvPanel.SelectedRows)
            {
                instrumentList.Add(instrumentRow.Instrument);
            }
            if (((FIXGroupList)instrumentList).Count <= 0 || MessageBox.Show("Do you want to remove selected instruments?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            IEnumerator enumerator = ((FIXGroupList)instrumentList).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    this.RemoveInstrument((Instrument)enumerator.Current);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Пример #3
0
        public override IEnumerable <Quote> GetQuoteList(string accountId, string mode)
        {
            //This need to be changed to PRICE API
            //TODO *******************************************************


            List <TDMData> instrList = null;
            List <Quote>   result    = new List <Quote>();
            Quote          q         = null;

            string[] tickerList = this.GetTickerList();
            for (int i = 0; i < tickerList.Length; i++)
            {
                instrList = GetInstrumentList(tickerList[i]);
                if (instrList == null)
                {
                    instrList = GetSymbolPriceList(tickerList[i], (DateTime.Now.AddDays(-5)));
                    InstrumentList.Add(tickerList[i], instrList);
                }
                q        = new Quote();
                q.Symbol = tickerList[i];
                if (mode == Constants.OrderAction.BUY)
                {
                    q.LastBuyTradePrice = GetCurrentBuyPrice(q.Symbol);
                }
                else if (mode == Constants.OrderAction.SELL)
                {
                    q.LastSellTradePrice = GetCurrentSellPrice(q.Symbol);
                }

                result.Add(q);
            }
            return(result);
        }
Пример #4
0
 public override void Subscribe(Instrument instrument)
 {
     if (!subscribbed.Contains(instrument))
     {
         subscribbed.Add(instrument);
     }
 }
        void LoadFromDB()
        {
            var connectionStr = ConfigurationManager.ConnectionStrings["MarketDataConnectionString"];

            using (var conn = new SqlConnection(connectionStr.ConnectionString))
            {
                conn.Open();
                var rl = conn.Query <Instrument>("Select * from Table_Instruments", new { }, null, true, 60000).ToList();
                InstrumentList.Clear();
                foreach (var r in rl)
                {
                    r.Ticker    = r.Ticker.Trim();
                    r.Currency  = r.Currency.Trim();
                    r.Industory = r.Industory.Trim();
                    r.Name      = r.Name.Trim();
                    r.Region    = r.Region.Trim();
                    if (r.Memo != null)
                    {
                        r.Memo = r.Memo.Trim();
                    }

                    InstrumentList.Add(r);
                }
            }
            ClearChangedFlag();
        }
 void Load(DistributeAnalyse obj)
 {
     TargetObject = obj;
     InstrumentList.Clear();
     TargetObject.InstrumentList.ForEach(v => InstrumentList.Add(v));
     SectorList.Clear();
     TargetObject.SectorList.ForEach(v => SectorList.Add(v));
     CurrentDataSource = TargetObject.CurrentDataSource;
 }
Пример #7
0
 public void Init()
 {
     AllInstrumentList.Clear();
     InstrumentList.Clear();
     Instrument.AllInstrumentList.ForEach(r =>
     {
         AllInstrumentList.Add(r);
         InstrumentList.Add(r);
     });
 }
Пример #8
0
        public int SetInstrumentInfo(string s)
        {
            var l = CommonLib.CommonProc.ConvertStringToObject <List <Instrument> >(s);

            if (l == null || l.Count == 0)
            {
                return(0);
            }
            InstrumentList.Clear();
            l.ForEach(v => InstrumentList.Add(v));
            return(l.Count);
        }
Пример #9
0
 public void Clear()
 {
     foreach (var i in Instruments)
     {
         i.Bid = null;
         i.Ask = null;
         i.Trade = null;
         i.Bar = null;
     }
     var deleted = new InstrumentList();
     foreach (var i in Instruments.Where(i => !i.Loaded))
         deleted.Add(i);
     foreach (var i in deleted)
         Delete(i);
 }
        void LoadFromFile()
        {
            var dlg = new OpenFileDialog()
            {
                Filter = "Text File|*.txt|Csv File|*.CSV| (*.*)|*.*"
            };

            if (dlg.ShowDialog() == true)
            {
                var ep  = new ReportCommonLib.ReportExportHelper();
                var dic = ep.LoadMappingFile(System.AppDomain.CurrentDomain.BaseDirectory + "MarketDataSupport\\InstrumentMapping.txt");
                var l   = ep.LoadFromCsvFile <InstrumentModel>(dlg.FileName, Encoding.GetEncoding("GB18030")  , GetSeperateChar(), dic , preProcess);
                InstrumentList.Clear();
                l.ForEach(v => InstrumentList.Add(v));
            }
            ClearChangedFlag();
        }
Пример #11
0
        public override IEnumerable <Quote> GetQuoteList(string[] tickerList, string accountId)
        {
            List <TDM_Instrument> instrList = null;
            List <Quote>          result    = new List <Quote>();
            Quote q = null;

            if (tickerList == null)
            {
                tickerList = this.GetTickerList();
            }
            for (int i = 0; i < tickerList.Length; i++)
            {
                instrList = ExchangeObject.GetSymbolPriceList(tickerList[i], DateTime.Now);
                InstrumentList.Add(tickerList[i], instrList);
                q                = new Quote();
                q.Symbol         = tickerList[i];
                q.LastTradePrice = instrList[0].BuyPrice;
                result.Add(q);
            }
            return(result);
        }
Пример #12
0
        public override void LoadInfo()
        {
            if (TargetProject == null)
            {
                return;
            }

            ConditionList.Clear();
            TargetProject.ConditionList.ForEach(v => ConditionList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));
            InstrumentList.Clear();
            TargetProject.InstrumentList.ForEach(v => InstrumentList.Add(v));
            CurrentStrategy   = TargetProject.TestStrategy;
            CurrentTradeGate  = TargetProject.CurrentTradeGate;
            CurrentDataSource = TargetProject.CurrentDataSource;
            IsChanged         = false;
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
        }
Пример #13
0
 public void Filter(string filter)
 {
     InstrumentList.Clear();
     if (!string.IsNullOrEmpty(filter))
     {
         GetTargetProject().InstrumentList.ForEach(v =>
         {
             if (v.Ticker.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
                 v.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
                 v.PYName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
             {
                 InstrumentList.Add(v);
             }
         });
     }
     else
     {
         GetTargetProject().InstrumentList.ForEach(v =>
         {
             InstrumentList.Add(v);
         });
     }
 }
Пример #14
0
        public override void LoadInfo()
        {
            if (TargetProject == null)
            {
                return;
            }
            ConditionList.Clear();
            TargetProject.ConditionList.ForEach(v => ConditionList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));
            PredicateList.Clear();
            TargetProject.PredicateList.ForEach(v => PredicateList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));

            InstrumentList.Clear();
            TargetProject.InstrumentList.ForEach(v => InstrumentList.Add(v));
            ResultList.Clear();
            TargetProject.ResultList.ForEach(v => ResultList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            TargetProject.BlockList.ForEach(v => BlockList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            CurrentDataSource = TargetProject.CurrentDataSource;

            IsChanged = false;
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
        }
Пример #15
0
 public void Unsubscribe(IDataProvider provider, InstrumentList instruments)
 {
     InstrumentList instrumentList = new InstrumentList();
     for (int i = 0; i < instruments.Count; i++)
     {
         Instrument byIndex = instruments.GetByIndex(i);
         Dictionary<Instrument, int> dictionary;
         Instrument key;
         (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] - 1;
         if (this.subscriptions[(int)provider.Id][byIndex] == 0)
         {
             instrumentList.Add(byIndex);
         }
     }
     provider.Unsubscribe(instrumentList);
 }
Пример #16
0
 /// <summary>
 /// Event fired when UnsubscriptionArrives
 /// </summary>
 /// <param name="unsubscribe"></param>
 public void UnsubscriptionArrived(Unsubscribe unsubscribe)
 {
     InstrumentList.Add(unsubscribe.Security);
     OnSearchChanged(Search);
 }
Пример #17
0
 public void RemoveInstrument(Instrument instrument)
 {
     this.instruments.Remove(instrument);
     InstrumentList instrumentList = new InstrumentList();
     instrumentList.Add(instrument);
     this.framework.strategyManager.UnregisterMarketDataRequest(this.GetDataProvider(this, instrument), instrumentList);
     if (this.parent != null)
     {
         this.parent.UnregisterStrategy(this, instrumentList, (int)this.id);
     }
 }
Пример #18
0
 private void RegisterInstrument(Instrument instrument)
 {
     InstrumentList instrumentList = new InstrumentList();
     instrumentList.Add(instrument);
     IDataProvider dataProvider = this.GetDataProvider(this, instrument);
     IExecutionProvider executionProvider = this.GetExecutionProvider(instrument);
     if (dataProvider.Status == ProviderStatus.Disconnected)
     {
         dataProvider.Connect();
     }
     if (executionProvider.Status == ProviderStatus.Disconnected)
     {
         executionProvider.Connect();
     }
     this.framework.strategyManager.RegisterMarketDataRequest(dataProvider, instrumentList);
     if (this.parent != null)
     {
         this.parent.RegisterStrategy(this, instrumentList, (int)this.id);
     }
 }
Пример #19
0
        public void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            lock (this)
            {
                this.subscriptions.Clear();
                Strategy = strategy;
                Mode = mode;
                if (this.framework.Mode == FrameworkMode.Simulation)
                {
                    this.framework.Clock.DateTime = this.framework.ProviderManager.DataSimulator.DateTime1;
                    this.framework.ExchangeClock.DateTime = DateTime.MinValue;
                }
                if (this.framework.EventManager.Status != EventManagerStatus.Running)
                    this.framework.EventManager.Start();

                SetStatusType(StrategyStatusType.Started);
                if (Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Load)
                {
                    this.framework.PortfolioManager.Load(strategy.Name);
                    this.framework.OrderManager.Load(strategy.Name, -1);
                    this.framework.OrderServer.SeriesName = strategy.Name;
                    this.framework.OrderManager.IsPersistent = true;
                }
                else
                {
                    this.framework.OrderManager.IsPersistent = false;
                }

                strategy.Init();

                if ((Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Save) && !strategy.Portfolio.IsLoaded)
                    this.framework.PortfolioManager.Save(strategy.Portfolio);
              
                strategy.EmitStrategyStart();

                if (!this.framework.IsExternalDataQueue)
                {
                    var dictionary = new Dictionary<IDataProvider, InstrumentList>();
                    while (this.subscriptions.Count != 0)
                    {
                        var dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.subscriptions);
                        this.subscriptions.Clear();
                        foreach (var current in dictionary2)
                        {
                            InstrumentList instrumentList = null;
                            if (!dictionary.TryGetValue(current.Key, out instrumentList))
                            {
                                instrumentList = new InstrumentList();
                                dictionary[current.Key] = instrumentList;
                            }
                            InstrumentList instrumentList2 = new InstrumentList();
                            foreach (Instrument current2 in current.Value)
                            {
                                if (!instrumentList.Contains(current2))
                                {
                                    instrumentList.Add(current2);
                                    instrumentList2.Add(current2);
                                }
                            }
                            if (current.Key is SellSideStrategy)
                            {
                                this.framework.SubscriptionManager?.Subscribe(current.Key, instrumentList2);
                            }
                        }
                    }
                    SetParametersGroup();
                    Status = StrategyStatus.Running;
                    this.subscriptions = dictionary;
                    if (this.subscriptions.Count == 0 && mode == StrategyMode.Backtest)
                    {
                        Console.WriteLine($"{DateTime.Now } StrategyManager::StartStrategy {strategy.Name} has no data requests in backtest mode, stopping...");
                        StopStrategy();
                    }
                    else
                    {
                        foreach (var current3 in this.subscriptions)
                        {
                            if (!(current3.Key is SellSideStrategy))
                                this.framework.SubscriptionManager?.Subscribe(current3.Key, current3.Value);
                        }
                        if (mode != StrategyMode.Backtest)
                            strategy.FundamentalProvider?.Connect();
                    }
                }
                else
                {
                    SetParametersGroup();
                    Status = StrategyStatus.Running;
                }
            }
        }
Пример #20
0
		public void Clear()
		{
			foreach (Instrument current in this.instruments)
			{
				current.bid = null;
				current.ask = null;
				current.trade = null;
			}
			InstrumentList instrumentList = new InstrumentList();
			foreach (Instrument current2 in this.instruments)
			{
				if (!current2.isPersistent)
				{
					instrumentList.Add(current2);
				}
			}
			foreach (Instrument current3 in instrumentList)
			{
				this.Delete(current3);
			}
		}
Пример #21
0
 public void Subscribe(IDataProvider provider, InstrumentList instruments)
 {
     if (provider.Status != ProviderStatus.Connected)
     {
         provider.Connect();
     }
     InstrumentList instrumentList = new InstrumentList();
     for (int i = 0; i < instruments.Count; i++)
     {
         Instrument byIndex = instruments.GetByIndex(i);
         if (!this.subscriptions.ContainsKey((int)provider.Id))
         {
             this.subscriptions[(int)provider.Id] = new Dictionary<Instrument, int>();
         }
         if (!this.subscriptions[(int)provider.Id].ContainsKey(byIndex) || this.subscriptions[(int)provider.Id][byIndex] == 0)
         {
             this.subscriptions[(int)provider.Id][byIndex] = 0;
             instrumentList.Add(byIndex);
         }
         Dictionary<Instrument, int> dictionary;
         Instrument key;
         (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] + 1;
     }
     if (instrumentList.Count > 0)
     {
         provider.Subscribe(instrumentList);
     }
 }
Пример #22
0
 public void RegisterMarketDataRequest(IDataProvider dataProvider, InstrumentList instrumentList)
 {
     InstrumentList instrumentList2 = new InstrumentList();
     InstrumentList instrumentList3 = null;
     if (!this.requests.TryGetValue(dataProvider, out instrumentList3))
     {
         instrumentList3 = new InstrumentList();
         this.requests[dataProvider] = instrumentList3;
     }
     foreach (Instrument current in instrumentList)
     {
         if (!instrumentList3.Contains(current.id))
         {
             instrumentList3.Add(current);
             instrumentList2.Add(current);
         }
     }
     if (this.status == StrategyStatus.Running && instrumentList2.Count > 0 && this.framework.SubscriptionManager != null)
     {
         this.framework.SubscriptionManager.Subscribe(dataProvider, instrumentList2);
     }
 }
        void New()
        {
            var instrument = new InstrumentModel();

            InstrumentList.Add(instrument);
        }
Пример #24
0
        public override void Run()
        {
            MulticoreOptimizer optimizer = new MulticoreOptimizer(this.framework);


            OptimizationUniverse universe = new OptimizationUniverse();

            for (decimal Delta = 1; Delta < 8; Delta++)
            {
                OptimizationParameterSet parameter = new OptimizationParameterSet();

                parameter.Add("Delta", Delta);

                universe.Add(parameter);
            }
            Instrument spreadInsturment = InstrumentManager.Get("*NG 01-15 vs *NG 02-15");

            // Add spread instrument if needed.
            if (spreadInsturment == null)
            {
                spreadInsturment = new Instrument(InstrumentType.Future, "*NG 01-15 vs *NG 02-15");

                InstrumentManager.Add(spreadInsturment);
            }

            spreadInsturment.Legs.Clear();

            // Add legs for spread instrument if needed.
            if (spreadInsturment.Legs.Count == 0)
            {
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("*NG 01-15"), 1));
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("*NG 02-15"), 1));
            }

            // Main strategy.
            strategy = new Strategy(framework, "SpreadTrading");

            // Create BuySide strategy and add trading instrument.
            MyStrategy buySide = new MyStrategy(framework, "BuySide");

            buySide.Instruments.Add(spreadInsturment);

            // Create SellSide strategy.
            SpreadSellSide sellSide = new SpreadSellSide(framework, "SellSide");

            //sellSide.Global[SpreadSellSide.barSizeCode] = barSize;

            // Set SellSide as data and execution provider for BuySide strategy.
            buySide.DataProvider      = sellSide;
            buySide.ExecutionProvider = sellSide;

            // Add strategies to main.
            strategy.AddStrategy(buySide);
            strategy.AddStrategy(sellSide);

            // Set DataSimulator's dates.
            DataSimulator.DateTime1 = new DateTime(2014, 11, 18);            // 1 day before real start
            DataSimulator.DateTime2 = new DateTime(2014, 12, 30);            // 1 day after real end

            InstrumentList instruments = new InstrumentList();

            instruments.Add(spreadInsturment);

            strategy.AddInstruments(instruments);

            //You can choose an optimization method from the "Optimizers" window
            //and observe the optimization results in the "Optimization Results" window.

            //Optimization can use either of two ways to declare parameters:

            //1. Optimization using [OptimizationParameter] atrributes from Strategy

            //Optimize(strategy);

            //2. Optimization via OptimizationUniverse
            optimizer.Optimize(strategy, universe);
        }
Пример #25
0
 public void StartStrategy(Strategy strategy, StrategyMode mode)
 {
     this.strategy = strategy;
     if (mode == StrategyMode.Backtest)
     {
         this.framework.Mode = FrameworkMode.Simulation;
     }
     else
     {
         this.framework.Mode = FrameworkMode.Realtime;
     }
     if (this.framework.eventManager.status != EventManagerStatus.Running)
     {
         this.framework.eventManager.Start();
     }
     StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started);
     strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name);
     strategyStatusInfo.Mode = mode.ToString();
     this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null));
     strategy.OnStrategyStart_();
     if (!this.framework.IsExternalDataQueue)
     {
         Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>();
         while (this.requests.Count != 0)
         {
             Dictionary<IDataProvider, InstrumentList> dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.requests);
             this.requests.Clear();
             foreach (KeyValuePair<IDataProvider, InstrumentList> current in new Dictionary<IDataProvider, InstrumentList>(dictionary2))
             {
                 InstrumentList instrumentList = null;
                 if (!dictionary.TryGetValue(current.Key, out instrumentList))
                 {
                     instrumentList = new InstrumentList();
                     dictionary[current.Key] = instrumentList;
                 }
                 InstrumentList instrumentList2 = new InstrumentList();
                 foreach (Instrument current2 in current.Value)
                 {
                     if (!instrumentList.Contains(current2))
                     {
                         instrumentList.Add(current2);
                         instrumentList2.Add(current2);
                     }
                 }
                 if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null)
                 {
                     this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2);
                 }
             }
         }
         this.status = StrategyStatus.Running;
         this.requests = dictionary;
         if (this.requests.Count == 0)
         {
             Console.WriteLine(string.Concat(new object[]
             {
                 DateTime.Now,
                 " StrategyManager::StartStrategy ",
                 strategy.Name,
                 " has no data requests, stopping..."
             }));
             this.StopStrategy();
             return;
         }
         foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in this.requests)
         {
             if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null)
             {
                 this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value);
             }
         }
     }
 }
Пример #26
0
        public override void Run()
        {
            MulticoreOptimizer optimizer = new MulticoreOptimizer();

            OptimizationUniverse universe = new OptimizationUniverse();

            for (int length1 = 2; length1 < 14; length1++)
                for (int length2 = length1 + 1; length2 < 28; length2++)
                {
                    OptimizationParameterSet parameter = new OptimizationParameterSet();

                    parameter.Add("Length1", length1);
                    parameter.Add("Length2", length2);
                    parameter.Add("Bar", (long)60);

                    universe.Add(parameter);
                }

            strategy = new SMACrossover(framework, "strategy ");

            Instrument instrument1 = InstrumentManager.Instruments["AAPL"];
            Instrument instrument2 = InstrumentManager.Instruments["MSFT"];

            InstrumentList instruments = new InstrumentList();

            instruments.Add(instrument1);
            instruments.Add(instrument2);

            DataSimulator.DateTime1 = new DateTime(2013, 12, 01);
            DataSimulator.DateTime2 = new DateTime(2013, 12, 31);

            optimizer.Optimize(strategy, instruments, universe, 100);
        }