diff --git a/04 Research Environment/04 Charting/05 Plotly NET/03 Import Libraries.html b/04 Research Environment/04 Charting/05 Plotly NET/03 Import Libraries.html index cd2c23fa40..b738048b53 100644 --- a/04 Research Environment/04 Charting/05 Plotly NET/03 Import Libraries.html +++ b/04 Research Environment/04 Charting/05 Plotly NET/03 Import Libraries.html @@ -1,13 +1,27 @@
Follow these steps to import the libraries that you need:
#load "../Initialize.csx"+
#r "../Plotly.NET.dll"+
#load "../QuantConnect.csx" +#r "../Plotly.NET.dll" +#r "../Plotly.NET.Interactive.dll"
Plotly.NET
and Plotly.NET.LayoutObjects
packages.QuantConnect
, Plotly.NET
, and Accord
packages.using Plotly.NET; -using Plotly.NET.LayoutObjects;-
using QuantConnect; +using QuantConnect.Research; + +using Plotly.NET; +using Plotly.NET.Interactive; +using Plotly.NET.LayoutObjects; + +using Accord.Math; +using Accord.Statistics;+ \ No newline at end of file diff --git a/04 Research Environment/04 Charting/05 Plotly NET/04 Get Historical Data.php b/04 Research Environment/04 Charting/05 Plotly NET/04 Get Historical Data.php index 2eae83304b..2aec5f492b 100644 --- a/04 Research Environment/04 Charting/05 Plotly NET/04 Get Historical Data.php +++ b/04 Research Environment/04 Charting/05 Plotly NET/04 Get Historical Data.php @@ -9,7 +9,7 @@ "GS", // Goldman Sachs Group, Inc. "JPM", // J P Morgan Chase & Co "WFC" // Wells Fargo & Company -} +}; var symbols = tickers.Select(ticker => qb.AddEquity(ticker, Resolution.Daily).Symbol); var history = qb.History(symbols, new DateTime(2021, 1, 1), new DateTime(2022, 1, 1)); diff --git a/04 Research Environment/04 Charting/05 Plotly NET/10 Create Heat Map.html b/04 Research Environment/04 Charting/05 Plotly NET/10 Create Heat Map.html new file mode 100644 index 0000000000..61648de8ad --- /dev/null +++ b/04 Research Environment/04 Charting/05 Plotly NET/10 Create Heat Map.html @@ -0,0 +1,60 @@ +
You must import the plotting libraries and get some historical data to create heat maps.
+ +In this example, you create a heat map that shows the correlation between the daily returns of the banking securities. Follow these steps to create the heat map:
+ +var data = history.SelectMany(x => x.Bars.Values) + .GroupBy(x => x.Symbol) + .Select(x => + { + var prices = x.Select(x => (double)x.Close).ToArray(); + return Enumerable.Range(0, prices.Length - 1) + .Select(i => prices[i+1] / prices[i] - 1).ToArray(); + }).ToArray().Transpose();+
Measures.Correlation
method.var corrMatrix = Measures.Correlation(data).Select(x => x.ToList()).ToList();+
Plotly.NET.Chart2D.Chart.Heatmap
constructor with the correlation matrix.var X = Enumerable.Range(0, tickers.Length).ToList(); + +var heatmap = Plotly.NET.Chart2D.Chart.Heatmap<IEnumerable<double>, double, int, int, string>( + zData: corr, + X: X, + Y: X, + ShowScale: true, + ReverseYAxis: true +);+
Layout
.var axis = new LinearAxis(); +axis.SetValue("tickvals", X); +axis.SetValue("ticktext", tickers); + +var layout = new Layout(); +layout.SetValue("xaxis", axis); +layout.SetValue("yaxis", axis); +layout.SetValue("title", Title.init("Banking Stocks and bank sector ETF Correlation Heat Map"));+
Layout
to the chart.heatmap.WithLayout(layout);+
HTML(GenericChart.toChartHTML(heatmap))+
The Jupyter Notebook displays the heat map.
+ +