17 using System.Collections.Generic;
26 internal sealed
class ExposureReportElement : ChartReportElement
30 private List<PointInTimePortfolio> _backtestPortfolios;
31 private List<PointInTimePortfolio> _livePortfolios;
42 public ExposureReportElement(
47 List<PointInTimePortfolio> backtestPortfolios,
48 List<PointInTimePortfolio> livePortfolios)
51 _backtestPortfolios = backtestPortfolios;
53 _livePortfolios = livePortfolios;
61 public override string Render()
63 var longBacktestFrame = Metrics.Exposure(_backtestPortfolios,
OrderDirection.Buy);
64 var shortBacktestFrame = Metrics.Exposure(_backtestPortfolios,
OrderDirection.Sell);
65 var longLiveFrame = Metrics.Exposure(_livePortfolios,
OrderDirection.Buy);
66 var shortLiveFrame = Metrics.Exposure(_livePortfolios,
OrderDirection.Sell);
68 var backtestFrame = longBacktestFrame.Join(shortBacktestFrame)
72 var liveFrame = longLiveFrame.Join(shortLiveFrame)
76 longBacktestFrame = Frame.CreateEmpty<DateTime, Tuple<SecurityType, OrderDirection>>();
77 shortBacktestFrame = Frame.CreateEmpty<DateTime, Tuple<SecurityType, OrderDirection>>();
78 longLiveFrame = Frame.CreateEmpty<DateTime, Tuple<SecurityType, OrderDirection>>();
79 shortLiveFrame = Frame.CreateEmpty<DateTime, Tuple<SecurityType, OrderDirection>>();
81 foreach (var key
in backtestFrame.ColumnKeys)
83 longBacktestFrame[key] = backtestFrame[key].SelectValues(x => x < 0 ? 0 : x);
84 shortBacktestFrame[key] = backtestFrame[key].SelectValues(x => x > 0 ? 0 : x);
87 foreach (var key
in liveFrame.ColumnKeys)
89 longLiveFrame[key] = liveFrame[key].SelectValues(x => x < 0 ? 0 : x);
90 shortLiveFrame[key] = liveFrame[key].SelectValues(x => x > 0 ? 0 : x);
93 longBacktestFrame = longBacktestFrame.DropSparseColumnsAll();
94 shortBacktestFrame = shortBacktestFrame.DropSparseColumnsAll();
95 longLiveFrame = longLiveFrame.DropSparseColumnsAll();
96 shortLiveFrame = shortLiveFrame.DropSparseColumnsAll();
101 var time = backtestFrame.RowKeys.ToList().ToPython();
102 var longSecurities = longBacktestFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython();
103 var shortSecurities = shortBacktestFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython();
104 var longData = longBacktestFrame.ColumnKeys.Select(x => longBacktestFrame[x].Values.ToList().ToPython()).ToPython();
105 var shortData = shortBacktestFrame.ColumnKeys.Select(x => shortBacktestFrame[x].Values.ToList().ToPython()).ToPython();
106 var liveTime = liveFrame.RowKeys.ToList().ToPython();
107 var liveLongSecurities = longLiveFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython();
108 var liveShortSecurities = shortLiveFrame.ColumnKeys.Select(x => x.Item1.ToStringInvariant()).ToList().ToPython();
109 var liveLongData = longLiveFrame.ColumnKeys.Select(x => longLiveFrame[x].Values.ToList().ToPython()).ToPython();
110 var liveShortData = shortLiveFrame.ColumnKeys.Select(x => shortLiveFrame[x].Values.ToList().ToPython()).ToPython();
112 base64 = Charting.GetExposure(