에디터즈 픽
OPEN-SOURCE SCRIPT

Probability Distribution Histogram

업데이트됨
Probability Distribution Histogram

During data exploration it is often useful to plot the distribution of the data one is exploring. This indicator plots the distribution of data between different bins.

Essentially, what we do is we look at the min and max of the entire data set to determine its range. When we have the range of the data, we decide how many bins we want to divide this range into, so that the more bins we get, the smaller the range (a.k.a. width) for each bin becomes. We then place each data point in its corresponding bin, to see how many of the data points end up in each bin. For instance, if we have a data set where the smallest number is 5 and the biggest number is 105, we get a range of 100. If we then decide on 20 bins, each bin will have a width of 5. So the left-most bin would therefore correspond to values between 5 and 10, and the bin to the right would correspond to values between 10 and 15, and so on.

Once we have distributed all the data points into their corresponding bins, we compare the count in each bin to the total number of data points, to get a percentage of the total for each bin. So if we have 100 data points, and the left-most bin has 2 data points in it, that would equal 2%. This is also known as probability mass (or well, an approximation of it at least, since we're dealing with a bin, and not an exact number).



Usage

This is not an indicator that will give you any trading signals. This indicator is made to help you examine data. It can take any input you give it and plot how that data is distributed.

The indicator can transform the data in a few ways to help you get the most out of your data exploration. For instance, it is usually more accurate to use logarithmic data than raw data, so there is an option to transform the data using the natural logarithmic function. There is also an option to transform the data into %-Change form or by using data differencing.

Another option that the indicator has is the ability to trim data from the data set before plotting the distribution. This can help if you know there are outliers that are made up of corrupted data or data that is not relevant to your research.

I also included the option to plot the normal distribution as well, for comparison. This can be useful when the data is made up of residuals from a prediction model, to see if the residuals seem to be normally distributed or not.
릴리즈 노트
Version 1.0.1
  • Fixed minor spelling errors in the tooltip about the "data transformation method" option.
  • Fixed a bug with the trimming of the data.
릴리즈 노트
No code changes. Corrected the chart image used for the publication.
릴리즈 노트
Version 1.0.3
  • Added the first 4 moments to the TradingView Data Window.
릴리즈 노트
Version 1.1.0
  • Updated code to PineScript version 5.
  • Added support for comparing to a uniform distribution and a Laplace distribution.
  • Fixed a few bugs.
  • Added min and max of the data set to the TradingView Data window.

릴리즈 노트
Version 1.1.1
  • Added the option to show which bin the current data point belongs to.
릴리즈 노트
Version 1.1.2
  • Made the highlighted bin highlight the entire column instead of just the empirical distribution.
릴리즈 노트
Version 1.1.3
  • Added absolute and squared transformations to the data transformation dropdown list.
  • Removed the log checkbox and added options for that in the dropdown list for data transformation.
  • Fixed a bug with the highlighted bin where it wouldn't properly disapear when the checkbox was unticked.
릴리즈 노트
Version 1.1.4
  • Changed from calculating only centralized sample moments to ("unbiased") centralized sample variance and standardized sample skewness and kurtosis.
  • Kurtosis is now showing "excess" kurtosis.

릴리즈 노트
Version 1.1.5
  • Fixed a bug that made the indicator crash when the first few data points were 'na'.
  • Made the default transformation "log %-change" again. Accidentally made it "%-change" in the 1.1.3 update.

릴리즈 노트
Version 1.1.6
  • Added exponent of raw data to the data transformation dropdown list.

Version 1.1.7
  • Added the option to use a lookback period for the histogram data source.
릴리즈 노트
Version 1.1.8
  • Added the option to set a date/time range for the data set.
  • Added the option to set a custom bin size.
릴리즈 노트
Version 1.1.9
  • Added the median and mean absolute deviation (the average absolute distance between the median and the data points) to the TradingView Data window.
  • Added the 1st quartile, 3rd quartile and interquartile range to the TradingView Data window.
  • Added the 5th quantile and 95th quantile for both the empirical and the theoretical distribution to the TradingView Data window.
cdfdensityhistogrammassnormaldistributionPDFprobabilityStandard DeviationVolatility

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항