public PortfolioComponentView(IInstrument instrument, decimal modelAllocation, PortfolioComponentView parent) : this(parent) { PortfolioComponentType = PortfolioComponentType.Instrument; ComponentKey = instrument.Key; ComponentName = instrument.DisplayName; ModelAllocation = modelAllocation; }
public PortfolioComponentView(IModelVersion modelVersion, decimal modelAllocation, PortfolioComponentView parent) : this(parent) { PortfolioComponentType = PortfolioComponentType.Model; ComponentKey = modelVersion.Key; ComponentName = modelVersion.ParentModel.ModelName; ModelAllocation = modelAllocation; }
private static IEnumerable<PortfolioComponentView> allDescendantInstruments(List<PortfolioComponentView> allComponents, PortfolioComponentView component) { if (component.PortfolioComponentType == PortfolioComponentType.Instrument || component.PortfolioComponentType == PortfolioComponentType.Cash) return EnumerableExtensions.Singleton(component); else return allComponents.Where(c => c.Parent == component) .Select(c => allDescendantInstruments(allComponents, c)) .Aggregate(Enumerable.Empty<PortfolioComponentView>(), Enumerable.Concat); }
private PortfolioComponentView(PortfolioComponentView parent) { Parent = parent; }
private static IEnumerable<PortfolioComponentView> expandModelVersion(IDalSession session, IModelVersion modelVersion, decimal allocation, PortfolioComponentView parent) { PortfolioComponentView model = new PortfolioComponentView(modelVersion, allocation, parent); return modelVersion.ModelComponents .OrderBy(mc => mc.ModelComponentType == ModelComponentType.Instrument ? 0 : 1) .ThenBy(mc => mc.ComponentName) //.Where(mc => mc.ModelComponentKey != 13258) .Select(mc => expandModelComponent(session, mc, allocation * mc.Allocation, model)) .Aggregate(EnumerableExtensions.Singleton(model), Enumerable.Concat); }
private static IEnumerable<PortfolioComponentView> expandModelComponent(IDalSession session, IModelComponent modelComponent, decimal allocation, PortfolioComponentView parent) { switch (modelComponent.ModelComponentType) { case ModelComponentType.Model: return expandModelVersion(session, ModelMapper.GetModelVersion(session, modelComponent.ModelComponentKey), allocation, parent); default: //if (modelComponent.ModelComponentKey == 13257) // return EnumerableExtensions.Singleton(new PortfolioComponentView( // InstrumentMapper.GetTradeableInstrument(session, modelComponent.ModelComponentKey), 0.12m, parent)); //else ITradeableInstrument instrument = InstrumentMapper.GetTradeableInstrument(session, modelComponent.ModelComponentKey); if (instrument != null) return EnumerableExtensions.Singleton(new PortfolioComponentView(instrument, allocation, parent)); else return Enumerable.Empty<PortfolioComponentView>(); } }