1"use strict";(self.webpackChunkdocumentation=self.webpackChunkdocumentation||[]).push([["3599"],{88888:function(s,e,a){a.r(e),a.d(e,{frontMatter:()=>r,toc:()=>h,default:()=>d,metadata:()=>n,assets:()=>c,contentTitle:()=>t});var n=JSON.parse('{"id":"query/functions/finance","title":"Finance functions","description":"Market data and financial functions including l2price, mid, spread_bps, TWAP, VWAP, and wmid for order book, execution benchmarking, and pricing analysis.","source":"@site/documentation/query/functions/finance.md","sourceDirName":"query/functions","slug":"/query/functions/finance","permalink":"/docs/query/functions/finance","draft":false,"unlisted":false,"editUrl":"https://github.com/questdb/documentation/edit/main/documentation/query/functions/finance.md","tags":[],"version":"current","frontMatter":{"title":"Finance functions","sidebar_label":"Finance","description":"Market data and financial functions including l2price, mid, spread_bps, TWAP, VWAP, and wmid for order book, execution benchmarking, and pricing analysis."},"sidebar":"docs","previous":{"title":"Date and time","permalink":"/docs/query/functions/date-time"},"next":{"title":"Hash","permalink":"/docs/query/functions/hash"}}'),l=a(85893),i=a(50065);let r={title:"Finance functions",sidebar_label:"Finance",description:"Market data and financial functions including l2price, mid, spread_bps, TWAP, VWAP, and wmid for order book, execution benchmarking, and pricing analysis."},t=void 0,c={},h=[{value:"l2price",id:"l2price",level:2},{value:"Parameters",id:"parameters",level:3},{value:"Return value",id:"return-value",level:3},{value:"Examples - ARRAY",id:"examples---array",level:3},{value:"Examples - scalar columns",id:"examples---scalar-columns",level:3},{value:"mid",id:"mid",level:2},{value:"Parameters",id:"parameters-1",level:3},{value:"Return value",id:"return-value-1",level:3},{value:"Examples",id:"examples",level:3},{value:"regr_intercept",id:"regr_intercept",level:2},{value:"Calculation",id:"calculation",level:3},{value:"Arguments",id:"arguments",level:3},{value:"Return value",id:"return-value-2",level:3},{value:"Examples",id:"examples-1",level:3},{value:"Calculate the regression intercept between two variables",id:"calculate-the-regression-intercept-between-two-variables",level:4},{value:"Calculate the regression intercept grouped by category",id:"calculate-the-regression-intercept-grouped-by-category",level:4},{value:"Handling null values",id:"handling-null-values",level:4},{value:"regr_r2",id:"regr_r2",level:2},{value:"Calculation",id:"calculation-1",level:3},{value:"Arguments",id:"arguments-1",level:3},{value:"Return value",id:"return-value-3",level:3},{value:"Examples",id:"examples-2",level:3},{value:"Measure how well the open explains the close",id:"measure-how-well-the-open-explains-the-close",level:4},{value:"Compare fit quality across instruments",id:"compare-fit-quality-across-instruments",level:4},{value:"regr_slope",id:"regr_slope",level:2},{value:"Calculation",id:"calculation-2",level:3},{value:"Arguments",id:"arguments-2",level:3},{value:"Return value",id:"return-value-4",level:3},{value:"Examples",id:"examples-3",level:3},{value:"Calculate the regression slope between two variables",id:"calculate-the-regression-slope-between-two-variables",level:4},{value:"Calculate the regression slope grouped by a category",id:"calculate-the-regression-slope-grouped-by-a-category",level:4},{value:"Handling null values",id:"handling-null-values-1",level:4},{value:"Calculating beta",id:"calculating-beta",level:4},{value:"spread_bps",id:"spread_bps",level:2},{value:"Parameters",id:"parameters-2",level:3},{value:"Return value",id:"return-value-5",level:3},{value:"Examples",id:"examples-4",level:3},{value:"TWAP (Time-Weighted Average Price)",id:"twap-time-weighted-average-price",level:2},{value:"VWAP (Volume-Weighted Average Price)",id:"vwap-volume-weighted-average-price",level:2},{value:"wmid",id:"wmid",level:2},{value:"Parameters",id:"parameters-3",level:3},{value:"Return value",id:"return-value-6",level:3},{value:"Examples",id:"examples-5",level:3}];function m(s){let e={a:"a",annotation:"annotation",code:"code",em:"em",h2:"h2",h3:"h3",h4:"h4",li:"li",math:"math",mfrac:"mfrac",mi:"mi",mn:"mn",mo:"mo",mover:"mover",mrow:"mrow",msub:"msub",msubsup:"msubsup",msup:"msup",mtext:"mtext",p:"p",pre:"pre",semantics:"semantics",span:"span",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.a)(),...s.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(e.p,{children:"This page describes functions specific to the financial services domain."}),"\n",(0,l.jsx)(e.h2,{id:"l2price",children:"l2price"}),"\n",(0,l.jsx)(e.p,{children:"Level-2 trade price calculation."}),"\n",(0,l.jsx)(e.p,{children:(0,l.jsx)(e.code,{children:"l2price(target_size, size_array, price_array)"})}),"\n",(0,l.jsx)(e.p,{children:(0,l.jsx)(e.code,{children:"l2price(target_size, size_1, price_1, size_2, price_2, ..., size_n, price_n)"})}),"\n",(0,l.jsxs)(e.p,{children:["Consider ",(0,l.jsx)(e.code,{children:"size_1"}),", ",(0,l.jsx)(e.code,{children:"price_1"}),", ",(0,l.jsx)(e.code,{children:"size_2"}),", ",(0,l.jsx)(e.code,{children:"price_2"}),", ..., ",(0,l.jsx)(e.code,{children:"size_n"}),",\n",(0,l.jsx)(e.code,{children:"price_n"})," to be either side of an order book with ",(0,l.jsx)(e.code,{children:"n"})," price levels. Then, the\nreturn value of the function is the average trade price of a market order\nexecuted with the size of ",(0,l.jsx)(e.code,{children:"target_size"})," against the book."]}),"\n",(0,l.jsx)(e.p,{children:"Let's take the below order book as an example."}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"Size"}),(0,l.jsx)(e.th,{children:"Bid"}),(0,l.jsx)(e.th,{children:"Ask"}),(0,l.jsx)(e.th,{children:"Size"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"10"}),(0,l.jsx)(e.td,{children:"14.10"}),(0,l.jsx)(e.td,{children:"14.50"}),(0,l.jsx)(e.td,{children:"14"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"17"}),(0,l.jsx)(e.td,{children:"14.00"}),(0,l.jsx)(e.td,{children:"14.60"}),(0,l.jsx)(e.td,{children:"16"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"19"}),(0,l.jsx)(e.td,{children:"13.90"}),(0,l.jsx)(e.td,{children:"14.80"}),(0,l.jsx)(e.td,{children:"23"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"21"}),(0,l.jsx)(e.td,{children:"13.70"}),(0,l.jsx)(e.td,{children:"15.10"}),(0,l.jsx)(e.td,{children:"12"})]})]})]}),"\n",(0,l.jsxs)(e.p,{children:["A ",(0,l.jsx)(e.em,{children:"buy market order"})," with the size of 50 would wipe out the first two price\nlevels of the ",(0,l.jsx)(e.em,{children:"Ask"})," side of the book, and would also trade on the third level."]}),"\n",(0,l.jsx)(e.p,{children:"The full price of the trade:"}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mn,{children:"14"}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"14.50"}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsx)(e.mn,{children:"16"}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"14.60"}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsx)(e.mn,{children:"50"}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsx)(e.mn,{children:"14"}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsx)(e.mn,{children:"16"}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"14.80"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"732.60"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"14 \\cdot \\$14.50 + 16 \\cdot \\$14.60 + (50 - 14 - 16) \\cdot \\$14.80 = \\$732.60"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"14"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8333em",verticalAlign:"-0.0833em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$14.50"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"16"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8333em",verticalAlign:"-0.0833em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$14.60"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsx)(e.span,{className:"mord",children:"50"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.7278em",verticalAlign:"-0.0833em"}}),(0,l.jsx)(e.span,{className:"mord",children:"14"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mord",children:"16"}),(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8056em",verticalAlign:"-0.0556em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$14.80"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8056em",verticalAlign:"-0.0556em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$732.60"})]})]})]})}),"\n",(0,l.jsx)(e.p,{children:"The average price of the instrument in this trade:"}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"732.60"}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"/"}),(0,l.jsx)(e.mn,{children:"50"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsx)(e.mi,{mathvariant:"normal",children:"$"}),(0,l.jsx)(e.mn,{children:"14.652"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\$732.60 / 50 = \\$14.652"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$732.60/50"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8056em",verticalAlign:"-0.0556em"}}),(0,l.jsx)(e.span,{className:"mord",children:"$14.652"})]})]})]})}),"\n",(0,l.jsx)(e.p,{children:"This average trade price is the output of the function when executed with the\nparameters taken from the above example:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"select l2price(50, ARRAY[14.0, 16.0, 23.0, 12.0], ARRAY[14.50, 14.60, 14.80, 15.10]);\n"})}),"\n",(0,l.jsx)(e.p,{children:"or"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"select l2price(50, 14, 14.50, 16, 14.60, 23, 14.80, 12, 15.10);\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"l2price"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"14.652"})})})]}),"\n",(0,l.jsx)(e.h3,{id:"parameters",children:"Parameters"}),"\n",(0,l.jsx)(e.p,{children:"There are two variants of the function, one accepting arrays of numbers,\nand the other accepting individual numbers:"}),"\n",(0,l.jsxs)(e.p,{children:["The variant with arrays takes a ",(0,l.jsx)(e.code,{children:"target size"}),", and a pair of arrays of type\n",(0,l.jsx)(e.code,{children:"DOUBLE[]"}),": ",(0,l.jsx)(e.code,{children:"size"})," and ",(0,l.jsx)(e.code,{children:"price"}),". The arrays must match in length. Each\nelement of the array represents a price level of the order book."]}),"\n",(0,l.jsxs)(e.p,{children:["The variant with individual numbers takes a ",(0,l.jsx)(e.code,{children:"target size"}),", and a variable\nnumber of ",(0,l.jsx)(e.code,{children:"size"}),"/",(0,l.jsx)(e.code,{children:"price"})," pairs of type ",(0,l.jsx)(e.code,{children:"DOUBLE"}),", or convertible to ",(0,l.jsx)(e.code,{children:"DOUBLE"}),"\n(",(0,l.jsx)(e.code,{children:"FLOAT"}),", ",(0,l.jsx)(e.code,{children:"LONG"}),", ",(0,l.jsx)(e.code,{children:"INT"}),", ",(0,l.jsx)(e.code,{children:"SHORT"}),", ",(0,l.jsx)(e.code,{children:"BYTE"}),")."]}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"target_size"}),": The size of a hypothetical market order to be filled."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"size*"}),": The sizes of offers available at the corresponding price levels (can\nbe fractional)."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"price*"}),": Price levels of the order book."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["The function returns a ",(0,l.jsx)(e.code,{children:"double"}),", representing the average trade price."]}),"\n",(0,l.jsxs)(e.p,{children:["It returns ",(0,l.jsx)(e.code,{children:"NULL"})," if the price is not calculable. For example, if the target\nsize cannot be filled, or there is incomplete data in the set (nulls)."]}),"\n",(0,l.jsx)(e.h3,{id:"examples---array",children:"Examples - ARRAY"}),"\n",(0,l.jsx)(e.p,{children:"Test data:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"CREATE TABLE order_book (\n ts TIMESTAMP,\n bidSize DOUBLE[], bid DOUBLE[],\n askSize DOUBLE[], ask DOUBLE[]\n) TIMESTAMP(ts) PARTITION BY DAY;\n\nINSERT INTO order_book VALUES\n ('2024-05-22T09:40:15.006000Z',\n ARRAY[40.0, 47.0, 39.0], ARRAY[14.10, 14.00, 13.90],\n ARRAY[54.0, 36.0, 23.0], ARRAY[14.50, 14.60, 14.8
10]),\n ('2024-05-22T09:40:15.175000Z',\n ARRAY[42.0, 45.0, 35.0], ARRAY[14.00, 13.90, 13.80],\n ARRAY[16.0, 57.0, 30.0], ARRAY[14.30, 14.50, 14.60]),\n ('2024-05-22T09:40:15.522000Z',\n ARRAY[36.0, 38.0, 31.0], ARRAY[14.10, 14.00, 13.90],\n ARRAY[30.0, 47.0, 34.0], ARRAY[14.40, 14.50, 14.60]);\n"})}),"\n",(0,l.jsx)(e.p,{children:"Trading price of instrument when buying 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, askSize, ask) AS buy FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"buy"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"14.565999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"14.495"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"14.493"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Trading price of instrument when selling 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, bidSize, bid) AS sell FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"sell"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"14.027"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"13.929"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"14.01"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"The spread for target quantity 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, askSize, ask) - L2PRICE(100, bidSize, bid) AS spread FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"spread"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"0.538999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"0.565999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"0.483"})]})]})]}),"\n",(0,l.jsx)(e.h3,{id:"examples---scalar-columns",children:"Examples - scalar columns"}),"\n",(0,l.jsx)(e.p,{children:"Test data:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"CREATE TABLE order_book (\n ts TIMESTAMP,\n bidSize1 DOUBLE, bid1 DOUBLE, bidSize2 DOUBLE, bid2 DOUBLE, bidSize3 DOUBLE, bid3 DOUBLE,\n askSize1 DOUBLE, ask1 DOUBLE, askSize2 DOUBLE, ask2 DOUBLE, askSize3 DOUBLE, ask3 DOUBLE\n) TIMESTAMP(ts) PARTITION BY DAY;\n\nINSERT INTO order_book VALUES\n ('2024-05-22T09:40:15.006000Z', 40, 14.10, 47, 14.00, 39, 13.90, 54, 14.50, 36, 14.60, 23, 14.80),\n ('2024-05-22T09:40:15.175000Z', 42, 14.00, 45, 13.90, 35, 13.80, 16, 14.30, 57, 14.50, 30, 14.60),\n ('2024-05-22T09:40:15.522000Z', 36, 14.10, 38, 14.00, 31, 13.90, 30, 14.40, 47, 14.50, 34, 14.60);\n"})}),"\n",(0,l.jsx)(e.p,{children:"Trading price of instrument when buying 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, askSize1, ask1, askSize2, ask2, askSize3, ask3) AS buy FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"buy"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"14.565999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"14.495"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"14.493"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Trading price of instrument when selling 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, bidSize1, bid1, bidSize2, bid2, bidSize3, bid3) AS sell FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"sell"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"14.027"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"13.929"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"14.01"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"The spread for target size of 100:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT ts, L2PRICE(100, askSize1, ask1, askSize2, ask2, askSize3, ask3)\n - L2PRICE(100, bidSize1, bid1, bidSize2, bid2, bidSize3, bid3) AS spread FROM order_book;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"ts"}),(0,l.jsx)(e.th,{children:"spread"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.006000Z"}),(0,l.jsx)(e.td,{children:"0.538999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.175000Z"}),(0,l.jsx)(e.td,{children:"0.565999999999"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2024-05-22T09:40:15.522000Z"}),(0,l.jsx)(e.td,{children:"0.483"})]})]})]}),"\n",(0,l.jsx)(e.h2,{id:"mid",children:"mid"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"mid(bid, ask)"})," - calculates the midpoint of a bidding price and asking price."]}),"\n",(0,l.jsx)(e.p,{children:"Returns null if either argument is NaN or null."}),"\n",(0,l.jsx)(e.h3,{id:"parameters-1",children:"Parameters"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"bid"})," is any numeric bidding price value."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"ask"})," is any numeric asking price value."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-1",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT mid(1.5760, 1.5763)\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{style:{textAlign:"left"},children:"mid"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{style:{textAlign:"left"},children:"1.57615"})})})]}),"\n",(0,l.jsx)(e.h2,{id:"regr_intercept",children:"regr_intercept"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"regr_intercept(y, x)"})," - Calculates the y-intercept of the linear regression line for the given numeric columns y (dependent variable) and x (independent variable)."]}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:["The function requires at least two valid (y, x) pairs to compute the intercept.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"If fewer than two pairs are available, the function returns null."}),"\n"]}),"\n"]}),"\n",(0,l.jsxs)(e.li,{children:["Supported data types for x and y include ",(0,l.jsx)(e.code,{children:"double"}),", ",(0,l.jsx)(e.code,{children:"float"}),", and ",(0,l.jsx)(e.code,{children:"integer"}
1)," types."]}),"\n",(0,l.jsxs)(e.li,{children:["The ",(0,l.jsx)(e.code,{children:"regr_intercept"})," function can be used with other statistical aggregation functions like ",(0,l.jsx)(e.code,{children:"regr_slope"})," or ",(0,l.jsx)(e.code,{children:"corr"}),"."]}),"\n",(0,l.jsxs)(e.li,{children:["The order of arguments in ",(0,l.jsx)(e.code,{children:"regr_intercept(y, x)"})," matters.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"Ensure that y is the dependent variable and x is the independent variable."}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"calculation",children:"Calculation"}),"\n",(0,l.jsxs)(e.p,{children:["The y-intercept ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"0"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"b_0"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"0"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]})]})})]})," of the regression line ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]}),(0,l.jsx)(e.mi,{children:"x"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"y = b_0 + b_1 x"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.625em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"0"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})]})]})," is calculated using the formula:"]}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"b_0 = \\bar{y} - b_1 \\bar{x}"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"0"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.7778em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.1944em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1944em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.2222em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]})})})})]})]})]})}),"\n",(0,l.jsx)(e.p,{children:"Where:"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\bar{y}"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.7622em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.1944em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1944em"},children:(0,l.jsx)(e.span,{})})})]})})]})})]})," is the mean of y values"]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\bar{x}"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.5678em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.2222em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]})})})})]})})]})," is the mean of x values"]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"b_1"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]})]})})]})," is the slope calculated by ",(0,l.jsx)(e.code,{children:"regr_slope(y, x)"})]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"arguments",children:"Arguments"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"y: A numeric column representing the dependent variable."}),"\n",(0,l.jsx)(e.li,{children:"x: A numeric column representing the independent variable."}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-2",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsx)(e.p,{children:"The function returns the y-intercept of the regression line, indicating the predicted value of y when x is 0."}),"\n",(0,l.jsx)(e.h3,{id:"examples-1",children:"Examples"}),"\n",(0,l.jsx)(e.h4,{id:"calculate-the-regression-intercept-between-two-variables",children:"Calculate the regression intercept between two variables"}),"\n",(0,l.jsx)(e.p,{children:"Using the same measurements table:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"x"}),(0,l.jsx)(e.th,{children:"y"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"1.0"}),(0,l.jsx)(e.td,{children:"2.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2.0"}),(0,l.jsx)(e.td,{children:"3.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"3.0"}),(0,l.jsx)(e.td,{children:"5.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"4.0"}),(0,l.jsx)(e.td,{children:"4.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"5.0"}),(0,l.jsx)(e.td,{children:"6.0"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Calculate the y-intercept:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT regr_intercept(y, x) AS y_intercept FROM measurements;\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"y_intercept"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"1.4"})})})]}),"\n",(0,l.jsx)(e.p,{children:"Or: When x is 0, y is predicted to be 1.4 units."}),"\n",(0,l.jsx)(e.h4,{id:"calculate-the-regression-intercept-grouped-by-category",children:"Calculate the regression intercept grouped by category"}),"\n",(0,l.jsx)(e.p,{children:"Using the same sales_data table:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"category"}),(0,l.jsx)(e.th,{children:"advertising_spend"}),(0,l.jsx)(e.th,{children:"sales"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"1000"}),(0,l.jsx)(e.td,{children:"15000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"2000"}),(0,l.jsx)(e.td,{children:"22000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"3000"}),(0,l.jsx)(e.td,{children:"28000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"1500"}),(0,l.jsx)(e.td,{children:"18000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"2500"}),(0,l.jsx)(e.td,{children:"26000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"3500"}),(0,l.jsx)(e.td,{children:"31000"})]})]})]}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT category, regr_intercept(sales, advertising_spend) AS base_sales\nFROM sales_data\nGROUP BY category;\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"category"}),(0,l.jsx)(e.th,{children:"base_sales"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"9500"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"12000"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Or:"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"In category A, with no advertising spend, the predicted base sales are 9,500 units"}),"\n",(0,l.jsx)(e.li,{children:"In category B, with no advertising spend, the predicted base sales are 12,000 units"}),"\n"]}),"\n",(0,l.jsx)(e.h4,{id:"handling-null-values",children:"Handling null values"}),"\n",(0,l.jsx)(e.p,{children:"The function ignores rows where either x or y is null:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT regr_intercept(y, x) AS y_intercept\nFROM (\n SELECT 1 AS x, 2 AS y\n UNION ALL SELECT 2, NULL\n UNION ALL SELECT NULL, 4\n UNION ALL SELECT 4, 5\n);\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"y_intercept"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"1.4"})})})]}),"\n",(0,l.jsx)(e.p,{children:"Only the rows where both x and y are not null are considered in the calculation."}),"\n",(0,l.jsx)(e.h2,{id:"regr_r2",children:"regr_r2"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"regr_r2(y, x)"})," - Calculates the coefficient of determination (R-squared) of\nthe linear regression of y on x. R-squared measures how well the regression\nline fits the data, on a scale from 0 (no linear relationship
1) to 1 (perfect\nlinear fit)."]}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:["The function requires at least two valid (y, x) pairs to compute a value.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"If fewer than two pairs are available, the function returns null."}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(e.li,{children:"The function returns null when x is constant across all rows (zero variance\nin the independent variable). This includes the single-row case."}),"\n",(0,l.jsxs)(e.li,{children:["The function returns 1 when y is constant and x varies (a horizontal line\nfits constant y perfectly). This follows the SQL:2003 specification and\ndiffers from ",(0,l.jsx)(e.code,{children:"corr(y, x)"}),", which returns null in that case."]}),"\n",(0,l.jsxs)(e.li,{children:["Supported data types for y and x include ",(0,l.jsx)(e.code,{children:"double"}),", ",(0,l.jsx)(e.code,{children:"float"}),", and ",(0,l.jsx)(e.code,{children:"integer"}),"\ntypes."]}),"\n",(0,l.jsxs)(e.li,{children:["The order of arguments in ",(0,l.jsx)(e.code,{children:"regr_r2(y, x)"})," matters.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"Ensure that y is the dependent variable and x is the independent variable."}),"\n"]}),"\n"]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"regr_r2(y, x)"})," equals ",(0,l.jsx)(e.code,{children:"corr(y, x) * corr(y, x)"})," everywhere except the\nconstant-y edge case noted above."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"calculation-1",children:"Calculation"}),"\n",(0,l.jsxs)(e.p,{children:["The coefficient of determination ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mi,{children:"r"}),(0,l.jsx)(e.mn,{children:"2"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"r^2"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8141em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.02778em"},children:"r"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.8141em"},children:(0,l.jsxs)(e.span,{style:{top:"-3.063em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]})]})})]})," is the squared Pearson correlation:"]}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mi,{children:"r"}),(0,l.jsx)(e.mn,{children:"2"})]}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.mfrac,{children:[(0,l.jsxs)(e.msup,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{fence:"true",children:"("}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"i"})]}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mi,{children:"i"})]}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mo,{fence:"true",children:")"})]}),(0,l.jsx)(e.mn,{children:"2"})]}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"i"})]}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]}),(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mn,{children:"2"})]}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mi,{children:"i"})]}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]}),(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mn,{children:"2"})]})]})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"r^2 = \\frac{\\left(\\sum (x_i - \\bar{x})(y_i - \\bar{y})\\right)^2}{\\sum (x_i - \\bar{x})^2 \\cdot \\sum (y_i - \\bar{y})^2}"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8641em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.02778em"},children:"r"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.8641em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-3.113em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"2.567em",verticalAlign:"-0.936em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mopen nulldelimiter"}),(0,l.jsx)(e.span,{className:"mfrac",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"1.631em"},children:[(0,l.jsxs)(e.span,{style:{top:"-2.314em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3117em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"i"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.2222em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]})})})}),(0,l.jsxs)(e.span,{className:"mclose",children:[(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.7401em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.989em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.311
17em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0359em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"i"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.1944em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1944em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsxs)(e.span,{className:"mclose",children:[(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.7401em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.989em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]})]})]}),(0,l.jsxs)(e.span,{style:{top:"-3.23em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,l.jsxs)(e.span,{style:{top:"-3.677em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord",children:(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsx)(e.span,{className:"mopen delimcenter",style:{top:"0em"},children:"("}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3117em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"i"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"}
1,children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.2222em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]})})})}),(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3117em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0359em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"i"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.1944em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1944em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"mclose delimcenter",style:{top:"0em"},children:")"})]}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.954em"},children:(0,l.jsxs)(e.span,{style:{top:"-3.2029em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.936em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mclose nulldelimiter"})]})]})]})]})}),"\n",(0,l.jsx)(e.p,{children:"Where:"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\bar{y}"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.7622em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"}
1,children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.1944em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1944em"},children:(0,l.jsx)(e.span,{})})})]})})]})})]})," and ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.mover,{accent:"true",children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u02C9"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\bar{x}"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.5678em"}}),(0,l.jsx)(e.span,{className:"mord accent",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.5678em"},children:[(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]}),(0,l.jsxs)(e.span,{style:{top:"-3em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"accent-body",style:{left:"-0.2222em"},children:(0,l.jsx)(e.span,{className:"mord",children:"\u02C9"})})]})]})})})})]})})]})," are the means of y and x across the valid pairs."]}),"\n",(0,l.jsxs)(e.li,{children:["The numerator is the squared sum of cross-deviations ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.msubsup,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"y"})]}),(0,l.jsx)(e.mn,{children:"2"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"S_{xy}^2"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1.1972em",verticalAlign:"-0.3831em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"0.8141em"},children:[(0,l.jsxs)(e.span,{style:{top:"-2.453em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsxs)(e.span,{className:"mord mtight",children:[(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"x"}),(0,l.jsx)(e.span,{className:"mord mathnormal mtight",style:{marginRight:"0.03588em"},children:"y"})]})})]}),(0,l.jsxs)(e.span,{style:{top:"-3.063em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3831em"},children:(0,l.jsx)(e.span,{})})})]})})]})]})})]}),"."]}),"\n",(0,l.jsxs)(e.li,{children:["The denominator is the product of the sums of squared deviations\n",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"x"})]})]}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mi,{children:"y"})]})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"S_{xx} \\cdot S_{yy}"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8333em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1514em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"xx"})})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.9694em",verticalAlign:"-0.2861em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1514em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",style:{marginRight:"0.03588em"},children:"yy"})})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.2861em"},children:(0,l.jsx)(e.span,{})})})]})})]})]})]})]}),"."]}),"\n"]}),"\n",(0,l.jsxs)(e.p,{children:["When ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"x"})]})]}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"S_{xx} = 0"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8333em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1514em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"xx"})})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"0"})]})]})]})," the function returns null; when ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"x"})]})]}),(0,l.jsx)(e.mo,{mathvariant:"normal",children:"\u2260"}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"S_{xx} \\neq 0"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8889em",verticalAlign:"-0.1944em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1514em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",children:"xx"})})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsxs)(e.span,{className:"mrel",children:[(0,l.jsx)(e.span,{className:"mrel",children:(0,l.jsx)(e.span,{className:"mord vbox",children:(0,l.jsx)(e.span,{className:"thinbox",children:(0,l.jsxs)(e.span,{className:"rlap",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8889em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"inner",children:(0,l.jsx)(e.span,{className:"mord",children:(0,l.jsx)(e.span,{className:"mrel",children:"\uE020"})})}),(0,l.jsx)(e.span,{className:"fix"})]})})})}),(0,l.jsx)(e.span,{className:"mrel",children:"="})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"0"})]})]})]})," and\n",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"S"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mi,{children:"y"})]})]}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"S_{yy} = 0"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.9694em",verticalAlign:"-0.2861em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.05764em"},children:"S"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.1514em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"-0.0576em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:(0,l.jsx)(e.span,{className:"mord mathnormal mtight",style:{marginRight:"0.03588em"},children:"yy"})})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.2861em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"0"})]})]})]})," the function returns 1."]}),"\n",(0,l.jsx)(e.h3,{id:"arguments-1",children:"Arguments"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"y: A numeric column representing the dependent variable."}),"\n",(0,l.jsx)(e.li,{children:"x: A numeric column representing the independent variable."}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-3",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsxs)(e.p,{children:["The function returns a value in the range ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{stretchy:"false",children:"["}),(0,l.jsx)(e.mn,{children:"0"}),(0,l.jsx)(e.mo,{separator:"true",children:","}),(0,l.jsx)(e.mn,{children:"1"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"]"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"[0, 1]"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mopen",children:"["}),(0,l.jsx)(e.span,{className:"mord",children:"0"}),(0,l.jsx)(e.span,{className:"mpunct",children:","}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord",children:"1"}),(0,l.jsx)(e.span,{className:"mclose",children:"]"})]})})]}),". A value close to 1\nindicates a strong linear relationship; a value close to 0 indicates that x\nhas little linear predictive power for y."]}),"\n",(0,l.jsx)(e.h3,{id:"examples-2",children:"Examples"}),"\n",(0,l.jsxs)(e.p,{children:["The following examples use the ",(0,l.jsx)(e.code,{children:"market_data_ohlc_1d"})," table on the\n",(0,l.jsx)(e.a,{href:"https://demo.questdb.io/",children:"QuestDB demo instance"}),", which records the daily\n",(0,l.jsx)(e.code,{children:"open"}),", ",(0,l.jsx)(e.code,{children:"high"}),", ",(0,l.jsx)(e.code,{children:"low"}),", and ",(0,l.jsx)(e.code,{children:"close"})," price of each FX pair."]}),"\n",(0,l.jsx)(e.h4,{id:"measure-how-well-the-open-explains-the-close",children:"Measure how well the open explains the close"}),"\n",(0,l.jsxs)(e.p,{children:["Treating the daily ",(0,l.jsx)(e.code,{children:"close"})," as the dependent variable y and the ",(0,l.jsx)(e.code,{children:"open"})," as the\nindependent variable x shows how much of the closing price is explained by where\nthe pair opened:"]}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",metastring:'title="R-squared of close against open for EURUSD" demo',children:"SELECT regr_r2(close, open) AS r2\nFROM market_data_ohlc_1d\nWHERE symbol = 'EURUSD';\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"r2"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"0.7973"})})})]}),"\n",(0,l.jsxs)(e.p,{children:["About 80% of the variation in the EURUSD daily close is explained by a\nstraight-line relationship with the open. Because ",(0,l.jsx)(e.code,{children:"regr_r2(y, x)"})," is the square\nof ",(0,l.jsx)(e.code,{children:"corr(y, x)"}),", the same value is returned by\n",(0,l.jsx)(e.code,{children:"corr(close, open) * corr(close, open)"}),"."]}),"\n",(0,l.jsx)(e.h4,{id:"compare-fit-quality-across-instruments",children:"Compare fit quality across instruments"}),"\n",(0,l.jsxs)(e.p,{children:["Running the same regression per ",(0,l.jsx)(e.code,{children:"symbol"})," turns R-squared into a\ntrending-versus-ranging gauge. Freely floating majors drift from day to day, so\nthe open explains most of the close, while the tightly managed USDHKD peg barely\nmoves and its small daily fluctuations are mostly noise:"]}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",metastring:'title="R-squared of close against open per pair" demo',children:"SELECT symbol, regr_r2(close, open) AS r2\nFROM market_data_ohlc_1d\nWHERE symbol IN ('USDCHF', 'EURUSD', 'GBPUSD', 'EURGBP', 'USDHKD')\nORDER BY r2 DESC;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"symbol"}),(0,l.jsx)(e.th,{children:"r2"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"USDCHF"}),(0,l.jsx)(e.td,{children:"0.8895"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"EURUSD"}),(0,l.jsx)(e.td,{children:"0.7973"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"GBPUSD"}),(0,l.jsx)(e.td,{children:"0.6946"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"EURGBP"}),(0,l.jsx)(e.td,{children:"0.1811"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"USDHKD"}),(0,l.jsx)(e.td,{children:"0.0564"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"The pegged USDHKD scores far lower than the floating pairs, flagging an\ninstrument whose daily close is largely disconnected from its open."}),"\n",(0,l.jsx)(e.h2,{id:"regr_slope",children:"regr_slope"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"regr_slope(y, x)"})," - Calculates the slope of the linear regression line for the\ngiven numeric columns y (dependent variable) and x (independent variable)."]}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:["The function requires at least two valid (x, y) pairs to compute the slope.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"If fewer than two pairs are available, the function returns null."}),"\n"]}),"\n"]}),"\n",(0,l.jsxs)(e.li,{children:["Supported data types for x and y include ",(0,l.jsx)(e.code,{children:"double"}),", ",(0,l.jsx)(e.code,{children:"float"}),", and ",(0,l.jsx)(e.code,{children:"integer"}),"\ntypes."]}),"\n",(0,l.jsxs)(e.li,{children:["The regr_slope function can be used with other statistical aggregation\nfunctions like ",(0,l.jsx)(e.code,{children:"corr"})," or ",(0,l.jsx)(e.code,{children:"covar_samp"}),"."]}),"\n",(0,l.jsxs)(e.li,{children:["The order of arguments in ",(0,l.jsx)(e.code,{children:"regr_slope(y, x)"})," matters.","\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"Ensure that y is the dependent variable and x is the independent variable."}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"calculation-2",children:"Calculation"}),"\n",(0,l.jsxs)(e.p,{children:["The slope ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"b_1"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]})]})})]})," of the regression line ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"0"})]}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]}),(0,l.jsx)(e.mi,{children:"x"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"y = b_0 + b_1 x"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.625em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"0"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})]})]})," is calculated using the\nformula:"]}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.msub,{children:[(0,l.jsx)(e.mi,{children:"b"}),(0,l.jsx)(e.mn,{children:"1"})]}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.mfrac,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"N"}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mi,{children:"y"})]}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mi,{children:"N"}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mn,{children:"2"})]}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mo,{stretchy:"false",children:")"}),(0,l.jsx)(e.mn,{children:"2"})]})]})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"b_1 = \\frac{N \\sum (xy) - \\sum x \\sum y}{N \\sum (x^2) - (\\sum x)^2}"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.8444em",verticalAlign:"-0.15em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"b"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.3011em"}
1,children:(0,l.jsxs)(e.span,{style:{top:"-2.55em",marginLeft:"0em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"1"})})]})}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.15em"},children:(0,l.jsx)(e.span,{})})})]})})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"2.363em",verticalAlign:"-0.936em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mopen nulldelimiter"}),(0,l.jsx)(e.span,{className:"mfrac",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"1.427em"},children:[(0,l.jsxs)(e.span,{style:{top:"-2.314em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.10903em"},children:"N"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.7401em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.989em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]}),(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsxs)(e.span,{className:"mclose",children:[(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.7401em"},children:(0,l.jsxs)(e.span,{style:{top:"-2.989em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]})]})]}),(0,l.jsxs)(e.span,{style:{top:"-3.23em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,l.jsxs)(e.span,{style:{top:"-3.677em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.10903em"},children:"N"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"mclose",children:")"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.936em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mclose nulldelimiter"})]})]})]})]})}),"\n",(0,l.jsx)(e.p,{children:"Where:"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"N"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"N"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6833em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.10903em"},children:"N"})]})})]})," is the number of valid data points."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mi,{children:"y"}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\sum (xy)"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"}),(0,l.jsx)(e.span,{className:"mclose",children:")"})]})})]})," is the sum of the products of ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"x"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"x"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.4306em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})})]})," and ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"y"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"y"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.625em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]})})]}),"."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mi,{children:"x"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\sum x"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})})]})," and ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mi,{children:"y"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\sum y"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]})})]})," is the sums of ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"x"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"x"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.4306em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})})]})," and ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"y"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"y"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.625em",verticalAlign:"-0.1944em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",style:{marginRight:"0.03588em"},children:"y"})]})})]})," values, respectively."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{children:"\u2211"}),(0,l.jsx)(e.mo,{stretchy:"false",children:"("}),(0,l.jsxs)(e.msup,{children:[(0,l.jsx)(e.mi,{children:"x"}),(0,l.jsx)(e.mn,{children:"2"})]}),(0,l.jsx)(e.mo,{stretchy:"false",children:")"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\sum (x^2)"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1.064
11em",verticalAlign:"-0.25em"}}),(0,l.jsx)(e.span,{className:"mop op-symbol small-op",style:{position:"relative",top:"0em"},children:"\u2211"}),(0,l.jsx)(e.span,{className:"mopen",children:"("}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"}),(0,l.jsx)(e.span,{className:"msupsub",children:(0,l.jsx)(e.span,{className:"vlist-t",children:(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.8141em"},children:(0,l.jsxs)(e.span,{style:{top:"-3.063em",marginRight:"0.05em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"2.7em"}}),(0,l.jsx)(e.span,{className:"sizing reset-size6 size3 mtight",children:(0,l.jsx)(e.span,{className:"mord mtight",children:"2"})})]})})})})})]}),(0,l.jsx)(e.span,{className:"mclose",children:")"})]})})]})," is the sum of the squares of ",(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsx)(e.mrow,{children:(0,l.jsx)(e.mi,{children:"x"})}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"x"})]})})}),(0,l.jsx)(e.span,{className:"katex-html","aria-hidden":"true",children:(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.4306em"}}),(0,l.jsx)(e.span,{className:"mord mathnormal",children:"x"})]})})]})," values."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"arguments-2",children:"Arguments"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"y: A numeric column representing the dependent variable."}),"\n",(0,l.jsx)(e.li,{children:"x: A numeric column representing the independent variable."}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-4",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsx)(e.p,{children:"The function returns the slope of the regression line, indicating how much y\nchanges for a unit change in x."}),"\n",(0,l.jsx)(e.h3,{id:"examples-3",children:"Examples"}),"\n",(0,l.jsx)(e.h4,{id:"calculate-the-regression-slope-between-two-variables",children:"Calculate the regression slope between two variables"}),"\n",(0,l.jsx)(e.p,{children:"Suppose you have a table measurements with the following data:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"x"}),(0,l.jsx)(e.th,{children:"y"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"1.0"}),(0,l.jsx)(e.td,{children:"2.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2.0"}),(0,l.jsx)(e.td,{children:"3.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"3.0"}),(0,l.jsx)(e.td,{children:"5.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"4.0"}),(0,l.jsx)(e.td,{children:"4.0"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"5.0"}),(0,l.jsx)(e.td,{children:"6.0"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"You can calculate the slope of the regression line between y and x using:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT regr_slope(y, x) AS slope FROM measurements;\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"slope"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"0.8"})})})]}),"\n",(0,l.jsx)(e.p,{children:"Or: The slope of 0.8 indicates that for each unit increase in x, y increases by\n0.8 units on average."}),"\n",(0,l.jsx)(e.h4,{id:"calculate-the-regression-slope-grouped-by-a-category",children:"Calculate the regression slope grouped by a category"}),"\n",(0,l.jsx)(e.p,{children:"Consider a table sales_data:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"category"}),(0,l.jsx)(e.th,{children:"advertising_spend"}),(0,l.jsx)(e.th,{children:"sales"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"1000"}),(0,l.jsx)(e.td,{children:"15000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"2000"}),(0,l.jsx)(e.td,{children:"22000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"3000"}),(0,l.jsx)(e.td,{children:"28000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"1500"}),(0,l.jsx)(e.td,{children:"18000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"2500"}),(0,l.jsx)(e.td,{children:"26000"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"3500"}),(0,l.jsx)(e.td,{children:"31000"})]})]})]}),"\n",(0,l.jsxs)(e.p,{children:["Calculate the regression slope of ",(0,l.jsx)(e.code,{children:"sales"})," versus ",(0,l.jsx)(e.code,{children:"advertising_spend"})," for each\ncategory:"]}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT category, regr_slope(sales, advertising_spend) AS slope FROM sales_data\nGROUP BY category;\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"category"}),(0,l.jsx)(e.th,{children:"slope"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"A"}),(0,l.jsx)(e.td,{children:"8.5"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"B"}),(0,l.jsx)(e.td,{children:"7.0"})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Or:"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsx)(e.li,{children:"In category A, for every additional unit spent on advertising, sales increase\nby 8.5 units on average."}),"\n",(0,l.jsx)(e.li,{children:"In category B, the increase is 7.0 units per advertising unit spent."}),"\n"]}),"\n",(0,l.jsx)(e.h4,{id:"handling-null-values-1",children:"Handling null values"}
1),"\n",(0,l.jsxs)(e.p,{children:["If your data contains null values, ",(0,l.jsx)(e.code,{children:"regr_slope()"})," will ignore those rows:"]}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb",children:"SELECT regr_slope(y, x) AS slope FROM ( SELECT 1 AS x, 2 AS y UNION ALL SELECT\n2, NULL UNION ALL SELECT NULL, 4 UNION ALL SELECT 4, 5 );\n"})}),"\n",(0,l.jsx)(e.p,{children:"Result:"}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"slope"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"0.8"})})})]}),"\n",(0,l.jsx)(e.p,{children:"Only the rows where both x and y are not null are considered in the calculation."}),"\n",(0,l.jsx)(e.h4,{id:"calculating-beta",children:"Calculating beta"}),"\n",(0,l.jsxs)(e.p,{children:["Assuming you have a table ",(0,l.jsx)(e.code,{children:"stock_returns"})," with daily returns for a specific\nstock and the market index:"]}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.th,{children:"date"}),(0,l.jsx)(e.th,{children:"stock_return"}),(0,l.jsx)(e.th,{children:"market_return"})]})}),(0,l.jsxs)(e.tbody,{children:[(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2023-01-01"}),(0,l.jsx)(e.td,{children:"0.5"}),(0,l.jsx)(e.td,{children:"0.4"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2023-01-02"}),(0,l.jsx)(e.td,{children:"-0.2"}),(0,l.jsx)(e.td,{children:"-0.1"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"2023-01-03"}),(0,l.jsx)(e.td,{children:"0.3"}),(0,l.jsx)(e.td,{children:"0.2"})]}),(0,l.jsxs)(e.tr,{children:[(0,l.jsx)(e.td,{children:"..."}),(0,l.jsx)(e.td,{children:"..."}),(0,l.jsx)(e.td,{children:"..."})]})]})]}),"\n",(0,l.jsx)(e.p,{children:"Calculate the stock's beta coefficient:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT regr_slope(stock_return, market_return) AS beta FROM stock_returns;\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{children:"beta"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{children:"1.2"})})})]}),"\n",(0,l.jsx)(e.p,{children:"Or: A beta of 1.2 suggests the stock is 20% more volatile than the market."}),"\n",(0,l.jsxs)(e.p,{children:["Remember: The order of arguments in ",(0,l.jsx)(e.code,{children:"regr_slope(y, x)"})," matters."]}),"\n",(0,l.jsx)(e.p,{children:"Ensure that y is the dependent variable and x is the independent variable."}),"\n",(0,l.jsx)(e.h2,{id:"spread_bps",children:"spread_bps"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"spread_bps(bid, ask)"})," - calculates the quoted bid-ask spread, based on the\nhighest bidding price, and the lowest asking price."]}),"\n",(0,l.jsx)(e.p,{children:"The result is provided in basis points, and the calculation is:"}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsxs)(e.mfrac,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mtext,{children:"spread"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{fence:"true",children:"("}),(0,l.jsx)(e.mtext,{children:"bid"}),(0,l.jsx)(e.mo,{separator:"true",children:","}),(0,l.jsx)(e.mtext,{children:"ask"}),(0,l.jsx)(e.mo,{fence:"true",children:")"})]})]}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mtext,{children:"mid"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{fence:"true",children:"("}),(0,l.jsx)(e.mtext,{children:"bid"}),(0,l.jsx)(e.mo,{separator:"true",children:","}),(0,l.jsx)(e.mtext,{children:"ask"}),(0,l.jsx)(e.mo,{fence:"true",children:")"})]})]})]}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mn,{children:"10"}),(0,l.jsx)(e.mtext,{children:"\u2009"}),(0,l.jsx)(e.mn,{children:"000"})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\frac\n{\\text{spread}\\left(\\text{bid}, \\text{ask}\\right)}\n{\\text{mid}\\left(\\text{bid}, \\text{ask}\\right)}\n\\cdot\n10\\,000"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"2.363em",verticalAlign:"-0.936em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mopen nulldelimiter"}),(0,l.jsx)(e.span,{className:"mfrac",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"1.427em"}
1,children:[(0,l.jsxs)(e.span,{style:{top:"-2.314em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"mid"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsx)(e.span,{className:"mopen delimcenter",style:{top:"0em"},children:"("}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"bid"})}),(0,l.jsx)(e.span,{className:"mpunct",children:","}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"ask"})}),(0,l.jsx)(e.span,{className:"mclose delimcenter",style:{top:"0em"},children:")"})]})]})]}),(0,l.jsxs)(e.span,{style:{top:"-3.23em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,l.jsxs)(e.span,{style:{top:"-3.677em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"spread"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsx)(e.span,{className:"mopen delimcenter",style:{top:"0em"},children:"("}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"bid"})}),(0,l.jsx)(e.span,{className:"mpunct",children:","}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"ask"})}),(0,l.jsx)(e.span,{className:"mclose delimcenter",style:{top:"0em"},children:")"})]})]})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.936em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mclose nulldelimiter"})]}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6444em"}}),(0,l.jsx)(e.span,{className:"mord",children:"10"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.1667em"}}),(0,l.jsx)(e.span,{className:"mord",children:"000"})]})]})]})}),"\n",(0,l.jsx)(e.h3,{id:"parameters-2",children:"Parameters"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"bid"})," is any numeric bidding price value."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"ask"})," is any numeric asking price value."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-5",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsx)(e.h3,{id:"examples-4",children:"Examples"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT spread_bps(1.5760, 1.5763)\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{style:{textAlign:"left"},children:"spread_bps"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{style:{textAlign:"left"},children:"1.903372140976"})})})]}),"\n",(0,l.jsx)(e.h2,{id:"twap-time-weighted-average-price",children:"TWAP (Time-Weighted Average Price)"}),"\n",(0,l.jsxs)(e.p,{children:["QuestDB provides a native ",(0,l.jsx)(e.code,{children:"twap(price, timestamp)"})," aggregate function that computes the time-weighted average price using step-function integration. Unlike VWAP, TWAP gives equal weight to every time interval, making it the preferred benchmark for illiquid instruments or when volume data is unavailable. It supports ",(0,l.jsx)(e.code,{children:"GROUP BY"}),", ",(0,l.jsx)(e.code,{children:"SAMPLE BY"}),", and ",(0,l.jsx)(e.code,{children:"FILL"})," modes."]}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.a,{href:"/docs/query/functions/aggregation#twap",children:"Function reference"})," \u2014 syntax, parameters, and formula"]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.a,{href:"/docs/cookbook/sql/finance/twap/",children:"Cookbook recipe"})," \u2014 practical examples with TWAP-vs-VWAP comparison"]}),"\n"]}),"\n",(0,l.jsx)(e.h2,{id:"vwap-volume-weighted-average-price",children:"VWAP (Volume-Weighted Average Price)"}),"\n",(0,l.jsx)(e.p,{children:"For VWAP calculations, use window functions with the typical price formula. This approach is more flexible and works well with high-frequency market data."}),"\n",(0,l.jsxs)(e.p,{children:["See the ",(0,l.jsx)(e.a,{href:"/docs/query/functions/window-functions/overview#vwap-volume-weighted-average-price",children:"VWAP example in Window Functions"})," for the recommended implementation using ",(0,l.jsx)(e.code,{children:"SAMPLE BY"})," and ",(0,l.jsx)(e.code,{children:"CUMULATIVE"})," window frames."]}),"\n",(0,l.jsx)(e.h2,{id:"wmid",children:"wmid"}),"\n",(0,l.jsxs)(e.p,{children:[(0,l.jsx)(e.code,{children:"wmid(bidSize, bidPrice, askPrice, askSize)"}
1)," - calculates the weighted mid-price\nfor a sized bid/ask pair."]}),"\n",(0,l.jsx)(e.p,{children:"It is calculated with these formulae:"}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mtext,{children:"imbalance"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsxs)(e.mfrac,{children:[(0,l.jsx)(e.mtext,{children:"bidSize"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{fence:"true",children:"("}),(0,l.jsx)(e.mtext,{children:"bidSize"}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsx)(e.mtext,{children:"askSize"}),(0,l.jsx)(e.mo,{fence:"true",children:")"})]})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\text{imbalance} =\n\\frac\n{ \\text{bidSize} }\n{ \\left( \\text{bidSize} + \\text{askSize} \\right) }"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6944em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"imbalance"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"2.3074em",verticalAlign:"-0.936em"}}),(0,l.jsxs)(e.span,{className:"mord",children:[(0,l.jsx)(e.span,{className:"mopen nulldelimiter"}),(0,l.jsx)(e.span,{className:"mfrac",children:(0,l.jsxs)(e.span,{className:"vlist-t vlist-t2",children:[(0,l.jsxs)(e.span,{className:"vlist-r",children:[(0,l.jsxs)(e.span,{className:"vlist",style:{height:"1.3714em"},children:[(0,l.jsxs)(e.span,{style:{top:"-2.314em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord",children:(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsx)(e.span,{className:"mopen delimcenter",style:{top:"0em"},children:"("}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"bidSize"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"askSize"})}),(0,l.jsx)(e.span,{className:"mclose delimcenter",style:{top:"0em"},children:")"})]})})]}),(0,l.jsxs)(e.span,{style:{top:"-3.23em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,l.jsxs)(e.span,{style:{top:"-3.677em"},children:[(0,l.jsx)(e.span,{className:"pstrut",style:{height:"3em"}}),(0,l.jsx)(e.span,{className:"mord",children:(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"bidSize"})})})]})]}),(0,l.jsx)(e.span,{className:"vlist-s",children:"\u200B"})]}),(0,l.jsx)(e.span,{className:"vlist-r",children:(0,l.jsx)(e.span,{className:"vlist",style:{height:"0.936em"},children:(0,l.jsx)(e.span,{})})})]})}),(0,l.jsx)(e.span,{className:"mclose nulldelimiter"})]})]})]})]})}),"\n",(0,l.jsx)(e.span,{className:"katex-display",children:(0,l.jsxs)(e.span,{className:"katex",children:[(0,l.jsx)(e.span,{className:"katex-mathml",children:(0,l.jsx)(e.math,{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block",children:(0,l.jsxs)(e.semantics,{children:[(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mtext,{children:"wmid"}),(0,l.jsx)(e.mo,{children:"="}),(0,l.jsx)(e.mtext,{children:"askPrice"}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsx)(e.mtext,{children:"imbalance"}),(0,l.jsx)(e.mo,{children:"+"}),(0,l.jsx)(e.mtext,{children:"bidPrice"}),(0,l.jsx)(e.mo,{children:"\u22C5"}),(0,l.jsxs)(e.mrow,{children:[(0,l.jsx)(e.mo,{fence:"true",children:"("}),(0,l.jsx)(e.mn,{children:"1"}),(0,l.jsx)(e.mo,{children:"\u2212"}),(0,l.jsx)(e.mtext,{children:"imbalance"}),(0,l.jsx)(e.mo,{fence:"true",children:")"})]})]}),(0,l.jsx)(e.annotation,{encoding:"application/x-tex",children:"\\text{wmid} = \\text{askPrice} \\cdot \\text{imbalance}\n+ \\text{bidPrice}\n\\cdot \\left( 1 - \\text{imbalance} \\right)"})]})})}),(0,l.jsxs)(e.span,{className:"katex-html","aria-hidden":"true",children:[(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6944em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"wmid"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,l.jsx)(e.span,{className:"mrel",children:"="}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6944em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"askPrice"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.7
1778em",verticalAlign:"-0.0833em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"imbalance"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"+"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"0.6944em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"bidPrice"})}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u22C5"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}})]}),(0,l.jsxs)(e.span,{className:"base",children:[(0,l.jsx)(e.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,l.jsxs)(e.span,{className:"minner",children:[(0,l.jsx)(e.span,{className:"mopen delimcenter",style:{top:"0em"},children:"("}),(0,l.jsx)(e.span,{className:"mord",children:"1"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mbin",children:"\u2212"}),(0,l.jsx)(e.span,{className:"mspace",style:{marginRight:"0.2222em"}}),(0,l.jsx)(e.span,{className:"mord text",children:(0,l.jsx)(e.span,{className:"mord",children:"imbalance"})}),(0,l.jsx)(e.span,{className:"mclose delimcenter",style:{top:"0em"},children:")"})]})]})]})]})}),"\n",(0,l.jsx)(e.h3,{id:"parameters-3",children:"Parameters"}),"\n",(0,l.jsxs)(e.ul,{children:["\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"bidSize"})," is any numeric value representing the size of the bid offer."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"bidPrice"})," is any numeric value representing the bidding price."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"askPrice"})," is any numeric value representing the asking price."]}),"\n",(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.code,{children:"askSize"})," is any numeric value representing the size of the ask offer."]}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"return-value-6",children:"Return value"}),"\n",(0,l.jsxs)(e.p,{children:["Return value type is ",(0,l.jsx)(e.code,{children:"double"}),"."]}),"\n",(0,l.jsx)(e.h3,{id:"examples-5",children:"Examples"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{className:"language-questdb-sql",children:"SELECT wmid(100, 5, 6, 100)\n"})}),"\n",(0,l.jsxs)(e.table,{children:[(0,l.jsx)(e.thead,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.th,{style:{textAlign:"left"},children:"wmid"})})}),(0,l.jsx)(e.tbody,{children:(0,l.jsx)(e.tr,{children:(0,l.jsx)(e.td,{style:{textAlign:"left"},children:"5.5"})})})]})]})}function d(s={}){let{wrapper:e}={...(0,i.a)(),...s.components};return e?(0,l.jsx)(e,{...s,children:(0,l.jsx)(m,{...s})}):m(s)}},50065:function(s,e,a){a.d(e,{Z:()=>t,a:()=>r});var n=a(67294);let l={},i=n.createContext(l);function r(s){let e=n.useContext(i);return n.useMemo(function(){return"function"==typeof s?s(e):{...e,...s}},[e,s])}function t(s){let e;return e=s.disableParentContext?"function"==typeof s.components?s.components(l):s.components||l:r(s.components),n.createElement(i.Provider,{value:e},s.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.