20 using System.Collections.Generic;
25 internal sealed
class RollingPortfolioBetaReportElement : ChartReportElement
33 private int _tradingDaysPerYear;
43 public RollingPortfolioBetaReportElement(
string name,
string key,
BacktestResult backtest,
LiveResult live,
int tradingDaysPerYear)
49 _tradingDaysPerYear = tradingDaysPerYear;
55 public override string Render()
57 var backtestPoints = GetReturnSeries(_backtest);
58 var backtestBenchmarkPoints = ResultsUtil.BenchmarkPoints(_backtest);
59 var livePoints = GetReturnSeries(_live);
60 var liveBenchmarkPoints = ResultsUtil.BenchmarkPoints(_live);
65 var backtestList =
new PyList();
66 var liveList =
new PyList();
68 var backtestRollingBetaSixMonths = Rolling.Beta(backtestPoints, backtestBenchmarkPoints, windowSize: 22 * 6);
69 var backtestRollingBetaTwelveMonths = Rolling.Beta(backtestPoints, backtestBenchmarkPoints, windowSize: _tradingDaysPerYear);
71 backtestList.Append(backtestRollingBetaSixMonths.Keys.ToList().ToPython());
72 backtestList.Append(backtestRollingBetaSixMonths.Values.ToList().ToPython());
73 backtestList.Append(backtestRollingBetaTwelveMonths.Keys.ToList().ToPython());
74 backtestList.Append(backtestRollingBetaTwelveMonths.Values.ToList().ToPython());
76 var liveRollingBetaSixMonths = Rolling.Beta(livePoints, liveBenchmarkPoints, windowSize: 22 * 6);
77 var liveRollingBetaTwelveMonths = Rolling.Beta(livePoints, liveBenchmarkPoints, windowSize: _tradingDaysPerYear);
79 liveList.Append(liveRollingBetaSixMonths.Keys.ToList().ToPython());
80 liveList.Append(liveRollingBetaSixMonths.Values.ToList().ToPython());
81 liveList.Append(liveRollingBetaTwelveMonths.Keys.ToList().ToPython());
82 liveList.Append(liveRollingBetaTwelveMonths.Values.ToList().ToPython());
84 base64 = Charting.GetRollingBeta(backtestList, liveList);
90 private static SortedList<DateTime, double> GetReturnSeries(Result leanResult)
93 if (returnSeries ==
null || returnSeries.Count == 0)
96 returnSeries = ResultsUtil.EquityPoints(leanResult,
"Daily Performance");