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:

    +
  1. Load the required assembly files and data types. You need to load assemblies at the start in their own cell.
  2. +
    +
    #load "../Initialize.csx"
    +
    +
  3. Load the necessary assembly files.
  4. -
    #r "../Plotly.NET.dll"
    +
    #load "../QuantConnect.csx"
    +#r "../Plotly.NET.dll"
    +#r "../Plotly.NET.Interactive.dll"
    -
  5. Import the Plotly.NET and Plotly.NET.LayoutObjects packages.
  6. +
  7. Import the QuantConnect, Plotly.NET, and Accord packages.
  8. -
    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:

    + +
      +
    1. Compute the daily returns.
    2. +
      +
      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();
      +
      + +
    3. Call the Measures.Correlation method.
    4. +
      +
      var corrMatrix = Measures.Correlation(data).Select(x => x.ToList()).ToList();
      +
      + +
    5. Call the Plotly.NET.Chart2D.Chart.Heatmap constructor with the correlation matrix.
    6. +
      +
      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
      +);
      +
      + +
    7. Create a Layout.
    8. +
      +
      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"));
      +
      + +
    9. Assign the Layout to the chart.
    10. +
      +
      heatmap.WithLayout(layout);
      +
      + +
    11. Show the plot.
    12. +
      +
      HTML(GenericChart.toChartHTML(heatmap))
      +
      + +

      The Jupyter Notebook displays the heat map.

      + Plotly.NET heat map +
    \ No newline at end of file