/// <summary> /// Generate the asset allocation pie chart using the python libraries. /// </summary> public override string Render() { var backtestSeries = Metrics.AssetAllocations(_backtestPortfolios); var liveSeries = Metrics.AssetAllocations(_livePortfolios); PyObject result; using (Py.GIL()) { var data = new PyList(); var liveData = new PyList(); data.Append(backtestSeries.SortBy(x => - x).Where(x => x.Value != 0).Keys.Select(x => x.Value).ToList().ToPython()); data.Append(backtestSeries.SortBy(x => - x).Where(x => x.Value != 0).Values.ToList().ToPython()); liveData.Append(liveSeries.SortBy(x => - x).Where(x => x.Value != 0).Keys.Select(x => x.Value).ToList().ToPython()); liveData.Append(liveSeries.SortBy(x => - x).Where(x => x.Value != 0).Values.ToList().ToPython()); result = Charting.GetAssetAllocation(data, liveData); } var base64 = result.ConvertToDictionary <string, string>(); if (base64.ContainsKey("Live Asset Allocation")) { return(base64["Live Asset Allocation"]); } return(base64["Backtest Asset Allocation"]); }