Exemplo n.º 1
0
        public void Optimize()
        {
            if (true)
            {
                IComponentBase ic;

                meta  = new ATSMetaStrategy("metagp");
                strat = new ATSStrategy("ATS", "Test ATS Strategy");

                //StrategyComponentManager.RegisterDefaultComponent(typeof(atscQT));
                //ic = StrategyComponentManager.GetComponent("{1bffce05-3830-484b-aabc-21297ab3fc2a}", this);
                //strat.SetComponent(ComponentType.ATSComponent, ic);

                StrategyComponentManager.RegisterDefaultComponent(typeof(atscPivot));
                ic = StrategyComponentManager.GetComponent("{55e7fcd2-3e34-4218-8d01-571c6c54fb4d}", this);
                strat.SetComponent(ComponentType.ATSComponent, ic);

                StrategyComponentManager.RegisterDefaultComponent(typeof(mktSingle));
                ic = StrategyComponentManager.GetComponent("{0c19f913-f3e5-4c53-9908-4b87403f0616}", this);
                strat.SetComponent(ComponentType.MarketManager, ic);

                //StrategyComponentManager.RegisterDefaultComponent(typeof(mktToTrade));
                //ic = StrategyComponentManager.GetComponent("{f6e7b160-1d92-4f46-af68-8d451783addc}", this);
                //strat.SetComponent(ComponentType.MarketManager, ic);

                meta.Add(strat);
                Console.WriteLine("meta.strategies.count {0}", meta.Strategies.Count);

                StrategyComponentManager.RegisterDefaultComponent(typeof(simQuotesAndTicks));
                ic = StrategyComponentManager.GetComponent("{52728743-527f-4e40-a128-dd37387e6304}", this);
                meta.SetComponent(ComponentType.SimulationManager, ic);

                meta.MetaStrategyMode = MetaStrategyMode.Simulation;
                meta.SimulationManager.Init();

                meta.OptimizationManager = new optimizer();
                //meta.Optimizer = new BruteForceTest(meta);
                meta.Optimizer     = new GPOptimizer(meta);
                meta.OptimizerType = EOptimizerType.GeneticAlgorithm;

                meta.Optimizer.UpdateCalled          += new EventHandler(Optimizer_UpdateCalled);
                meta.Optimizer.StepCalled            += new EventHandler(Optimizer_StepCalled);
                meta.Optimizer.ObjectiveCalled       += new EventHandler(Optimizer_ObjectiveCalled);
                meta.Optimizer.Inited                += new EventHandler(Optimizer_Inited);
                meta.Optimizer.BestObjectiveReceived += new EventHandler(Optimizer_BestObjectiveRecieved);
                meta.Optimizer.CircleCalled          += new EventHandler(Optimizer_CircleCalled);

                meta.GetOptimizationParameters();

                meta.Started += new EventHandler(meta_Started);
                meta.Stopped += new EventHandler(meta_Stopped);

                //meta.DesignMode = false;
                meta.Optimize();
            }
        }
Exemplo n.º 2
0
    public override void Init()
    {
        //Console.WriteLine("We are in atscQT init.");

        //if (null == instrument) return;

        strat = base.Strategy;
        ms    = strat.ATSMetaStrategy;
        mm    = strat.MarketManager;

        dsZero       = new DoubleSeries("Zero");
        dsZero.Color = Color.Black;

        //individual = (Individual) strat.Global[ "Individual" ];
        GPOptimizer gpo = (GPOptimizer)ms.Optimizer;

        individual = gpo.curIndividual;


        //gpstrategy.EmitSignalInit(this);
        bars = new BarSeries("Bars");

        dsTrade           = new DoubleSeries("Trades");
        smaTrades         = new SMA(dsTrade, intTradeSmoothing);
        dsTradeVolume     = new DoubleSeries("Trade Volume");
        dsBid             = new DoubleSeries("Bid");
        dsAsk             = new DoubleSeries("Ask");
        dsBidAskSpread    = new DoubleSeries("Bid Ask Spread");
        smaBidAskSpread   = new SMA(dsBidAskSpread, intBidAskSpreadSmoothing);
        dsBidAskMidPoint  = new DoubleSeries("Bid Ask Midpoint");
        smaBidAskMidPoint = new SMA(dsBidAskMidPoint, intBidAskSmoothing);

        dsBidAskKama0 = new DoubleSeries("Bid Ask Kama 0");
        dsBidAskKama1 = new DoubleSeries("Bid Ask Kama 1");

        dsTradeER0 = new DoubleSeries("Trade ER 0");
        dsTradeER1 = new DoubleSeries("Trade ER 1");

        //dsBidAskER0 = new DoubleSeries("Bid Ask ER 0");
        //dsBidAskER1 = new DoubleSeries("Bid Ask ER 1");

        dsReturns = new DoubleSeries("Trade Returns");

        stats      = new Statistics(dsTrade);
        dsKurtosis = new DoubleSeries("Kurtosis");
        dsSkew     = new DoubleSeries("Skew");



        /*
         * dtCurrentDay = new DateTime(0);
         * try {
         * daily = DataManager.GetDailySeries(this.instrument);
         * }
         * catch {
         * new Exception("couldn't load ds for instrument " + instrument.Symbol);
         * }
         */

        DateTime dtStartingDate;

        if (MetaStrategyMode.Live == strat.ATSMetaStrategy.MetaStrategyMode)
        {
            dtStartingDate = DateTime.Today;
            string      prov    = "IQFeed";
            IBarFactory factory = ProviderManager.MarketDataProviders[prov].BarFactory;
            factory.Items.Clear();
            factory.Items.Add(new BarFactoryItem(BarType.Time, 60, true));

            instrument.RequestMarketData(
                ProviderManager.MarketDataProviders[prov], MarketDataType.Quote);
            instrument.RequestMarketData(
                ProviderManager.MarketDataProviders[prov], MarketDataType.Trade);

            tsStart = new TimeSpan(10, 30, 0);
            tsStop  = new TimeSpan(16, 55, 0);
        }
        else
        {
            dtStartingDate = strat.MetaStrategyBase.SimulationManager.EntryDate;
            IBarFactory factory = ProviderManager.MarketDataProviders[1].BarFactory;
            factory.Items.Clear();
            factory.Items.Add(new BarFactoryItem(BarType.Time, 60, true));

            tsStart = new TimeSpan(9, 30, 0);
            tsStop  = new TimeSpan(15, 55, 0);
        }

        //Console.WriteLine( "StartingDate {0}", dtStartingDate );
        dtCurrentDay = dtStartingDate.Date;

        /*
         * Bar barDay1;
         *
         * int i = daily.GetIndex(dtStartingDate.Date, EIndexOption.Prev);
         * barDay1 = daily[i];
         * if (barDay1.DateTime.Date == dtStartingDate.Date) {
         * i--; // realtime will come up with different one from simulation, depending upon what is dateset
         * // ie, there is no bar or information for today, only the previous trading day
         * barDay1 = daily[i];
         * }
         */
    }