<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wynn Tee</title>
    <description>The latest articles on DEV Community by Wynn Tee (@wynntee).</description>
    <link>https://dev.to/wynntee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F740428%2F596e23a3-0866-4167-aa21-c222c2912ac5.png</url>
      <title>DEV Community: Wynn Tee</title>
      <link>https://dev.to/wynntee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wynntee"/>
    <language>en</language>
    <item>
      <title>How to create bins with a monotonic weight of evidence trend in Excel</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Wed, 23 Feb 2022 11:51:37 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-create-bins-with-a-monotonic-weight-of-evidence-trend-in-excel-215e</link>
      <guid>https://dev.to/quantirisk/how-to-create-bins-with-a-monotonic-weight-of-evidence-trend-in-excel-215e</guid>
      <description>&lt;p&gt;Risk practitioners often apply weight of evidence (WOE) transformation to the independent variables of a logistic regression. A key challenge in the transformation is grouping data into bins that, when sorted logically, show a monotonic WOE trend.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.BIN functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug7oiqq9bq4r0lnb9x99.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug7oiqq9bq4r0lnb9x99.png" alt="QRS.BIN functions" width="560" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com" rel="noopener noreferrer"&gt;QRS Toolbox for Excel&lt;/a&gt; includes functions for binning data with application to WOE transformation. The names of the functions all begin with QRS.BIN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.eqfreq" rel="noopener noreferrer"&gt;QRS.BIN.EQFREQ&lt;/a&gt;, &lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.eqwidth" rel="noopener noreferrer"&gt;QRS.BIN.EQWIDTH&lt;/a&gt;, and &lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.unique" rel="noopener noreferrer"&gt;QRS.BIN.UNIQUE&lt;/a&gt; return bins using the equal frequency, equal width, and unique value methods respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.mono" rel="noopener noreferrer"&gt;QRS.BIN.MONO&lt;/a&gt; returns bins using a novel combination of the Monotone Adjacent Pooling Algorithm and ChiMerge. It can be used to automatically create bins with a monotonic WOE trend.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.manual" rel="noopener noreferrer"&gt;QRS.BIN.MANUAL&lt;/a&gt; returns bins using user-defined criteria. It can be used to manually create bins with a monotonic WOE trend, such as by merging bins returned from one of the other QRS.BIN functions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.map" rel="noopener noreferrer"&gt;QRS.BIN.MAP&lt;/a&gt; returns mapped bin values. It can be used to map original data values to WOE values for subsequent use in &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.regression" rel="noopener noreferrer"&gt;QRS.LOGISTIC.REGRESSION&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.BIN.MONO
&lt;/h2&gt;

&lt;p&gt;To try QRS.BIN.MONO yourself, first &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.BIN.MONO. Then, download and open the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-bin-data-monotonic-woe-excel/example.xlsx" rel="noopener noreferrer"&gt;example workbook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgeep3ziduje4zspf83k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgeep3ziduje4zspf83k.png" alt="Data" width="560" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The data in the workbook is based on the 2020 version of the &lt;a href="https://archive.ics.uci.edu/ml/datasets/South+German+Credit+%28UPDATE%29" rel="noopener noreferrer"&gt;South German credit&lt;/a&gt; dataset. In the workbook:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cells A2–A1001 contain credit duration in months for 1000 debtors.&lt;/li&gt;
&lt;li&gt;Cells B2–B1001 contain ones if credit defaults occurred and zeros otherwise.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MONO(A2:A1001, B2:B1001, 1, 7)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fext5pscmfmk3m4u748jc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fext5pscmfmk3m4u748jc.png" alt="Formula" width="560" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To group credit duration into 7 bins with a monotonic WOE trend, enter the formula &lt;code&gt;=QRS.BIN.MONO(A2:A1001, B2:B1001, 1, 7)&lt;/code&gt; in cell E1. The third argument is 1, because credit risk generally increases as credit duration increases.&lt;/p&gt;

&lt;p&gt;The result is a frequency table with 7 rows and 7 columns. The rows correspond to bins. The columns correspond to identifier, description, total frequency, frequency of zeros, frequency of ones, proportion of ones, and WOE respectively.&lt;/p&gt;

&lt;p&gt;The WOE values in the final column increase monotonically, as required. Note that some applications assume a definition of WOE that differs by a negative sign.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MONO(A2:A1001, B2:B1001, 1, 7, "HEADER", TRUE)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5zs0qzfj2ysfgeofjr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5zs0qzfj2ysfgeofjr1.png" alt="Formula" width="560" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To improve the presentation of the result, add &lt;code&gt;"HEADER", TRUE&lt;/code&gt; to the formula. The result now contains a header row.&lt;/p&gt;

&lt;p&gt;The identifiers in the first column represent the lower bounds of the bins. They can be used as binning keys in QRS.BIN.MAP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MAP(A2:A1001, E2:E9, K2:K9)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ki3vjtzh7pkynphelca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ki3vjtzh7pkynphelca.png" alt="Formula" width="560" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, to map the original credit duration values to WOE values, enter the formula &lt;code&gt;=QRS.BIN.MAP(A2:A1001, E2:E9, K2:K9)&lt;/code&gt; in cell C2.&lt;/p&gt;

&lt;p&gt;Please read the &lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.mono" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to learn more about QRS.BIN.MONO, including how to include a total row and how to include only selected columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.BIN.MANUAL
&lt;/h2&gt;

&lt;p&gt;The bins created using QRS.BIN.MONO will always have a monotonic WOE trend, but they might not have "nice" lower bounds or "smooth" frequencies. For example, the lower bounds might not be integers, or the frequencies might not be unimodal.&lt;/p&gt;

&lt;p&gt;Continuing with the example from the previous section, suppose that the bins are required to have not only a monotonic WOE trend, but also lower bounds that are multiples of 6 or 12 months.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MANUAL(A2:A1001, B2:B1001, F15:F23, , "HEADER", TRUE, "EXC", TRUE, "COLS", "NO,DESC,N,WOE")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjuf0kz7sfr1aaxql2z3h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjuf0kz7sfr1aaxql2z3h.png" alt="Formula" width="560" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create bins with such "nice" lower bounds, enter 0, 6, 12, 18, 24, 30, 36, 48, 60 in cells F15–F23, and enter the formula &lt;code&gt;=QRS.BIN.MANUAL(A2:A1001, B2:B1001, F15:F23, , "HEADER", TRUE, "EXC", TRUE, "COLS", "NO,DESC,N,WOE")&lt;/code&gt; in cell H14. The &lt;code&gt;"EXC", TRUE&lt;/code&gt; option turns the lower bounds into exclusive, rather than inclusive, bounds.&lt;/p&gt;

&lt;p&gt;The result contains 9 bins that satisfy the "nice" lower bounds requirement, but not the monotonic WOE trend requirement. The WOE of the ninth bin cannot even be calculated. A possible solution is to merge some of the bins.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MANUAL(A2:A1001, B2:B1001, F15:F23, E15:E23, "HEADER", TRUE, "EXC", TRUE, "COLS", "NO,DESC,N,WOE")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ezyfxr36eyssxbrqhbf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ezyfxr36eyssxbrqhbf.png" alt="Formula" width="560" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To merge bins 3–4, 5–6, and 7–9, enter the new bin numbers 1, 2, 3, 3, 4, 4, 5, 5, 5 in cells E15–E23, and change the empty fourth argument in cell H14 to &lt;code&gt;E15:E23&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The result now contains 5 bins that satisfy both the "nice" lower bounds and monotonic WOE trend requirements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MAP(E15:E23, H15:H19, K15:K19)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fracqr5alapizrnig9da0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fracqr5alapizrnig9da0.png" alt="Formula" width="560" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, to map the original credit duration values to WOE values, enter the formula &lt;code&gt;=QRS.BIN.MAP(E15:E23, H15:H19, K15:K19)&lt;/code&gt; in cell G15.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.BIN.MAP(A2:A1001, F15:F23, G15:G23)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyaa364486iomr3y2okl0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyaa364486iomr3y2okl0.png" alt="Formula" width="560" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, enter the formula &lt;code&gt;=QRS.BIN.MAP(A2:A1001, F15:F23, G15:G23)&lt;/code&gt; in cell C2. The mapping is done in two steps, because the original values and WOE values are indirectly linked by the bin numbers.&lt;/p&gt;

&lt;p&gt;Please read the &lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.mono" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to learn more about QRS.BIN.MANUAL, including how to use regular expressions for text values and how to handle stray values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;If you would like to use &lt;a href="https://addin.qrstoolbox.com/pages/docs/bin.mono" rel="noopener noreferrer"&gt;QRS.BIN.MONO&lt;/a&gt; beyond your free trial period, you may &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-buy-premium" rel="noopener noreferrer"&gt;purchase the right to use&lt;/a&gt; it indefinitely for as little as USD 9.00. If you find the QRS.BIN functions useful, please share this page with other potential users.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>statistics</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to calculate accuracy ratio in Excel using only a formula</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Mon, 15 Nov 2021 13:48:36 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-calculate-accuracy-ratio-in-excel-using-only-a-formula-32j6</link>
      <guid>https://dev.to/quantirisk/how-to-calculate-accuracy-ratio-in-excel-using-only-a-formula-32j6</guid>
      <description>&lt;p&gt;Risk practitioners often use accuracy ratio (AR) to measure the discriminatory power of &lt;a href="https://en.wikipedia.org/wiki/Binary_classification" rel="noopener noreferrer"&gt;binary classification&lt;/a&gt; models, such as models of credit default and insurance fraud. The closer AR is to 1, the higher the discriminatory power of the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnzqwuneqibv1ifcp98wy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnzqwuneqibv1ifcp98wy.png" alt="Cumulative Accuracy Profile" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram shows the &lt;a href="https://en.wikipedia.org/wiki/Cumulative_accuracy_profile" rel="noopener noreferrer"&gt;cumulative accuracy profiles&lt;/a&gt; of a realistic model, a random model, and a perfect model.&lt;/p&gt;

&lt;p&gt;As the proportion of observations increases, a perfect model would correctly classify all events before all non-events, but a random model would indiscriminately classify events and non-events together. A realistic model would be somewhere in between.&lt;/p&gt;

&lt;p&gt;AR is the ratio of the area between the cumulative accuracy profiles of the realistic and random models (B) to the area between the cumulative accuracy profiles of the perfect and random models (A+B).&lt;/p&gt;

&lt;p&gt;Unfortunately, Excel does not come with a native function for calculating AR. It is possible to calculate AR in Excel manually, but the process involves auxiliary rows and columns with complicated formulas that have to be adjusted as observations are added or removed. The problem is exacerbated with the standard error of AR.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.DISC.AR
&lt;/h2&gt;

&lt;p&gt;Fortunately, &lt;a href="https://addin.qrstoolbox.com" rel="noopener noreferrer"&gt;QRS Toolbox for Excel&lt;/a&gt; includes the &lt;a href="https://addin.qrstoolbox.com/pages/docs/disc.ar" rel="noopener noreferrer"&gt;QRS.DISC.AR&lt;/a&gt; function for calculating AR. It is applicable to both grouped and ungrouped data.&lt;/p&gt;

&lt;p&gt;To try QRS.DISC.AR yourself, first &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and then open the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-calculate-accuracy-ratio-excel/example.xlsx" rel="noopener noreferrer"&gt;example workbook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegfm29xcjs7rymf670kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegfm29xcjs7rymf670kc.png" alt="Ungrouped data" width="560" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The workbook contains 2 worksheets. In the UNGROUPED worksheet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cells A2–A2001 contain credit scores for 2000 borrowers. The scores range between 0 for least creditworthy and 100 for most creditworthy.&lt;/li&gt;
&lt;li&gt;Cells B2–B2001 contain ones if credit default occurred and zeros otherwise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fksbv8aeka4gvbr6jhx0u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fksbv8aeka4gvbr6jhx0u.png" alt="Grouped data" width="560" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the GROUPED worksheet, cells A2–E8 contain data from the previous worksheet grouped into 7 score ranges, each with an alphabetical rating grade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ungrouped data example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.DISC.AR(A2:A2001, B2:B2001)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4q6tzdmkbsi54mz52mvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4q6tzdmkbsi54mz52mvy.png" alt="Formula" width="560" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To calculate AR of the ungrouped data, open the UNGROUPED worksheet and enter the formula &lt;code&gt;=QRS.DISC.AR(A2:A2001, B2:B2001)&lt;/code&gt; in cell D1. The result is -0.794, which is generally considered to be a large AR in absolute terms.&lt;/p&gt;

&lt;p&gt;The result is negative-valued, because the credit scores and credit default events in this example are negatively correlated by design. In a perfect model, score=0 corresponds to event=1, and score=100 corresponds to event=0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Significance test
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.DISC.AR(A2:A2001, B2:B2001, "TEST", "RAG")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faq71tt26y4a41d0dzmdk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faq71tt26y4a41d0dzmdk.png" alt="Formula" width="560" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the statistical significance of the AR, add &lt;code&gt;"TEST", "RAG"&lt;/code&gt; to the formula. The result now contains a second row with a red/amber/green rating that summarizes the significance test.&lt;/p&gt;

&lt;p&gt;The AR in this example has a green rating. A green/amber rating means the AR is significant at the 5%/10% significance level. A red rating means the AR is not significant at the 10% significance level.&lt;/p&gt;

&lt;p&gt;Please read the &lt;a href="https://addin.qrstoolbox.com/pages/docs/disc.ar" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to learn how to return the p-value and other useful information about the significance test, as well as how to change the significance levels of the ratings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Labels and transpose
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.DISC.AR(A2:A2001, B2:B2001, "TEST", "RAG", "LABELS", TRUE)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstndmwborminfs26n5mj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstndmwborminfs26n5mj.png" alt="Formula" width="560" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To add labels to the result, add &lt;code&gt;"LABELS", TRUE&lt;/code&gt; to the formula. To swap the rows and columns of the result, add &lt;code&gt;"TRANSPOSE", TRUE&lt;/code&gt; to the formula.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grouped data example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.DISC.AR(B2:B8, D2:E8)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43r83hhm4d4xcn1hqgt5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43r83hhm4d4xcn1hqgt5.png" alt="Formula" width="560" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To calculate AR of the grouped data, switch to the GROUPED worksheet and enter the formula &lt;code&gt;=QRS.DISC.AR(B2:B8, D2:E8)&lt;/code&gt; in cell F9. The result is -0.797, which is similar to the AR of the ungrouped data.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TEST&lt;/code&gt;, &lt;code&gt;LABELS&lt;/code&gt;, and &lt;code&gt;TRANSPOSE&lt;/code&gt; options can be used as before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;If you find QRS.DISC.AR useful, please share this page with other potential users.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>statistics</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to estimate value-at-risk given skewness and kurtosis in Excel</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Mon, 15 Nov 2021 09:01:20 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-estimate-value-at-risk-given-skewness-and-kurtosis-in-excel-1n5o</link>
      <guid>https://dev.to/quantirisk/how-to-estimate-value-at-risk-given-skewness-and-kurtosis-in-excel-1n5o</guid>
      <description>&lt;p&gt;Risk practitioners often use &lt;a href="https://en.wikipedia.org/wiki/Value_at_risk" rel="noopener noreferrer"&gt;value-at-risk&lt;/a&gt; (VaR) to quantify the potential future loss of an investment. As a risk metric, VaR answers questions like "What is the worst daily/monthly/yearly return going to be 90%/95%/99% of the time?"&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Faddin.qrstoolbox.com%2Fpages%2Fdemos%2Fhow-to-estimate-var-skewness-kurtosis-excel%2Fvar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Faddin.qrstoolbox.com%2Fpages%2Fdemos%2Fhow-to-estimate-var-skewness-kurtosis-excel%2Fvar.png" alt="VaR is a &amp;lt;br&amp;gt;
percentile" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In statistical jargon, VaR is simply the percentile of the return distribution at a given confidence level. The above diagram illustrates VaR at the 95% confidence level.&lt;/p&gt;

&lt;p&gt;Sometimes, VaR is defined in terms of a loss (instead of return) distribution. In that case, the above diagram would flip horizontally and VaR would be in the right tail.&lt;/p&gt;
&lt;h2&gt;
  
  
  Mean and variance
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxio6snnys0tek5q5sy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxio6snnys0tek5q5sy8.png" alt="Normal distribution" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the mean and variance of the return distribution are given, VaR can be estimated by assuming returns follow the normal distribution and calculating the percentile of the normal distribution that fits the given mean and variance.&lt;/p&gt;

&lt;p&gt;To estimate VaR at the 95% confidence level in Excel when the mean and variance of the return distribution are 10% and 0.01 respectively, enter the formula &lt;code&gt;=NORM.INV(1-0.95, 10%, SQRT(0.01))&lt;/code&gt; in a cell.&lt;/p&gt;

&lt;p&gt;To estimate VaR when the previous mean and variance are for the loss (instead of return) distribution, change the formula to &lt;code&gt;=NORM.INV(0.95, 10%, SQRT(0.01))&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Skewness and kurtosis
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxp56eqxw78tvxn0clcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxp56eqxw78tvxn0clcm.png" alt="Taleb distribution" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In reality, returns are more likely to follow a non-normal distribution with negative skewness and large kurtosis. According to journalist Martin Wolf, many investment strategies have a high probability of small gains and a low probability of huge losses.&lt;/p&gt;

&lt;p&gt;If the skewness and kurtosis of the return distribution are given in addition to the mean and variance, VaR can be estimated by assuming returns follow a non-normal parametric distribution and calculating the percentile of the distribution that fits the given moments.&lt;/p&gt;

&lt;p&gt;There are many non-normal parametric distributions, but the Pearson and Johnson distributions are the only ones that fit all possible combinations of skewness and kurtosis. No other parametric distribution has such a feature.&lt;/p&gt;

&lt;p&gt;Unfortunately, Excel does not come with native functions for using the Pearson and Johnson distributions.&lt;/p&gt;
&lt;h2&gt;
  
  
  QRS.VAR functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frqqkywq12nxil17wjnu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frqqkywq12nxil17wjnu7.png" alt="QRS.VAR functions" width="560" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, &lt;a href="https://addin.qrstoolbox.com" rel="noopener noreferrer"&gt;QRS Toolbox for Excel&lt;/a&gt; includes functions for estimating VaR from not only the normal distribution, but also the Pearson and Johnson distributions. The names of the functions all begin with QRS.VAR.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/var.normal" rel="noopener noreferrer"&gt;QRS.VAR.NORMAL&lt;/a&gt; returns VaR for the normal distribution. It accepts the confidence level, mean, standard deviation, and choice of tail as parameters. It is simpler to use compared to the two previous formulas involving NORM.INV.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/var.pearson" rel="noopener noreferrer"&gt;QRS.VAR.PEARSON&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/var.johnson" rel="noopener noreferrer"&gt;QRS.VAR.JOHNSON&lt;/a&gt; return VaR for the Pearson and Johnson distributions respectively. They accept the same parameters as QRS.VAR.NORMAL in addition to skewness and kurtosis.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pearson Type IV example
&lt;/h2&gt;

&lt;p&gt;There are 5 main types of Pearson distributions, namely Types I, III, IV, V, and VI. To the best of our knowledge, QRS.VAR.PEARSON is the only publicly available Excel function for estimating VaR from all 5 types of Pearson distributions.&lt;/p&gt;

&lt;p&gt;The Pearson Type IV distribution deserves special mention. It is a natural alternative to the normal distribution in risk applications, because it is not only unimodal and unbounded, but also skewed (squared skewness &amp;lt; 32) and fat-tailed (kurtosis &amp;gt; 3).&lt;/p&gt;

&lt;p&gt;To try QRS.VAR.PEARSON yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.VAR.PEARSON. Then, open the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-estimate-var-skewness-kurtosis-excel/example.xlsx" rel="noopener noreferrer"&gt;example workbook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the workbook:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cell B1 contains the confidence level, 99%.&lt;/li&gt;
&lt;li&gt;Cell B2 contains the mean, 10%.&lt;/li&gt;
&lt;li&gt;Cell B3 contains the variance, 0.01.&lt;/li&gt;
&lt;li&gt;Cell B4 contains the skewness, -2.&lt;/li&gt;
&lt;li&gt;Cell B5 contains the kurtosis, 16.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.PEARSON.TYPE(B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ae5cy8e4lps530dhnau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ae5cy8e4lps530dhnau.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the type of Pearson distribution that fits the given moments, enter the formula &lt;code&gt;=QRS.PEARSON.TYPE(B2, B3, B4, B5)&lt;/code&gt; in cell B6. The result is IV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.VAR.PEARSON(B1, B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztbq26wbl8x2mrl7udvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztbq26wbl8x2mrl7udvu.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To estimate VaR for the corresponding Pearson Type IV distribution, enter the formula &lt;code&gt;=QRS.VAR.PEARSON(B1, B2, B3, B4, B5)&lt;/code&gt; in cell B7. The result is -23.7%, which means the investment is estimated to lose at most 23.7% in 99 out of 100 periods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Johnson SU example
&lt;/h2&gt;

&lt;p&gt;There are 3 types of Johnson distributions, namely SU, SL, and SB. To the best of our knowledge, QRS.VAR.JOHNSON is the only publicly available Excel function for estimating VaR from all 3 types of Johnson distributions by moment matching.&lt;/p&gt;

&lt;p&gt;Software that support fitting the Johnson distributions by moments typically use a method by Hill, Hill, and Holder, but that method does not always return a result. QRS.VAR.JOHNSON uses a proprietary method that is more reliable.&lt;/p&gt;

&lt;p&gt;To try QRS.VAR.JOHNSON yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.VAR.JOHNSON and reopen the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-estimate-var-skewness-kurtosis-excel/example.xlsx" rel="noopener noreferrer"&gt;workbook&lt;/a&gt; from the previous example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.JOHNSON.TYPE(B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5rukcr30smry8z3fjr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5rukcr30smry8z3fjr4.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the type of Johnson distribution that fits the given moments, enter the formula &lt;code&gt;=QRS.JOHNSON.TYPE(B2, B3, B4, B5)&lt;/code&gt; in cell B6. The result is SU.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.VAR.JOHNSON(B1, B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0b1pssg5lkqazxp8e5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0b1pssg5lkqazxp8e5a.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To estimate VaR for the corresponding Johnson SU distribution, enter the formula &lt;code&gt;=QRS.VAR.JOHNSON(B1, B2, B3, B4, B5)&lt;/code&gt; in cell B7. The result is -24.3%, which is in the same ballpark as the result from the previous example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;If you would like to use &lt;a href="https://addin.qrstoolbox.com/pages/docs/var.pearson" rel="noopener noreferrer"&gt;QRS.VAR.PEARSON&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/var.johnson" rel="noopener noreferrer"&gt;QRS.VAR.JOHNSON&lt;/a&gt; beyond your free trial periods, you may &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-buy-premium" rel="noopener noreferrer"&gt;purchase the right to use&lt;/a&gt; them indefinitely for as little as USD 19.00. If you find the QRS.VAR functions useful, please share this page with other potential users.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>statistics</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to estimate expected shortfall given skewness and kurtosis in Excel</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Mon, 15 Nov 2021 05:24:56 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-estimate-expected-shortfall-given-skewness-and-kurtosis-in-excel-1d3g</link>
      <guid>https://dev.to/quantirisk/how-to-estimate-expected-shortfall-given-skewness-and-kurtosis-in-excel-1d3g</guid>
      <description>&lt;p&gt;Risk practitioners sometimes use &lt;a href="https://en.wikipedia.org/wiki/Expected_shortfall" rel="noopener noreferrer"&gt;expected shortfall&lt;/a&gt; (ES) to quantify the potential future loss of an investment. As a risk metric, ES answers questions like "What is the average daily/monthly/yearly return going to be in the worst 1%/5%/10% of times?"&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj2amtwhxcqu8jz6y82t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj2amtwhxcqu8jz6y82t.png" alt="ES is a conditional mean" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In statistical jargon, ES is the conditional mean of the return distribution given that returns are less than the percentile at a given confidence level. The above diagram illustrates ES at the 95% confidence level.&lt;/p&gt;

&lt;p&gt;Sometimes, ES is defined in terms of a loss (instead of return) distribution. In that case, the above diagram would flip horizontally and ES would be in the right tail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mean and variance
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2766eeovb87yd9ybi91.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2766eeovb87yd9ybi91.png" alt="Normal distribution" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the mean and variance of the return distribution are given, ES can be estimated by assuming returns follow the normal distribution and calculating the conditional mean of the normal distribution that fits the given mean and variance.&lt;/p&gt;

&lt;p&gt;To estimate ES at the 95% confidence level in Excel when the mean and variance of the return distribution are 10% and 0.01 respectively, enter the formula &lt;code&gt;=10% - SQRT(0.01) * NORM.S.DIST(NORM.S.INV(1-0.95), FALSE) / (1-0.95)&lt;/code&gt; in a cell.&lt;/p&gt;

&lt;p&gt;To estimate ES when the previous mean and variance are for the loss (instead of return) distribution, change the formula to &lt;code&gt;=10% + SQRT(0.01) * NORM.S.DIST(NORM.S.INV(0.95), FALSE) / (1-0.95)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Skewness and kurtosis
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryw93i6retmyaexir7d4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryw93i6retmyaexir7d4.png" alt="Taleb distribution" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In reality, returns are more likely to follow a non-normal distribution with negative skewness and large kurtosis. According to journalist Martin Wolf, many investment strategies have a high probability of small gains and a low probability of huge losses.&lt;/p&gt;

&lt;p&gt;If the skewness and kurtosis of the return distribution are given in addition to the mean and variance, ES can be estimated by assuming returns follow a non-normal parametric distribution and calculating the conditional mean of the distribution that fits the given moments.&lt;/p&gt;

&lt;p&gt;There are many non-normal parametric distributions, but the Pearson and Johnson distributions are the only ones that fit all possible combinations of skewness and kurtosis. No other parametric distribution has such a feature.&lt;/p&gt;

&lt;p&gt;Unfortunately, Excel does not come with native functions for using the Pearson and Johnson distributions.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.ES functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsknoytr7lu7ot5pq1cfm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsknoytr7lu7ot5pq1cfm.png" alt="QRS.ES functions" width="560" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, &lt;a href="https://addin.qrstoolbox.com" rel="noopener noreferrer"&gt;QRS Toolbox for Excel&lt;/a&gt; includes functions for estimating ES from not only the normal distribution, but also the Pearson and Johnson distributions. The names of the functions all begin with QRS.ES.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/es.normal" rel="noopener noreferrer"&gt;QRS.ES.NORMAL&lt;/a&gt; returns ES for the normal distribution. It accepts the confidence level, mean, standard deviation, and choice of tail as parameters. It is simpler to use compared to the two previous formulas involving NORM.S.DIST and NORM.S.INV.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/es.pearson" rel="noopener noreferrer"&gt;QRS.ES.PEARSON&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/es.johnson" rel="noopener noreferrer"&gt;QRS.ES.JOHNSON&lt;/a&gt;  return ES for the Pearson and Johnson distributions respectively. They accept the same parameters as QRS.ES.NORMAL in addition to skewness and kurtosis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pearson Type IV example
&lt;/h2&gt;

&lt;p&gt;There are 5 main types of Pearson distributions, namely Types I, III, IV, V, and VI. To the best of our knowledge, QRS.ES.PEARSON is the only publicly available Excel function for estimating ES from all 5 types of Pearson distributions.&lt;/p&gt;

&lt;p&gt;The Pearson Type IV distribution deserves special mention. It is a natural alternative to the normal distribution in risk applications, because it is not only unimodal and unbounded, but also skewed (squared skewness &amp;lt; 32) and fat-tailed (kurtosis &amp;gt; 3).&lt;/p&gt;

&lt;p&gt;To try QRS.ES.PEARSON yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt;  of QRS.ES.PEARSON. Then, open the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-estimate-es-skewness-kurtosis-excel/example.xlsx" rel="noopener noreferrer"&gt;example workbook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the workbook:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cell B1 contains the confidence level, 99%.&lt;/li&gt;
&lt;li&gt;Cell B2 contains the mean, 10%.&lt;/li&gt;
&lt;li&gt;Cell B3 contains the variance, 0.01.&lt;/li&gt;
&lt;li&gt;Cell B4 contains the skewness, -2.&lt;/li&gt;
&lt;li&gt;Cell B5 contains the kurtosis, 16.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.PEARSON.TYPE(B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdm8x6u112dpoix8wsh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdm8x6u112dpoix8wsh2.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the type of Pearson distribution that fits the given moments, enter the formula &lt;code&gt;=QRS.PEARSON.TYPE(B2, B3, B4, B5)&lt;/code&gt; in cell B6. The result is IV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.ES.PEARSON(B1, B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7rr44oyfc292kahs7oy2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7rr44oyfc292kahs7oy2.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To estimate ES for the corresponding Pearson Type IV distribution, enter the formula &lt;code&gt;=QRS.ES.PEARSON(B1, B2, B3, B4, B5)&lt;/code&gt; in cell B7. The result is -36.7%, which means the investment is estimated to lose on average 36.7% in 1 out of 100 periods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Johnson SU example
&lt;/h2&gt;

&lt;p&gt;There are 3 types of Johnson distributions, namely SU, SL, and SB. To the best of our knowledge, QRS.ES.JOHNSON is the only publicly available Excel function for estimating ES from all 3 types of Johnson distributions by moment matching.&lt;/p&gt;

&lt;p&gt;Software that support fitting the Johnson distributions by moments typically use a method by Hill, Hill, and Holder, but that method does not always return a result. QRS.ES.JOHNSON uses a proprietary method that is more reliable.&lt;/p&gt;

&lt;p&gt;To try QRS.ES.JOHNSON yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.ES.JOHNSON and reopen the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-estimate-es-skewness-kurtosis-excel/example.xlsx" rel="noopener noreferrer"&gt;workbook&lt;/a&gt; from the previous example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.JOHNSON.TYPE(B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3um9n5n454f6mw10fsl1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3um9n5n454f6mw10fsl1.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the type of Johnson distribution that fits the given moments, enter the formula &lt;code&gt;=QRS.JOHNSON.TYPE(B2, B3, B4, B5)&lt;/code&gt; in cell B6. The result is SU.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.ES.JOHNSON(B1, B2, B3, B4, B5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ferwykhx393b2k3n3ybei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ferwykhx393b2k3n3ybei.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To estimate ES for the corresponding Johnson SU distribution, enter the formula &lt;code&gt;=QRS.ES.JOHNSON(B1, B2, B3, B4, B5)&lt;/code&gt; in cell B7. The result is -38.1%, which is in the same ballpark as the result from the previous example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;If you would like to use &lt;a href="https://addin.qrstoolbox.com/pages/docs/es.pearson" rel="noopener noreferrer"&gt;QRS.ES.PEARSON&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/es.johnson" rel="noopener noreferrer"&gt;QRS.ES.JOHNSON&lt;/a&gt; beyond your free trial periods, you may &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-buy-premium" rel="noopener noreferrer"&gt;purchase the right to use&lt;/a&gt; them indefinitely for as little as USD 19.00. If you find the QRS.ES functions useful, please share this page with other potential users.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>statistics</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to perform logistic regression in Excel using only a formula</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Mon, 08 Nov 2021 01:19:23 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-perform-logistic-regression-using-a-formula-in-excel-1nef</link>
      <guid>https://dev.to/quantirisk/how-to-perform-logistic-regression-using-a-formula-in-excel-1nef</guid>
      <description>&lt;p&gt;Logistic regression is a process for modelling the probability of a binary outcome in terms of explanatory factors using a logistic function. It can be used to model the probability of a risk event occurring, such as credit default and insurance fraud.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.LOGISTIC.REGRESSION
&lt;/h2&gt;

&lt;p&gt;QRS Toolbox for Excel includes the &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.regression" rel="noopener noreferrer"&gt;QRS.LOGISTIC.REGRESSION&lt;/a&gt; function for performing logistic regression using nothing more than a formula. The function includes options to return the same results as more expensive commercial products.&lt;/p&gt;

&lt;p&gt;To try QRS.LOGISTIC.REGRESSION yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.LOGISTIC.REGRESSION. Then, download and open the &lt;a href="https://addin.qrstoolbox.com/pages/demos/how-to-perform-logistic-regression-excel/example.xlsx" rel="noopener noreferrer"&gt;example workbook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fop3bhzzgjjp7uei5s9og.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fop3bhzzgjjp7uei5s9og.png" alt="Data" width="560" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the workbook:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cells A7–A33 contain identifiers for 27 leukemia patients.&lt;/li&gt;
&lt;li&gt;Cells B7–B33 contain ones if remission occurred and zeros otherwise.&lt;/li&gt;
&lt;li&gt;Cells C7–H33 contain factors that potentially explain the occurrence of remission.&lt;/li&gt;
&lt;li&gt;Cells C6–H6 contain shortened names of the factors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Constant and coefficients
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4tm9gxxjjpfyk1dfap0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4tm9gxxjjpfyk1dfap0.png" alt="Formula" width="560" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To perform a logistic regression between the occurrence of remission and the given factors, enter the formula &lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33)&lt;/code&gt; in cell A1. The result contains 7 numbers. The first number is the regression constant. The remaining 6 numbers are the coefficients of the factors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Labels and headers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33, "LABELS", TRUE, "NAMES", C6:H6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92s3hrccump6fpk1fk5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92s3hrccump6fpk1fk5q.png" alt="Formula" width="560" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To improve the presentation of the result, add &lt;code&gt;"LABELS", TRUE&lt;/code&gt; and &lt;code&gt;"NAMES", C6:H6&lt;/code&gt; to the formula. The result now contains row labels and column headers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Significance tests
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33, "LABELS", TRUE, "NAMES", C6:H6, "LRTEST", "RAG")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpdh7j3izjpbl3nc8now8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpdh7j3izjpbl3nc8now8.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To determine the statistical significance of the factors, add &lt;code&gt;"LRTEST", "RAG"&lt;/code&gt; to the formula. The result now contains red/amber/green ratings that summarize the likelihood ratio test for each factor.&lt;/p&gt;

&lt;p&gt;The LI factor has a green rating. The other factors have red ratings. A green/amber rating means a factor is significant at the 5%/10% significance level. A red rating means a factor is not significant at the 10% significance level.&lt;/p&gt;

&lt;p&gt;Please read the &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.regression" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to learn how to return the test statistic and p-value of the likelihood ratio test, as well as the corresponding results of the Wald test.&lt;/p&gt;

&lt;h3&gt;
  
  
  Significance levels
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33, "LABELS", TRUE, "NAMES", C6:H6, "LRTEST", "RAG", "PGREEN", 0.3, "PRED", 0.35)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgtqtkirz47nvwogxsw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgtqtkirz47nvwogxsw7.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To change the significance levels from the default values of 5% and 10% to, say, 30% and 35%, add &lt;code&gt;"PGREEN", 0.3&lt;/code&gt; and &lt;code&gt;"PRED", 0.35&lt;/code&gt; to the formula. The TEMP factor now has a green rating too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Manual factor selection
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33, "LABELS", TRUE, "NAMES", C6:H6, "LRTEST", "RAG", "PGREEN", 0.3, "PRED", 0.35, "MASK", C5:H5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzrfhq6d9gp5l6blog9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzrfhq6d9gp5l6blog9c.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To manually select only the LI and TEMP factors, enter &lt;code&gt;0, 0, 0, 1, 0, 1&lt;/code&gt; in cells C5–H5 and add &lt;code&gt;"MASK", C5:H5&lt;/code&gt; to the formula. The excluded factors now have coefficients equal to zero.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatic factor selection
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.REGRESSION(C7:H33, B7:B33, "LABELS", TRUE, "NAMES", C6:H6, "LRTEST", "RAG", "PGREEN", 0.3, "PRED", 0.35, "METHOD", "STEPWISE")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc3kkxgbsx63j0w7fzog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc3kkxgbsx63j0w7fzog.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To automatically select factors using stepwise selection, remove &lt;code&gt;"MASK", C5:H5&lt;/code&gt; and add &lt;code&gt;"METHOD", "STEPWISE"&lt;/code&gt; to the formula. The automatically selected factors are CELL, LI, and TEMP.&lt;/p&gt;

&lt;p&gt;Please read the &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.regression" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to learn how to use forward selection or backward elimination instead, and how to control the significance levels for factor selection.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.LOGISTIC.MODEL
&lt;/h2&gt;

&lt;p&gt;You can calculate the probability modelled by a logistic regression in Excel using the &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.model" rel="noopener noreferrer"&gt;QRS.LOGISTIC.MODEL&lt;/a&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.LOGISTIC.MODEL(B$2:H$2, C7:H7)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqquvksctqlq9lnsx83ki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqquvksctqlq9lnsx83ki.png" alt="Formula" width="560" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Continuing from the example above, to calculate the probability of remission, enter the formula &lt;code&gt;=QRS.LOGISTIC.MODEL(B$2:H$2, C7:H7)&lt;/code&gt; in cell I7, and copy the formula across cells I8–I33.&lt;/p&gt;

&lt;p&gt;The probability of remission for Patient 01 is 72%. The probability for Patient 02 is 58%. The probability for Patient 03 is 10%, and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;If you find &lt;a href="https://addin.qrstoolbox.com/pages/docs/logistic.regression" rel="noopener noreferrer"&gt;QRS.LOGISTIC.REGRESSION&lt;/a&gt; useful and would like to use it beyond your free trial period, you may &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-buy-premium" rel="noopener noreferrer"&gt;purchase the right to use&lt;/a&gt; it indefinitely for as little as USD 29.00.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>statistics</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to seamlessly exchange data between JavaScript environments</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Thu, 04 Nov 2021 02:22:55 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-seamlessly-exchange-data-between-javascript-environments-32aa</link>
      <guid>https://dev.to/quantirisk/how-to-seamlessly-exchange-data-between-javascript-environments-32aa</guid>
      <description>&lt;h2&gt;
  
  
  JSON limitations
&lt;/h2&gt;

&lt;p&gt;Wouldn't you find it strange if adults who are fluent in the same language spoke to each other using the vocabulary of a 3-year-old? Well, something analogous is happening when browsers and JavaScript servers exchange data using JSON, the de facto serialization format on the internet.&lt;/p&gt;

&lt;p&gt;For example, if we wanted to send a &lt;code&gt;Date&lt;/code&gt; object from a JavaScript server to a browser, we would have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert the &lt;code&gt;Date&lt;/code&gt; object to a number.&lt;/li&gt;
&lt;li&gt;Convert the number to a JSON string.&lt;/li&gt;
&lt;li&gt;Send the JSON string to the browser.&lt;/li&gt;
&lt;li&gt;Revert the JSON string to a number.&lt;/li&gt;
&lt;li&gt;Realize the number represents a date.&lt;/li&gt;
&lt;li&gt;Revert the number to a &lt;code&gt;Date&lt;/code&gt; object.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This roundabout route seems ludicrous, because the browser and server both support the &lt;code&gt;Date&lt;/code&gt; object, but is necessary, because JSON does not support the &lt;code&gt;Date&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;In fact, JSON does not support most of the data types and data structures intrinsic to JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoakh1kdpn6hx190d30i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoakh1kdpn6hx190d30i.png" alt="JavaScript data supported by JSON" width="320" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JOSS as a solution
&lt;/h2&gt;

&lt;p&gt;The aforementioned limitations of JSON motivated us to create the JS Open Serialization Scheme (JOSS), a new binary serialization format that supports almost all data types and data structures intrinsic to JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdm5uns2ksvso59eyxdrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdm5uns2ksvso59eyxdrj.png" alt="JavaScript data supported by JOSS" width="320" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JOSS also supports some often overlooked features of JavaScript, such as primitive wrapper objects, circular references, sparse arrays, and negative zeros. Please read the &lt;a href="https://github.com/quantirisk/joss/blob/main/SPECS.md" rel="noopener noreferrer"&gt;official specification&lt;/a&gt; for all the gory details.&lt;/p&gt;

&lt;p&gt;JOSS serializations come with the textbook advantages that binary formats have over text formats, such as efficient storage of numeric data and ability to be consumed as streams. The latter allows for JOSS serializations to be handled asynchronously, which we shall see in the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference implementation
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://github.com/quantirisk/joss" rel="noopener noreferrer"&gt;reference implementation&lt;/a&gt; of JOSS is available to be downloaded as an &lt;a href="https://github.com/quantirisk/joss/raw/main/joss.min.js" rel="noopener noreferrer"&gt;ES module&lt;/a&gt; (for browsers and Deno), &lt;a href="https://github.com/quantirisk/joss/raw/main/joss.node.min.js" rel="noopener noreferrer"&gt;CommonJS module&lt;/a&gt; (for Node.js), and &lt;a href="https://github.com/quantirisk/joss/raw/main/joss.iife.min.js" rel="noopener noreferrer"&gt;IIFE&lt;/a&gt; (for older browsers). It provides the following methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;serialize()&lt;/code&gt; and &lt;code&gt;deserialize()&lt;/code&gt; to handle serializations in the form of static data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;serializable()&lt;/code&gt;, &lt;code&gt;deserializable()&lt;/code&gt;, and &lt;code&gt;deserializing()&lt;/code&gt; to handle serializations in the form of readable streams.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To illustrate the syntax of the methods, allow us to guide you through an example in Node.js.&lt;/p&gt;

&lt;p&gt;First, we import the CommonJS module into a variable called &lt;code&gt;JOSS&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Change the path accordingly&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/path/to/joss.node.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we create some dummy data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;simples&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;u2661 JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;bigints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;72057594037927935&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1152921504606846975&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;sparse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;object&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}},&lt;/span&gt;
  &lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)]]),&lt;/span&gt;
  &lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;)]),&lt;/span&gt;
  &lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;regexp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/ab+c/gi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To serialize the data, we use the &lt;code&gt;JOSS.serialize()&lt;/code&gt; method, which returns the serialized bytes as a &lt;code&gt;Uint8Array&lt;/code&gt; or &lt;code&gt;Buffer&lt;/code&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To deserialize, we use the &lt;code&gt;JOSS.deserialize()&lt;/code&gt; method, which simply returns the deserialized data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deserialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we inspect the original data and deserialized data, we will find they look exactly the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should be evident by now that you can migrate from JSON to JOSS by replacing all occurrences of &lt;code&gt;JSON.stringify/parse&lt;/code&gt; in your code with &lt;code&gt;JOSS.serialize/deserialize&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Readable Streams
&lt;/h3&gt;

&lt;p&gt;If the data to be serialized is large, it is better to work with readable streams to avoid blocking the JavaScript event loop.&lt;/p&gt;

&lt;p&gt;To serialize the data, we use the &lt;code&gt;JOSS.serializable()&lt;/code&gt; method, which returns a readable stream from which the serialized bytes can be read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serializable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To deserialize, we use the &lt;code&gt;JOSS.deserializable()&lt;/code&gt; method, which returns a writable stream to which the readable stream can be piped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;writable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deserializable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;readable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;finish&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To access the deserialized data, we wait for the piping process to complete and read the &lt;code&gt;result&lt;/code&gt; property of the writable stream.&lt;/p&gt;

&lt;p&gt;Whilst writable streams are well supported in Deno and Node.js, they are either not supported or not enabled by default in browsers at the present time.&lt;/p&gt;

&lt;p&gt;To deserialize when we do not have recourse to writable streams, we use the &lt;code&gt;JOSS.deserializing()&lt;/code&gt; method, which returns a &lt;code&gt;Promise&lt;/code&gt; that resolves to the deserialized data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serializable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JOSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deserializing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;readable2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Servers
&lt;/h3&gt;

&lt;p&gt;In practice, we would serialize data to be sent in an outgoing HTTP request or response, and deserialize data received from an incoming HTTP request or response.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/quantirisk/joss" rel="noopener noreferrer"&gt;reference implementation&lt;/a&gt; page contains examples on how to use JOSS in the context of the &lt;a href="https://github.com/quantirisk/joss/#fetch-api" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt;, &lt;a href="https://github.com/quantirisk/joss/#deno-http-server" rel="noopener noreferrer"&gt;Deno HTTP server&lt;/a&gt;, and &lt;a href="https://github.com/quantirisk/joss/#nodejs-http-server" rel="noopener noreferrer"&gt;Node.js HTTP server&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing remarks
&lt;/h2&gt;

&lt;p&gt;JOSS will evolve with the JavaScript specification. To keep track of changes to JOSS, please star or watch the &lt;a href="https://github.com/quantirisk/joss" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>deno</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to generate random numbers for Monte Carlo simulation in Excel</title>
      <dc:creator>Wynn Tee</dc:creator>
      <pubDate>Sun, 31 Oct 2021 03:41:23 +0000</pubDate>
      <link>https://dev.to/quantirisk/how-to-generate-random-numbers-for-monte-carlo-simulation-in-excel-159i</link>
      <guid>https://dev.to/quantirisk/how-to-generate-random-numbers-for-monte-carlo-simulation-in-excel-159i</guid>
      <description>&lt;p&gt;Risk practitioners often use Monte Carlo simulation to simulate the potential future outcomes of a decision. A key requirement for Monte Carlo simulation is the ability to generate random numbers from a desired probability distribution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Analysis Toolpak
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztywgae07ynx6yxv2241.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztywgae07ynx6yxv2241.png" alt="Analysis Toolpak" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Excel comes with an add-in called Analysis Toolpak, which includes a graphical user interface for generating random numbers from the uniform distribution, normal distribution, and several discrete probability distributions.&lt;/p&gt;

&lt;p&gt;However, the graphical user interface can be inconvenient when you want to change the parameters or regenerate the random numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  RANDARRAY function
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdsxuxl1piqd2ho911o0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdsxuxl1piqd2ho911o0.png" alt="RANDARRAY function" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Excel also comes with the RAND and RANDARRAY functions, which return uniformly distributed random numbers. The functions can be used with &lt;a href="https://en.wikipedia.org/wiki/Inverse_transform_sampling" rel="noopener noreferrer"&gt;inverse sampling&lt;/a&gt; to generate random numbers from any probability distribution whose inverse cumulative distribution function can be evaluated in Excel.&lt;/p&gt;

&lt;p&gt;For example, to generate a column of 100,000 random numbers from the standard normal distribution, enter the formula &lt;code&gt;=NORM.S.INV(RANDARRAY(100000,1))&lt;/code&gt; in a cell.&lt;/p&gt;

&lt;p&gt;However, this method can be inefficient when you want to generate a lot of random numbers and the inverse cumulative distribution function is expensive to evaluate.&lt;/p&gt;

&lt;h2&gt;
  
  
  QRS.RAND functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffol1h19y1nl77bv4xzwk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffol1h19y1nl77bv4xzwk.png" alt="QRS.RAND functions" width="560" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com" rel="noopener noreferrer"&gt;QRS Toolbox for Excel&lt;/a&gt; includes functions for generating random numbers from some probability distributions using &lt;a href="https://en.wikipedia.org/wiki/Rejection_sampling" rel="noopener noreferrer"&gt;rejection sampling&lt;/a&gt;. The names of all the functions begin with QRS.RAND.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/rand.normal" rel="noopener noreferrer"&gt;QRS.RAND.NORMAL&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/rand.exp" rel="noopener noreferrer"&gt;QRS.RAND.EXP&lt;/a&gt; return random numbers from the normal and exponential distributions respectively using the &lt;a href="https://en.wikipedia.org/wiki/Ziggurat_algorithm" rel="noopener noreferrer"&gt;ziggurat algorithm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/rand.gamma" rel="noopener noreferrer"&gt;QRS.RAND.GAMMA&lt;/a&gt; returns random numbers from the gamma distribution. It can be used to generate random numbers from gamma-related distributions, such as the chi-squared distribution and Beta distribution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addin.qrstoolbox.com/pages/docs/rand.pearson" rel="noopener noreferrer"&gt;QRS.RAND.PEARSON&lt;/a&gt; and &lt;a href="https://addin.qrstoolbox.com/pages/docs/rand.johnson" rel="noopener noreferrer"&gt;QRS.RAND.JOHNSON&lt;/a&gt; return random numbers from the Pearson and Johnson distributions respectively. They can be used to simulate rare but extreme events, because the Pearson and Johnson distributions uniquely fit all possible combinations of skewness and kurtosis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pearson Type IV example
&lt;/h2&gt;

&lt;p&gt;There are in fact 5 types of Pearson distributions, namely Types I, III, IV, V, and VI. To the best of our knowledge, QRS.RAND.PEARSON is the only publicly available Excel function for generating random numbers from all 5 types of Pearson distributions.&lt;/p&gt;

&lt;p&gt;The Pearson Type IV distribution deserves special mention. It is a natural alternative to the normal distribution in risk applications, because it is not only unimodal and unbounded, but also skewed (squared skewness &amp;lt; 32) and fat-tailed(kurtosis &amp;gt; 3).&lt;/p&gt;

&lt;p&gt;To try QRS.RAND.PEARSON yourself, &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-add-toolbox" rel="noopener noreferrer"&gt;add QRS Toolbox&lt;/a&gt; to your instance of Excel and &lt;a href="https://addin.qrstoolbox.com/pages/support/#how-to-try-premium" rel="noopener noreferrer"&gt;start your free trial&lt;/a&gt; of QRS.RAND.PEARSON. Then, open a blank workbook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.RAND.PEARSON(100000, 1, 0, 1, 2, 16)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsty9onmy0qqrj52pq5jk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsty9onmy0qqrj52pq5jk.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To generate a column of 100,000 random numbers from the Pearson Type IV distribution with mean 0, variance 1, skewness 2, and kurtosis 16, enter the formula &lt;code&gt;=QRS.RAND.PEARSON(100000, 1, 0, 1, 2, 16)&lt;/code&gt; in cell A1. The random numbers appear in cells A1:A100000.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=QRS.RAND.PEARSON(100000, 5, 0, 1, 2, 16)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk611mnfxvoknhhpdk77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk611mnfxvoknhhpdk77.png" alt="Formula" width="560" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To generate 5 columns of random numbers instead, change the second argument to 5 so that the formula becomes &lt;code&gt;=QRS.RAND.PEARSON(100000, 5, 0, 1, 2, 16)&lt;/code&gt;. The random numbers now appear in cells A1:E100000.&lt;/p&gt;

&lt;p&gt;To regenerate the random numbers, simply recalculate cell A1. Unlike the RAND and RANDARRAY functions, the QRS.RAND functions are designed to be non-volatile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final remarks
&lt;/h2&gt;

&lt;p&gt;The other QRS.RAND functions can be used in a similar manner. If you find the QRS.RAND functions useful, please share this page with other potential users.&lt;/p&gt;

</description>
      <category>excel</category>
      <category>risk</category>
      <category>datascience</category>
      <category>montecarlo</category>
    </item>
  </channel>
</rss>
