18 using System.Collections.Generic;
31 private readonly decimal _maximumSectorExposure;
39 decimal maximumSectorExposure = 0.20m
42 if (maximumSectorExposure <= 0)
44 throw new ArgumentOutOfRangeException(
"MaximumSectorExposureRiskManagementModel: the maximum sector exposure cannot be a non-positive value.");
47 _maximumSectorExposure = maximumSectorExposure;
58 var maximumSectorExposureValue = algorithm.
Portfolio.TotalPortfolioValue * _maximumSectorExposure;
60 _targetsCollection.AddRange(targets);
64 .Where(x => x.Value.Fundamentals !=
null && x.Value.Fundamentals.HasFundamentalData)
65 .GroupBy(x => x.Value.Fundamentals.CompanyReference.IndustryTemplateCode);
67 foreach (var securities
in groupBySector)
72 var sectorAbsoluteHoldingsValue = 0m;
74 foreach (var security
in securities)
76 var absoluteHoldingsValue = security.Value.Holdings.AbsoluteHoldingsValue;
79 if (_targetsCollection.TryGetValue(security.Value.Symbol, out target))
81 absoluteHoldingsValue = security.Value.Price * Math.Abs(target.Quantity) *
82 security.Value.SymbolProperties.ContractMultiplier *
83 security.Value.QuoteCurrency.ConversionRate;
86 sectorAbsoluteHoldingsValue += absoluteHoldingsValue;
92 var ratio = sectorAbsoluteHoldingsValue / maximumSectorExposureValue;
95 foreach (var security
in securities)
97 var quantity = security.Value.Holdings.
Quantity;
98 var symbol = security.Value.Symbol;
101 if (_targetsCollection.TryGetValue(symbol, out target))
123 .Any(kvp => kvp.Value.Fundamentals !=
null && kvp.Value.Fundamentals.HasFundamentalData);
125 if (!anyFundamentalData)
127 throw new Exception(
"MaximumSectorExposureRiskManagementModel.OnSecuritiesChanged: Please select a portfolio selection model that selects securities with fundamental data.");