Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HighProfitMarketClosureRule"/> class.
 /// </summary>
 /// <param name="equitiesParameters">
 /// The equities parameters.
 /// </param>
 /// <param name="ruleContext">
 /// The rule context.
 /// </param>
 /// <param name="costCalculatorFactory">
 /// The cost calculator factory.
 /// </param>
 /// <param name="revenueCalculatorFactory">
 /// The revenue calculator factory.
 /// </param>
 /// <param name="exchangeRateProfitCalculator">
 /// The exchange rate profit calculator.
 /// </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="marketDataCacheFactory">
 /// The market data cache factory.
 /// </param>
 /// <param name="dataRequestSubscriber">
 /// The data request subscriber.
 /// </param>
 /// <param name="judgementService">
 /// The judgement service.
 /// </param>
 /// <param name="runMode">
 /// The run mode.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="tradingHistoryLogger">
 /// The trading history logger.
 /// </param>
 public HighProfitMarketClosureRule(
     IHighProfitsRuleEquitiesParameters equitiesParameters,
     ISystemProcessOperationRunRuleContext ruleContext,
     ICostCalculatorFactory costCalculatorFactory,
     IRevenueCalculatorFactory revenueCalculatorFactory,
     IExchangeRateProfitCalculator exchangeRateProfitCalculator,
     IUniverseOrderFilter orderFilter,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     IEquityMarketDataCacheStrategyFactory marketDataCacheFactory,
     IUniverseDataRequestsSubscriber dataRequestSubscriber,
     IHighProfitJudgementService judgementService,
     ICurrencyConverterService currencyConverterService,
     RuleRunMode runMode,
     ILogger <HighProfitsRule> logger,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
     : base(
         equitiesParameters,
         ruleContext,
         costCalculatorFactory,
         revenueCalculatorFactory,
         exchangeRateProfitCalculator,
         orderFilter,
         equityMarketCacheFactory,
         fixedIncomeMarketCacheFactory,
         marketDataCacheFactory,
         dataRequestSubscriber,
         judgementService,
         currencyConverterService,
         runMode,
         logger,
         tradingHistoryLogger)
 {
     this.MarketClosureRule = true;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HighProfitsRule"/> class.
 /// </summary>
 /// <param name="equitiesParameters">
 /// The equities parameters.
 /// </param>
 /// <param name="streamRule">
 /// The stream rule.
 /// </param>
 /// <param name="marketClosureRule">
 /// The market closure rule.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public HighProfitsRule(
     IHighProfitsRuleEquitiesParameters equitiesParameters,
     IHighProfitStreamRule streamRule,
     IHighProfitMarketClosureRule marketClosureRule,
     ILogger <HighProfitsRule> logger)
 {
     this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters));
     this.streamRule         = streamRule ?? throw new ArgumentNullException(nameof(streamRule));
     this.marketClosureRule  = marketClosureRule ?? throw new ArgumentNullException(nameof(marketClosureRule));
     this.logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        /// <summary>
        /// The subscribe parameters.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="dataRequestSubscriber">
        /// The data request subscriber.
        /// </param>
        /// <param name="judgementService">
        /// The judgement service.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule SubscribeParameters(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            IHighProfitsRuleEquitiesParameters parameter)
        {
            var ruleCtxStream = operationContext.CreateAndStartRuleRunContext(
                Rules.HighProfits.GetDescription(),
                EquityRuleHighProfitFactory.Version,
                parameter.Id,
                (int)Rules.HighProfits,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var ruleCtxMarketClosure = operationContext.CreateAndStartRuleRunContext(
                Rules.HighProfits.GetDescription(),
                EquityRuleHighProfitFactory.Version,
                parameter.Id,
                (int)Rules.HighProfits,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var highProfitsRule = this.equityRuleHighProfitFactory.Build(
                parameter,
                ruleCtxStream,
                ruleCtxMarketClosure,
                dataRequestSubscriber,
                judgementService,
                execution);

            var highProfitsRuleOrgFactor = this.brokerServiceFactory.Build(
                highProfitsRule,
                parameter.Factors,
                parameter.AggregateNonFactorableIntoOwnCategory);

            var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;
            var decoratedHighProfits = this.DecorateWithFilter(
                operationContext,
                parameter,
                highProfitsRuleOrgFactor,
                dataRequestSubscriber,
                ruleCtxMarketClosure,
                runMode);

            return(decoratedHighProfits);
        }
        /// <summary>
        /// The decorate with filter.
        /// </summary>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="highProfitsRule">
        /// The high profits rule.
        /// </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,
            IHighProfitsRuleEquitiesParameters parameter,
            IUniverseRule highProfitsRule,
            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(
                    highProfitsRule,
                    parameter.Accounts,
                    parameter.Traders,
                    parameter.Markets,
                    parameter.Funds,
                    parameter.Strategies,
                    parameter.Sectors,
                    parameter.Industries,
                    parameter.Regions,
                    parameter.Countries,
                    parameter.MarketCapFilter,
                    ruleRunMode,
                    "High Profits Equity",
                    universeDataRequestsSubscriber,
                    processOperationRunRuleContext);

                var decoratedFilter = filteredUniverse;

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

                decoratedFilter.Subscribe(highProfitsRule);

                return(decoratedFilter);
            }

            return(highProfitsRule);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HighProfitStreamRule"/> class.
 /// </summary>
 /// <param name="equitiesParameters">
 /// The equities parameters.
 /// </param>
 /// <param name="ruleContext">
 /// The rule context.
 /// </param>
 /// <param name="costCalculatorFactory">
 /// The cost calculator factory.
 /// </param>
 /// <param name="revenueCalculatorFactory">
 /// The revenue calculator factory.
 /// </param>
 /// <param name="exchangeRateProfitCalculator">
 /// The exchange rate profit calculator.
 /// </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="marketDataCacheFactory">
 /// The market data cache factory.
 /// </param>
 /// <param name="dataRequestSubscriber">
 /// The data request subscriber.
 /// </param>
 /// <param name="judgementService">
 /// The judgement service.
 /// </param>
 /// <param name="runMode">
 /// The run mode.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="tradingHistoryLogger">
 /// The trading history logger.
 /// </param>
 public HighProfitStreamRule(
     IHighProfitsRuleEquitiesParameters equitiesParameters,
     ISystemProcessOperationRunRuleContext ruleContext,
     ICostCalculatorFactory costCalculatorFactory,
     IRevenueCalculatorFactory revenueCalculatorFactory,
     IExchangeRateProfitCalculator exchangeRateProfitCalculator,
     IUniverseOrderFilter orderFilter,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     IEquityMarketDataCacheStrategyFactory marketDataCacheFactory,
     IUniverseDataRequestsSubscriber dataRequestSubscriber,
     IHighProfitJudgementService judgementService,
     ICurrencyConverterService currencyConversionService,
     RuleRunMode runMode,
     ILogger <HighProfitsRule> logger,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
     : base(
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromHours(8),
         equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromHours(8),
         equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero,
         Rules.HighProfits,
         EquityRuleHighProfitFactory.Version,
         "High Profit Rule",
         ruleContext,
         equityMarketCacheFactory,
         fixedIncomeMarketCacheFactory,
         runMode,
         logger,
         tradingHistoryLogger)
 {
     this.EquitiesParameters =
         equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters));
     this.RuleContext           = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext));
     this.CostCalculatorFactory =
         costCalculatorFactory ?? throw new ArgumentNullException(nameof(costCalculatorFactory));
     this.RevenueCalculatorFactory =
         revenueCalculatorFactory ?? throw new ArgumentNullException(nameof(revenueCalculatorFactory));
     this.MarketDataCacheFactory =
         marketDataCacheFactory ?? throw new ArgumentNullException(nameof(marketDataCacheFactory));
     this.ExchangeRateProfitCalculator =
         exchangeRateProfitCalculator ?? throw new ArgumentNullException(nameof(exchangeRateProfitCalculator));
     this.OrderFilter           = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter));
     this.DataRequestSubscriber =
         dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber));
     this.currencyConversionService = currencyConversionService ?? throw new ArgumentNullException(nameof(currencyConversionService));
     this.JudgementService          = judgementService ?? throw new ArgumentNullException(nameof(judgementService));
     this.Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public IHighProfitRule Build(
            IHighProfitsRuleEquitiesParameters equitiesParameters,
            ISystemProcessOperationRunRuleContext ruleCtxStream,
            ISystemProcessOperationRunRuleContext ruleCtxMarket,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            ScheduledExecution scheduledExecution)
        {
            var runMode = scheduledExecution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;

            var stream = new HighProfitStreamRule(
                equitiesParameters,
                ruleCtxStream,
                this._costCalculatorFactory,
                this._revenueCalculatorFactory,
                this._exchangeRateProfitCalculator,
                this._orderFilterService,
                this._equityMarketCacheFactory,
                this._fixedIncomeMarketCacheFactory,
                this._cacheStrategyFactory,
                dataRequestSubscriber,
                judgementService,
                this._currencyConversionService,
                runMode,
                this._logger,
                this._tradingHistoryLogger);

            var marketClosure = new HighProfitMarketClosureRule(
                equitiesParameters,
                ruleCtxMarket,
                this._costCalculatorFactory,
                this._revenueCalculatorFactory,
                this._exchangeRateProfitCalculator,
                this._orderFilterService,
                this._equityMarketCacheFactory,
                this._fixedIncomeMarketCacheFactory,
                this._cacheStrategyFactory,
                dataRequestSubscriber,
                judgementService,
                this._currencyConversionService,
                runMode,
                this._logger,
                this._tradingHistoryLogger);

            return(new HighProfitsRule(equitiesParameters, stream, marketClosure, this._logger));
        }
        /// <summary>
        /// The high profit data source for window.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="DataSource"/>.
        /// </returns>
        private DataSource HighProfitDataSourceForWindow(IHighProfitsRuleEquitiesParameters parameters)
        {
            if (parameters == null)
            {
                return(DataSource.AnyInterday);
            }

            if (parameters.PerformHighProfitWindowAnalysis)
            {
                return(DataSource.AnyIntraday);
            }

            if (parameters.PerformHighProfitDailyAnalysis)
            {
                return(DataSource.AnyInterday);
            }

            return(this.DataSourceForWindow(parameters.Windows));
        }
        public void Setup()
        {
            this._orderFilterService            = A.Fake <IUniverseEquityOrderFilterService>();
            this._costCalculatorFactory         = A.Fake <ICostCalculatorFactory>();
            this._revenueCalculatorFactory      = A.Fake <IRevenueCalculatorFactory>();
            this._exchangeRateProfitCalculator  = A.Fake <IExchangeRateProfitCalculator>();
            this._equityMarketCacheFactory      = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._cacheStrategyFactory          = A.Fake <IEquityMarketDataCacheStrategyFactory>();
            this._judgementService         = A.Fake <IJudgementService>();
            this._logger                   = new NullLogger <HighProfitsRule>();
            this._tradingHistoryLogger     = new NullLogger <TradingHistoryStack>();
            this._currencyConverterService = A.Fake <ICurrencyConverterService>();

            this._equitiesParameters    = A.Fake <IHighProfitsRuleEquitiesParameters>();
            this._ruleCtxStream         = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._ruleCtxMarket         = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>();
            this._scheduledExecution    = new ScheduledExecution();
        }
 public HighProfitJudgementContext(
     HighProfitJudgement judgement,
     bool projectToAlert,
     IRuleBreachContext ruleBreachContext,
     IHighProfitsRuleEquitiesParameters equitiesParameters,
     Money?absoluteProfits,
     string absoluteProfitCurrency,
     decimal?relativeProfits,
     bool hasAbsoluteProfitBreach,
     bool hasRelativeProfitBreach,
     IExchangeRateProfitBreakdown profitBreakdown)
 {
     this.Judgement               = judgement;
     this.RaiseRuleViolation      = projectToAlert;
     this.RuleBreachContext       = ruleBreachContext;
     this.EquitiesParameters      = equitiesParameters;
     this.AbsoluteProfits         = absoluteProfits;
     this.AbsoluteProfitCurrency  = absoluteProfitCurrency;
     this.RelativeProfits         = relativeProfits;
     this.HasAbsoluteProfitBreach = hasAbsoluteProfitBreach;
     this.HasRelativeProfitBreach = hasRelativeProfitBreach;
     this.ExchangeRateProfits     = profitBreakdown;
 }