Example #1
0
        public void Setup()
        {
            this._currencyConverterService = A.Fake <ICurrencyConverterService>();
            this._ruleCtx                = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._alertStream            = A.Fake <IUniverseAlertStream>();
            this._clustering             = new ClusteringService();
            this._equitiesParameters     = A.Fake <IWashTradeRuleEquitiesParameters>();
            this._logger                 = A.Fake <ILogger>();
            this._ruleRunRepository      = A.Fake <IRuleRunDataRequestRepository>();
            this._stubRuleRunRepository  = A.Fake <IStubRuleRunDataRequestRepository>();
            this._loggerEquityCache      = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >();
            this._loggerFixedIncomeCache = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >();
            this._tradingLogger          = A.Fake <ILogger <TradingHistoryStack> >();

            this._orderFilter   = A.Fake <IUniverseOrderFilter>();
            this._equityFactory = new UniverseEquityMarketCacheFactory(
                this._stubRuleRunRepository,
                this._ruleRunRepository,
                this._loggerEquityCache);
            this._fixedIncomeFactory = new UniverseFixedIncomeMarketCacheFactory(
                this._stubRuleRunRepository,
                this._ruleRunRepository,
                this._loggerFixedIncomeCache);
            A.CallTo(() => this._orderFilter.Filter(A <IUniverseEvent> .Ignored))
            .ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]);

            A.CallTo(() => this._equitiesParameters.PerformClusteringPositionAnalysis).Returns(true);
            A.CallTo(() => this._equitiesParameters.ClusteringPercentageValueDifferenceThreshold).Returns(0.05m);
        }
        /// <summary>
        /// The subscribe to parameters.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="alertStream">
        /// The alert stream.
        /// </param>
        /// <param name="universeDataRequestsSubscriber">
        /// The universe data requests subscriber.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule SubscribeToParameters(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseAlertStream alertStream,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            IWashTradeRuleEquitiesParameters parameters)
        {
            var ctx = operationContext.CreateAndStartRuleRunContext(
                Rules.WashTrade.GetDescription(),
                EquityRuleWashTradeFactory.Version,
                parameters.Id,
                (int)Rules.WashTrade,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var runMode             = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;
            var washTrade           = this.equityRuleWashTradeFactory.Build(parameters, ctx, alertStream, runMode);
            var washTradeOrgFactors = this.brokerServiceFactory.Build(
                washTrade,
                parameters.Factors,
                parameters.AggregateNonFactorableIntoOwnCategory);

            var washTradeFiltered = this.DecorateWithFilter(
                operationContext,
                parameters,
                washTradeOrgFactors,
                universeDataRequestsSubscriber,
                ctx,
                runMode);

            return(washTradeFiltered);
        }
Example #3
0
        public IWashTradeRule Build(
            IWashTradeRuleEquitiesParameters equitiesParameters,
            ISystemProcessOperationRunRuleContext ruleCtx,
            IUniverseAlertStream alertStream,
            RuleRunMode runMode)
        {
            if (ruleCtx == null)
            {
                throw new ArgumentNullException(nameof(ruleCtx));
            }

            if (equitiesParameters == null)
            {
                throw new ArgumentNullException(nameof(equitiesParameters));
            }

            return(new WashTradeRule(
                       equitiesParameters,
                       ruleCtx,
                       this._clustering,
                       alertStream,
                       this._currencyConverterService,
                       this._orderFilterService,
                       this._equityFactory,
                       this._fixedIncomeFactory,
                       runMode,
                       this._logger,
                       this._tradingHistoryLogger));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WashTradeRule"/> class.
 /// </summary>
 /// <param name="equitiesParameters">
 /// The equities parameters.
 /// </param>
 /// <param name="ruleContext">
 /// The rule context.
 /// </param>
 /// <param name="clustering">
 /// The clustering.
 /// </param>
 /// <param name="alertStream">
 /// The alert stream.
 /// </param>
 /// <param name="currencyConverterService">
 /// The currency converter service.
 /// </param>
 /// <param name="orderFilter">
 /// The order filter.
 /// </param>
 /// <param name="equityMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="fixedIncomeMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="runMode">
 /// The run mode.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="tradingHistoryLogger">
 /// The trading history logger.
 /// </param>
 public WashTradeRule(
     IWashTradeRuleEquitiesParameters equitiesParameters,
     ISystemProcessOperationRunRuleContext ruleContext,
     IClusteringService clustering,
     IUniverseAlertStream alertStream,
     ICurrencyConverterService currencyConverterService,
     IUniverseOrderFilter orderFilter,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     RuleRunMode runMode,
     ILogger logger,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
     : base(
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1),
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1),
         equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero,
         Rules.WashTrade,
         EquityRuleWashTradeFactory.Version,
         "Wash Trade Rule",
         ruleContext,
         equityMarketCacheFactory,
         fixedIncomeMarketCacheFactory,
         runMode,
         logger,
         tradingHistoryLogger)
 {
     this.equitiesParameters =
         equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters));
     this.clustering = clustering ?? throw new ArgumentNullException(nameof(clustering));
     this.currencyConverterService =
         currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
     this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter));
     this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream));
     this.logger      = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        /// <summary>
        /// The decorate with filter.
        /// </summary>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="washTrade">
        /// The wash trade.
        /// </param>
        /// <param name="universeDataRequestsSubscriber">
        /// The universe data requests subscriber.
        /// </param>
        /// <param name="processOperationRunRuleContext">
        /// The process operation run rule context.
        /// </param>
        /// <param name="ruleRunMode">
        /// The rule run mode.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule DecorateWithFilter(
            ISystemProcessOperationContext operationContext,
            IWashTradeRuleEquitiesParameters parameters,
            IUniverseRule washTrade,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            ISystemProcessOperationRunRuleContext processOperationRunRuleContext,
            RuleRunMode ruleRunMode)
        {
            if (parameters.HasInternalFilters() || parameters.HasReferenceDataFilters() || parameters.HasMarketCapFilters() ||
                parameters.HasVenueVolumeFilters())
            {
                this.logger.LogInformation($"parameters had filters. Inserting filtered universe in {operationContext.Id} OpCtx");

                var filteredUniverse = this.universeFilterFactory.Build(
                    washTrade,
                    parameters.Accounts,
                    parameters.Traders,
                    parameters.Markets,
                    parameters.Funds,
                    parameters.Strategies,
                    parameters.Sectors,
                    parameters.Industries,
                    parameters.Regions,
                    parameters.Countries,
                    parameters.MarketCapFilter,
                    ruleRunMode,
                    "Wash Trade Equity",
                    universeDataRequestsSubscriber,
                    processOperationRunRuleContext);

                var decoratedFilter = filteredUniverse;

                if (parameters.HasVenueVolumeFilters())
                {
                    decoratedFilter = this.decoratorFilterFactory.Build(
                        parameters.Windows,
                        filteredUniverse,
                        parameters.VenueVolumeFilter,
                        processOperationRunRuleContext,
                        universeDataRequestsSubscriber,
                        this.DataSourceForWindow(parameters.Windows),
                        ruleRunMode);
                }

                decoratedFilter.Subscribe(washTrade);

                return(decoratedFilter);
            }

            return(washTrade);
        }
        public void Setup()
        {
            this._currencyConverterService = A.Fake <ICurrencyConverterService>();
            this._clustering           = A.Fake <IClusteringService>();
            this._orderFilterService   = A.Fake <IUniverseEquityOrderFilterService>();
            this._equityFactory        = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeFactory   = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._logger               = new NullLogger <WashTradeRule>();
            this._tradingHistoryLogger = new NullLogger <TradingHistoryStack>();

            this._equitiesParameters = A.Fake <IWashTradeRuleEquitiesParameters>();
            this._ruleCtx            = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._alertStream        = A.Fake <IUniverseAlertStream>();
        }