17 using System.Collections.Generic;
26 internal sealed
class AssetAllocationReportElement : ChartReportElement
29 private List<PointInTimePortfolio> _backtestPortfolios;
31 private List<PointInTimePortfolio> _livePortfolios;
42 public AssetAllocationReportElement(
47 List<PointInTimePortfolio> backtestPortfolios,
48 List<PointInTimePortfolio> livePortfolios)
51 _backtestPortfolios = backtestPortfolios;
53 _livePortfolios = livePortfolios;
61 public override string Render()
63 var backtestSeries = Metrics.AssetAllocations(_backtestPortfolios);
64 var liveSeries = Metrics.AssetAllocations(_livePortfolios);
70 var data =
new PyList();
71 var liveData =
new PyList();
73 data.Append(backtestSeries.SortBy(x => -x).Where(x => x.Value != 0).Keys.Select(x => x.Value).ToList().ToPython());
74 data.Append(backtestSeries.SortBy(x => -x).Where(x => x.Value != 0).Values.ToList().ToPython());
76 liveData.Append(liveSeries.SortBy(x => -x).Where(x => x.Value != 0).Keys.Select(x => x.Value).ToList().ToPython());
77 liveData.Append(liveSeries.SortBy(x => -x).Where(x => x.Value != 0).Values.ToList().ToPython());
79 result = Charting.GetAssetAllocation(data, liveData);
82 var base64 = result.ConvertToDictionary<string,
string>();
83 if (base64.ContainsKey(
"Live Asset Allocation"))
85 return base64[
"Live Asset Allocation"];
88 return base64[
"Backtest Asset Allocation"];