예제 #1
0
        protected override void OnOrderPartiallyFilled(SingleOrder order)
        {
            Instrument instrument = order.Instrument;
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnOrderPartiallyFilled(order);
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnOrderPartiallyFilled(order);
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnOrderPartiallyFilled(order);
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnOrderPartiallyFilled(order);
            }
            /*---------------------------------------*/

            /*this.runtimeCrossEntry.OnOrderPartiallyFilled(order);
            *           this.runtimeCrossExit.OnOrderPartiallyFilled(order);
            *           this.entries[instrument].OnOrderPartiallyFilled(order);
            *           this.exits[instrument].OnOrderPartiallyFilled(order);*/
        }
예제 #2
0
        internal SingleOrder EmitSignal(Signal signal)
        {
            signal.Strategy = this;
            MoneyManager moneyManager = this.moneyManagers[signal.Instrument];
            double       positionSize = moneyManager.GetPositionSize(signal);

            if (positionSize > 0.0)
            {
                signal.Qty = positionSize;
                RiskManager riskManager = this.riskManagers[signal.Instrument];
                if (!riskManager.Validate(signal))
                {
                    signal.Status   = SignalStatus.Rejected;
                    signal.Rejecter = ComponentType.RiskManager;
                }
                if (!this.exposureManager.Validate(signal))
                {
                    signal.Status   = SignalStatus.Rejected;
                    signal.Rejecter = ComponentType.ExposureManager;
                }
            }
            else
            {
                signal.Status   = SignalStatus.Rejected;
                signal.Rejecter = ComponentType.MoneyManager;
            }
            return(this.MetaStrategy.EmitSignal(signal));
        }
예제 #3
0
        protected override void OnExecutionReport(SingleOrder order, ExecutionReport report)
        {
            Instrument instrument = order.Instrument;
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnExecutionReport(order, report);
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnExecutionReport(order, report);
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnExecutionReport(order, report);
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnExecutionReport(order, report);
            }
            /*---------------------------------------*/

            /*this.runtimeCrossEntry.OnExecutionReport(order, report);
            *           this.runtimeCrossExit.OnExecutionReport(order, report);
            *           this.entries[instrument].OnExecutionReport(order, report);
            *           this.exits[instrument].OnExecutionReport(order, report);*/
        }
예제 #4
0
        protected override void OnPositionClosed(Position position)
        {
            foreach (Stop stop in new ArrayList(this.activeStops[position.Instrument]))
            {
                if ((stop.Type == StopType.Time && stop.Status == StopStatus.Active) || stop.Connected)
                {
                    stop.OnPositionClosed(position);
                }
            }
            this.runtimeCrossExit.OnPositionClosed(position);
            this.runtimeCrossEntry.OnPositionClosed(position);
            this.exposureManager.OnPositionClosed(position);
            Instrument instrument = position.Instrument;
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnPositionClosed();
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnPositionClosed();
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnPositionClosed();
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnPositionClosed();
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnPositionClosed();
             *          this.entries[instrument].OnPositionClosed();
             *          this.moneyManagers[instrument].OnPositionClosed();
             *          this.riskManagers[instrument].OnPositionClosed();*/
        }
예제 #5
0
        protected override void OnNewBar(Instrument instrument, Bar bar)
        {
            foreach (Stop stop in new ArrayList(this.activeStops[instrument]))
            {
                if (stop.Connected)
                {
                    stop.OnNewBar(bar);
                }
            }
            this.runtimeCrossExit.OnBar(instrument, bar);
            this.runtimeCrossEntry.OnBar(instrument, bar);
            this.marketManager.OnBar(instrument, bar);
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnBar(bar);
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnBar(bar);
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnBar(bar);
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnBar(bar);
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnBar(bar);
             *          this.entries[instrument].OnBar(bar);
             *          this.moneyManagers[instrument].OnBar(bar);
             *          this.riskManagers[instrument].OnBar(bar);*/
        }
예제 #6
0
        protected override void OnPortfolioValueChanged(Position position)
        {
            this.MetaStrategy.MetaRiskManager.OnStrategyPortfolioValueChanged(this);
            if (!this.isActive)
            {
                return;
            }
            this.runtimeCrossExit.OnPortfolioValueChanged(position);
            this.runtimeCrossEntry.OnPortfolioValueChanged(position);
            this.exposureManager.OnPortfolioValueChanged(position);
            Instrument instrument = position.Instrument;
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnPositionValueChanged();
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnPositionValueChanged();
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnPositionValueChanged();
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnPositionValueChanged();
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnPositionValueChanged();
             *          this.entries[instrument].OnPositionValueChanged();
             *          this.moneyManagers[instrument].OnPositionValueChanged();
             *          this.riskManagers[instrument].OnPositionValueChanged();*/
        }
예제 #7
0
 protected override void OnBehaviorInit()
 {
     this.entries.Clear();
     this.exits.Clear();
     this.moneyManagers.Clear();
     this.riskManagers.Clear();
     //把持仓中的证券添加到市场中来
     foreach (Position position in this.portfolio.Positions)
     {
         Instrument instrument = position.Instrument;
         this.marketManager.AddInstrument(instrument);
     }
     foreach (Instrument instrument in this.marketManager.Instruments)
     {
         this.activeInstruments.Add(instrument);
         Entry        entry        = Activator.CreateInstance(this.entry.GetType()) as Entry;
         Exit         exit         = Activator.CreateInstance(this.exit.GetType()) as Exit;
         MoneyManager moneyManager = Activator.CreateInstance(this.moneyManager.GetType()) as MoneyManager;
         RiskManager  riskManager  = Activator.CreateInstance(this.riskManager.GetType()) as RiskManager;
         entry.StrategyBase        = this;
         exit.StrategyBase         = this;
         moneyManager.StrategyBase = this;
         riskManager.StrategyBase  = this;
         entry.Instrument          = instrument;
         exit.Instrument           = instrument;
         moneyManager.Instrument   = instrument;
         riskManager.Instrument    = instrument;
         base.SetProxyProperties(entry, this.entry);
         base.SetProxyProperties(exit, this.exit);
         base.SetProxyProperties(moneyManager, this.moneyManager);
         base.SetProxyProperties(riskManager, this.riskManager);
         entry.Init();
         exit.Init();
         moneyManager.Init();
         riskManager.Init();
         this.entries.Add(instrument, entry);
         this.exits.Add(instrument, exit);
         this.moneyManagers.Add(instrument, moneyManager);
         this.riskManagers.Add(instrument, riskManager);
     }
 }
예제 #8
0
        protected override void OnPositionChanged(Position position)
        {
            this.runtimeCrossExit.OnPositionChanged(position);
            this.runtimeCrossEntry.OnPositionChanged(position);
            this.exposureManager.OnPositionChanged(position);
            Instrument instrument = position.Instrument;
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnPositionChanged();
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnPositionChanged();
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnPositionChanged();
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnPositionChanged();
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnPositionChanged();
             *          this.entries[instrument].OnPositionChanged();
             *          this.moneyManagers[instrument].OnPositionChanged();
             *          this.riskManagers[instrument].OnPositionChanged();*/
        }
예제 #9
0
        protected override void OnNewCorporateAction(Instrument instrument, CorporateAction corporateAction)
        {
            this.runtimeCrossExit.OnCorporateAction(instrument, corporateAction);
            this.runtimeCrossEntry.OnCorporateAction(instrument, corporateAction);
            this.marketManager.OnCorporateAction(instrument, corporateAction);
            this.exposureManager.OnCorporateAction(instrument, corporateAction);
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnCorporateAction(corporateAction);
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnCorporateAction(corporateAction);
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnCorporateAction(corporateAction);
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnCorporateAction(corporateAction);
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnCorporateAction(corporateAction);
             *          this.entries[instrument].OnCorporateAction(corporateAction);
             *          this.moneyManagers[instrument].OnCorporateAction(corporateAction);
             *          this.riskManagers[instrument].OnCorporateAction(corporateAction);*/
        }
예제 #10
0
        protected override void OnNewMarketDepth(Instrument instrument, MarketDepth marketDepth)
        {
            this.runtimeCrossExit.OnMarketDepth(instrument, marketDepth);
            this.runtimeCrossEntry.OnMarketDepth(instrument, marketDepth);
            this.marketManager.OnMarketDepth(instrument, marketDepth);
            /*---------------------------------------*/
            Exit exit = this.exits[instrument];

            if (exit != null)
            {
                exit.OnMarketDepth(marketDepth);
            }
            Entry entry = this.entries[instrument];

            if (entry != null)
            {
                entry.OnMarketDepth(marketDepth);
            }
            MoneyManager moneyManager = this.moneyManagers[instrument];

            if (moneyManager != null)
            {
                moneyManager.OnMarketDepth(marketDepth);
            }
            RiskManager riskManager = this.riskManagers[instrument];

            if (riskManager != null)
            {
                riskManager.OnMarketDepth(marketDepth);
            }
            /*---------------------------------------*/

            /*this.exits[instrument].OnMarketDepth(marketDepth);
             *          this.entries[instrument].OnMarketDepth(marketDepth);
             *          this.moneyManagers[instrument].OnMarketDepth(marketDepth);
             *          this.riskManagers[instrument].OnMarketDepth(marketDepth);*/
        }