protected override void RegisterMetric()
 {
     base.RegisterMetric();
     _sdtrMetricProxy = new RuntimeMetricProxy(
         Context.MetricManager,
         string.Format("SDTR[{0}]", AtrWindowSize));
 }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _priceChangeMetricProxy  = new RuntimeMetricProxy(Context.MetricManager, "ROC[1]");
            _volumeChangeMetricProxy = new RuntimeMetricProxy(Context.MetricManager, string.Format("VC[{0}]", VolumeLookbackWindow));
        }
예제 #3
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            IncreasePositionSortMetricProxy = null;
            NewPositionSortMetricProxy      = null;

            // register metric for sorting instruction
            if (!string.IsNullOrWhiteSpace(IncreasePositionSortMetric))
            {
                IncreasePositionSortMetricProxy = new RuntimeMetricProxy(Context.MetricManager, IncreasePositionSortMetric);
            }

            if (!string.IsNullOrWhiteSpace(NewPositionSortMetric))
            {
                NewPositionSortMetricProxy = new RuntimeMetricProxy(Context.MetricManager, NewPositionSortMetric);
            }

            if (!string.IsNullOrWhiteSpace(ObservableMetrics))
            {
                ObservableMetricProxies = ObservableMetrics.Split('|')
                                          .Where(s => !string.IsNullOrWhiteSpace(s))
                                          .Select(s => new UnifiedMetricProxy(s, Context))
                                          .ToArray();
            }
        }
예제 #4
0
        public ValueExtractor(IRuntimeMetricManager manager, string expression, Func <string, IRuntimeMetric> creator = null)
        {
            if (manager == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrWhiteSpace(expression))
            {
                throw new ArgumentNullException(expression);
            }

            double constantValue;

            if (!double.TryParse(expression, out constantValue))
            {
                _isConstant = false;
                _proxy      = creator == null ? new RuntimeMetricProxy(manager, expression) : new RuntimeMetricProxy(manager, expression, creator);
                _constant   = double.NaN;
            }
            else
            {
                _proxy      = null;
                _constant   = constantValue;
                _isConstant = true;
            }
        }
예제 #5
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _metricProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("BLP[{0:0.000}]", BuyPriceDownLimitProportion));
        }
예제 #6
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _referenceBar = new RuntimeMetricProxy(
                Context.MetricManager,
                "REFBAR[1]");
        }
예제 #7
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _shortMetricProxy  = new RuntimeMetricProxy(Context.MetricManager, string.Format("LR[{0}]", ShortWindowSize));
            _middleMetricProxy = new RuntimeMetricProxy(Context.MetricManager, string.Format("LR[{0}]", MiddleWindowSize));
            _longMetricProxy   = new RuntimeMetricProxy(Context.MetricManager, string.Format("LR[{0}]", LongWindowSize));
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _firstDayBarProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                "REFBAR[1]");
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _metricProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("BreakoutAndReturn[{0},{1},{2},{3}]", BreakoutWindow, PriceSelector, RerisingMaxInterval, RerisingMinInterval),
                (string s) => new BreakoutAndReturnRuntimeMetric(BreakoutWindow, PriceSelector, RerisingMaxInterval, RerisingMinInterval));
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _bounceMetricProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("BounceRuntimeMetric[{0},{1}]", WindowSize, MinBouncePercentage),
                (string s) => new BounceRuntimeMetric(WindowSize, MinBouncePercentage));
        }
예제 #11
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _rocMetricProxy = new RuntimeMetricProxy(Context.MetricManager,
                                                     string.Format("ROC[{0}]", RocWindowSize));

            Context.MetricManager.RegisterAfterUpdatedMetricsObserver(this);

            _sorter = new MetricGroupSorter(Context.GetAllTradingObjects());
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _previousBarProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                "REFBAR[1]");

            //_twoDaysPreviousBarProxy = new RuntimeMetricProxy(
            //    Context.MetricManager,
            //    "REFBAR[2]");
        }
예제 #13
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _highestMetricProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("HI[{0}](BAR.HP)", HighestLookbackPeriods));

            _movingAverageMetricProxy = new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("MA[{0}]", MovingAveragePeriods));
        }
예제 #14
0
        public BoardIndexBasedEquityUtilizationCalculator(IEvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException();
            }

            _context = context;

            _ma    = new RuntimeMetricProxy(_context.MetricManager, "AMA[22]");
            _close = new RuntimeMetricProxy(_context.MetricManager, "BAR.CP");
        }
예제 #15
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _movingAverage = MovingAveragePeriod > 0
                ? new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("REF[1](MA[{0}])", MovingAveragePeriod))
                : null;

            _previousDayBar = new RuntimeMetricProxy(
                Context.MetricManager,
                "REFBAR[1]");
        }
예제 #16
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _movingAverage = MovingAveragePeriod > 0
                ? new RuntimeMetricProxy(
                Context.MetricManager,
                string.Format("MA[{0}]", MovingAveragePeriod))
                : null;

            _previousDayBar = new RuntimeMetricProxy(
                Context.MetricManager,
                "REFBAR[1]");

            _lowest = MinPeriodForBeingLowestPrice > 0
                ? new RuntimeMetricProxy(Context.MetricManager, string.Format("LO[{0}](BAR.LP)", MinPeriodForBeingLowestPrice))
                : null;
        }
예제 #17
0
        public StreamDataDumper(StreamWriter writer, int numberOfBarsToDump, int numberOfBarsBacktrace, string metrics, IEvaluationContext context, ITradingDataProvider provider)
        {
            if (numberOfBarsBacktrace < 0 ||
                numberOfBarsBacktrace >= numberOfBarsToDump ||
                numberOfBarsToDump <= 0 ||
                context == null ||
                provider == null ||
                writer == null)
            {
                throw new ArgumentException();
            }

            _context  = context;
            _provider = provider;

            // register metrics
            if (string.IsNullOrEmpty(metrics))
            {
                _metricProxies = new RuntimeMetricProxy[0];
                _forBoardIndex = new bool[0];
            }
            else
            {
                _metricNames = metrics.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToArray();

                if (_metricNames.Count() == 0)
                {
                    _metricProxies = new RuntimeMetricProxy[0];
                    _forBoardIndex = new bool[0];
                }
                else
                {
                    _metricProxies = new RuntimeMetricProxy[_metricNames.Count()];
                    _forBoardIndex = new bool[_metricNames.Count()];

                    for (int i = 0; i < _metricNames.Length; ++i)
                    {
                        string metricName = _metricNames[i];

                        if (metricName.StartsWith(ForBoardIndexMetricHeader))
                        {
                            // for board
                            _forBoardIndex[i] = true;
                            metricName        = metricName.Substring(ForBoardIndexMetricHeader.Length);
                        }
                        else
                        {
                            _forBoardIndex[i] = false;
                        }

                        _metricProxies[i] = new RuntimeMetricProxy(_context.MetricManager, metricName);
                    }
                }
            }

            _writer                = writer;
            _numberOfBarsToDump    = numberOfBarsToDump;
            _numberOfBarsBacktrace = numberOfBarsBacktrace;

            for (int i = 0; i < _numberOfBarsToDump; ++i)
            {
                _writer.Write("Bar{0}.Time,Bar{0}.Open,Bar{0}.Highest,Bar{0}.Lowest,Bar{0}.Close,", i);
            }

            if (_metricProxies != null)
            {
                for (int j = 0; j < _metricProxies.Length; ++j)
                {
                    _writer.Write("{0},", _metricNames[j]);
                }
            }

            _writer.WriteLine();
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _metricProxy = new RuntimeMetricProxy(Context.MetricManager, RawMetric);
        }
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _metricProxy = new RuntimeMetricProxy(Context.MetricManager, "SAR[4,0.02,0.02,0.2]");
        }
 protected override void RegisterMetric()
 {
     base.RegisterMetric();
     _atrMetricProxy = new RuntimeMetricProxy(Context.MetricManager, string.Format("ATR[{0}]", VolatilityWindowSize));
 }
예제 #21
0
        private IEnumerable <Instruction> SortInstructions(IEnumerable <Instruction> instructions, InstructionSortMode mode, RuntimeMetricProxy metricProxy)
        {
            switch (mode)
            {
            case InstructionSortMode.NoSorting:
                return(instructions);

            case InstructionSortMode.Randomize:
                var randomizedInstructions = instructions.OrderBy(instruction => _random.Next());
                return(randomizedInstructions);

            case InstructionSortMode.SortByCodeAscending:
                return(instructions.OrderBy(instruction => instruction.TradingObject.Code));

            case InstructionSortMode.SortByCodeDescending:
                return(instructions.OrderBy(instruction => instruction.TradingObject.Code).Reverse());

            case InstructionSortMode.SortByInstructionIdAscending:
                return(instructions.OrderBy(instruction => instruction.Id));

            case InstructionSortMode.SortByInstructionIdDescending:
                return(instructions.OrderBy(instruction => instruction.Id).Reverse());

            case InstructionSortMode.SortByVolumeAscending:
                return(instructions.OrderBy(instruction => instruction.Volume));

            case InstructionSortMode.SortByVolumeDescending:
                return(instructions.OrderBy(instruction => - instruction.Volume));

            case InstructionSortMode.SortByMetricAscending:
                return(instructions.OrderBy(
                           instruction => metricProxy.GetMetricValues(instruction.TradingObject)[0]));

            case InstructionSortMode.SortByMetricDescending:
                return(instructions.OrderBy(
                           instruction => - metricProxy.GetMetricValues(instruction.TradingObject)[0]));

            default:
                throw new NotSupportedException(string.Format("unsupported instruction sort mode {0}", mode));
            }
        }
예제 #22
0
        protected override void RegisterMetric()
        {
            base.RegisterMetric();

            _growthProxy = new RuntimeMetricProxy(Context.MetricManager, string.Format("GROWTH[{0}]", GrowthCalculationWindow));
        }