/// <summary>
        /// Gets the multiplier by which all trade volumes from this component are multipied before using in portfolio and correlation analysis.
        /// </summary>
        public static void UpdateComponentNormalizationMultiplier(this PortfolioComponent component, PortfolioSimulation sim)
        {
            double multiplier = 1.0;

            var minTradeVolumeForSymbol = component.SymbolHandle.GetMinTradeVolumeForSymbol();

            if (sim.Options.VolumeNormalization.ReductionMode?.HasFlag(VolumeNormalizationReductionMode.DivideByMinimumsMultipleOfMinimumAllowedTradeSize) == true)
            {
                var min = component.MinAbsoluteVolume;
                if (min > minTradeVolumeForSymbol)
                {
                    multiplier *= minTradeVolumeForSymbol / min;
#if DEBUG
                    if (sim.Options.Verbosity >= 5)
                    {
                        Console.WriteLine($"[VolumeNormalize] component absolute min: {min},  min for symbol {component.BacktestResult.Symbol}: {minTradeVolumeForSymbol}, multiplier: {multiplier}");
                    }
#endif
                }
            }

            if (sim.Options.VolumeNormalization.ReductionMode?.HasFlag(VolumeNormalizationReductionMode.DivideByMinimumAllowedTradeVolume) == true)
            {
                multiplier /= minTradeVolumeForSymbol;
            }

            component.NormalizationMultiplier = multiplier;
        }
        private static double NormalizeVolumeSource(PortfolioSimulation sim, PortfolioComponent component, double unnormalizedVolume)
        {
            double value = unnormalizedVolume * component.NormalizationMultiplier.Value;


#if DEBUG
            if (sim.Options.VolumeNormalization.MaxSourceValue.HasValue && value > sim.Options.VolumeNormalization.MaxSourceValue.Value)
            {
                if (sim.Options.Verbosity >= 6)
                {
                    Console.WriteLine($"Capping normalized volume of {value} to max: {sim.Options.VolumeNormalization.MaxSourceValue.Value}");
                }
            }
#endif
            value = Math.Min(value, sim.Options.VolumeNormalization.MaxSourceValue.Value);

            return(value);
        }
Example #3
0
 public Correlation(PortfolioComponent component1, PortfolioComponent component2)
 {
     this.Component1 = component1;
     this.Component2 = component2;
     SameSymbol      = component1.BacktestResultId == component2.BacktestResultId;
 }