Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayeringRule"/> class.
 /// </summary>
 /// <param name="equitiesParameters">
 /// The equities parameters.
 /// </param>
 /// <param name="alertStream">
 /// The alert stream.
 /// </param>
 /// <param name="orderFilter">
 /// The order filter.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="equityMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="fixedIncomeMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="tradingHoursService">
 /// The trading hours service.
 /// </param>
 /// <param name="operationContext">
 /// The op context.
 /// </param>
 /// <param name="runMode">
 /// The run mode.
 /// </param>
 /// <param name="tradingHistoryLogger">
 /// The trading history logger.
 /// </param>
 public LayeringRule(
     ILayeringRuleEquitiesParameters equitiesParameters,
     IUniverseAlertStream alertStream,
     IUniverseOrderFilter orderFilter,
     ILogger logger,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     IMarketTradingHoursService tradingHoursService,
     ISystemProcessOperationRunRuleContext operationContext,
     RuleRunMode runMode,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
     : base(
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20),
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20),
         equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero,
         Domain.Surveillance.Scheduling.Rules.Layering,
         EquityRuleLayeringFactory.Version,
         "Layering Rule",
         operationContext,
         equityMarketCacheFactory,
         fixedIncomeMarketCacheFactory,
         runMode,
         logger,
         tradingHistoryLogger)
 {
     this.equitiesParameters  = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters));
     this.logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this.ruleContext         = operationContext ?? throw new ArgumentNullException(nameof(operationContext));
     this.alertStream         = alertStream ?? throw new ArgumentNullException(nameof(alertStream));
     this.orderFilter         = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter));
 }
Beispiel #2
0
 public LayeringRuleBreach(
     IFactorValue factorValue,
     ISystemProcessOperationContext operationContext,
     string correlationId,
     ILayeringRuleEquitiesParameters equitiesParameters,
     TimeSpan window,
     ITradePosition trades,
     FinancialInstrument security,
     RuleBreachDescription bidirectionalTradeBreach,
     RuleBreachDescription dailyVolumeTradeBreach,
     RuleBreachDescription windowVolumeTradeBreach,
     RuleBreachDescription priceMovementBreach,
     string description,
     string caseTitle,
     DateTime universeDateTime)
 {
     this.FactorValue              = factorValue;
     this.EquitiesParameters       = equitiesParameters;
     this.Window                   = window;
     this.Trades                   = trades;
     this.Security                 = security;
     this.BidirectionalTradeBreach = bidirectionalTradeBreach;
     this.DailyVolumeTradeBreach   = dailyVolumeTradeBreach;
     this.WindowVolumeTradeBreach  = windowVolumeTradeBreach;
     this.PriceMovementBreach      = priceMovementBreach;
     this.RuleParameterId          = equitiesParameters?.Id ?? string.Empty;
     this.SystemOperationId        = operationContext.Id.ToString();
     this.CorrelationId            = correlationId;
     this.RuleParameters           = equitiesParameters;
     this.Description              = description ?? string.Empty;
     this.CaseTitle                = caseTitle ?? string.Empty;
     this.UniverseDateTime         = universeDateTime;
 }
Beispiel #3
0
        /// <summary>
        /// The decorate with filter.
        /// </summary>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="layering">
        /// The layering.
        /// </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,
            ILayeringRuleEquitiesParameters parameter,
            IUniverseRule layering,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            ISystemProcessOperationRunRuleContext processOperationRunRuleContext,
            RuleRunMode ruleRunMode)
        {
            if (parameter.HasInternalFilters() ||
                parameter.HasReferenceDataFilters() ||
                parameter.HasMarketCapFilters() ||
                parameter.HasVenueVolumeFilters())
            {
                this.logger.LogInformation($"parameters had filters. Inserting filtered universe in {operationContext.Id} OpCtx");

                var filteredUniverse = this.universeFilterFactory.Build(
                    layering,
                    parameter.Accounts,
                    parameter.Traders,
                    parameter.Markets,
                    parameter.Funds,
                    parameter.Strategies,
                    parameter.Sectors,
                    parameter.Industries,
                    parameter.Regions,
                    parameter.Countries,
                    parameter.MarketCapFilter,
                    ruleRunMode,
                    "Layering Equity",
                    universeDataRequestsSubscriber,
                    processOperationRunRuleContext);

                var decoratedFilters = filteredUniverse;

                if (parameter.HasVenueVolumeFilters())
                {
                    decoratedFilters = this.decoratorFilterFactory.Build(
                        parameter.Windows,
                        filteredUniverse,
                        parameter.VenueVolumeFilter,
                        processOperationRunRuleContext,
                        universeDataRequestsSubscriber,
                        this.LayeringDataSource(parameter),
                        ruleRunMode);
                }

                decoratedFilters.Subscribe(layering);

                return(decoratedFilters);
            }

            return(layering);
        }
        public void Setup()
        {
            this._tradingHoursService = A.Fake <IMarketTradingHoursService>();
            this._equityFactory       = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeFactory  = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._orderFilterService  = A.Fake <IUniverseEquityOrderFilterService>();
            this._logger        = A.Fake <ILogger <EquityRuleLayeringFactory> >();
            this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >();

            this._equitiesParameters = A.Fake <ILayeringRuleEquitiesParameters>();
            this._ruleCtx            = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._alertStream        = A.Fake <IUniverseAlertStream>();
        }
 public ILayeringRule Build(
     ILayeringRuleEquitiesParameters equitiesParameters,
     ISystemProcessOperationRunRuleContext ruleCtx,
     IUniverseAlertStream alertStream,
     RuleRunMode runMode)
 {
     return(new LayeringRule(
                equitiesParameters,
                alertStream,
                this._orderFilterService,
                this._logger,
                this._equityFactory,
                this._fixedIncomeFactory,
                this._tradingHoursService,
                ruleCtx,
                runMode,
                this._tradingHistoryLogger));
 }
Beispiel #6
0
        /// <summary>
        /// The layering data source.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="DataSource"/>.
        /// </returns>
        private DataSource LayeringDataSource(ILayeringRuleEquitiesParameters parameters)
        {
            if (parameters == null)
            {
                return(DataSource.AnyInterday);
            }

            if (parameters.PercentageOfMarketWindowVolume != null)
            {
                return(DataSource.AnyIntraday);
            }

            if (parameters.PercentageOfMarketDailyVolume != null)
            {
                return(DataSource.AnyInterday);
            }

            return(this.DataSourceForWindow(parameters.Windows));
        }
        public void Setup()
        {
            _logger             = A.Fake <ILogger>();
            _tradingLogger      = A.Fake <ILogger <TradingHistoryStack> >();
            _alertStream        = A.Fake <IUniverseAlertStream>();
            _ruleCtx            = A.Fake <ISystemProcessOperationRunRuleContext>();
            _operationCtx       = A.Fake <ISystemProcessOperationContext>();
            _equitiesParameters = new LayeringRuleEquitiesParameters("id", TimeSpan.FromMinutes(30), 0.2m, null, null, null, false, true);

            _orderFilter = A.Fake <IUniverseOrderFilter>();
            A.CallTo(() => _orderFilter.Filter(A <IUniverseEvent> .Ignored)).ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]);

            _ruleRunRepository        = A.Fake <IRuleRunDataRequestRepository>();
            _stubRuleRunRepository    = A.Fake <IStubRuleRunDataRequestRepository>();
            _equityFactoryLogger      = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >();
            _equityFactory            = new UniverseEquityMarketCacheFactory(_stubRuleRunRepository, _ruleRunRepository, _equityFactoryLogger);
            _fixedIncomeFactoryLogger = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >();
            _fixedIncomeFactory       = new UniverseFixedIncomeMarketCacheFactory(_stubRuleRunRepository, _ruleRunRepository, _fixedIncomeFactoryLogger);
            _tradingHoursService      = A.Fake <IMarketTradingHoursService>();

            _tradingHoursRepository = A.Fake <IMarketOpenCloseApiCachingDecorator>();
            A.CallTo(() => _tradingHoursRepository.GetAsync())
            .Returns(
                new ExchangeDto[]
            {
                new ExchangeDto
                {
                    Code              = "XLON",
                    MarketOpenTime    = TimeSpan.FromHours(8),
                    MarketCloseTime   = TimeSpan.FromHours(16),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true,
                }
            });

            A.CallTo(() => _ruleCtx.EndEvent()).Returns(_operationCtx);
        }
Beispiel #8
0
        /// <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="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule SubscribeToParameters(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseAlertStream alertStream,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            ILayeringRuleEquitiesParameters parameter)
        {
            var ruleCtx = operationContext.CreateAndStartRuleRunContext(
                Rules.Layering.GetDescription(),
                EquityRuleLayeringFactory.Version,
                parameter.Id,
                (int)Rules.Layering,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var runMode      = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;
            var layeringRule = this.equityRuleLayeringFactory.Build(parameter, ruleCtx, alertStream, runMode);

            var layeringRuleOrgFactors = this.brokerServiceFactory.Build(
                layeringRule,
                parameter.Factors,
                parameter.AggregateNonFactorableIntoOwnCategory);

            var layeringRuleFiltered = this.DecorateWithFilter(
                operationContext,
                parameter,
                layeringRuleOrgFactors,
                universeDataRequestsSubscriber,
                ruleCtx,
                runMode);

            return(layeringRuleFiltered);
        }