Distribution Of Returns Indicator

Forums ProRealTime English forum ProBuilder support Distribution Of Returns Indicator

Viewing 15 posts - 1 through 15 (of 20 total)
  • #99021

    After reading this:

    https://www.managedfuturesinvesting.com/analyzing-a-ctas-daily-returns-part-1/

    I decided to try to code a distribution of returns indicator. I post it here in case it of any use to anyone.

    The indicator checks all the candles between the latest one and whatever start date you set (or all candles if you set StartDate to zero) and calculates the rate of return from close to close of each candle. It then counts how many candles fit into each specific range (in buckets of 0.25%) from -5% return to +5% return and displays it as a bar chart.

    The values above the bars represent the (rounded) percentage of candles whose return fell into that specific range.

    The values below the chart indicates rate of return. Each bar represents a 0.25% range of return (so 0.0% to 0.25% then 0.25% to 0.5% and so on). The bars at either end of the chart represent returns greater than 5% and returns lower than -5%.

     

    #99049

    Nice bell curve! well done 🙂

    #99072

    I have a few ideas to add to it like maybe an indication of where current price is on the bell curve. If I manage to find time to develop it a bit further and it looks useful then I will post it to the library.

    1 user thanked author for this post.
    #99088

    I really shouldn’t rush to post stuff! In the process of trying to improve this indicator I spotted a major flaw in the calculation of returns and a mass of typos due to cut and paste. Please ignore the previously posted code and ITF file as it is pants!

    Here is a new and improved (correct I hope) version with not only the corrections but it also draws an arrow to show in which bucket the latest bar on the charts return is on the chart.

     

    4 users thanked author for this post.
    #99105

    wonderful vonasi 😉

    #99144

    The indicator is now in the library and can be found here:

    https://www.prorealcode.com/prorealtime-indicators/distribution-of-returns/

    #99175

    I spotted a typo in the code. There is a minus sign missing on line 274. I have edited the code in my previous post and Nicolas will amend the code and the ITF file in the library but anyone who has already downloaded the ITF file or cut and pasted the code should change line 274 to the following for the indicator to work correctly:

     

    1 user thanked author for this post.
    #99520
    Jan

    Vonassi,

    I can see what you/ the code is doing.  Seems like a Bell curve to me.

    In all your comments I am missing WHY  you developed it, and what it is meant to tell us as users.

     

    Presumably if the curve is very steep and small, the underlying stock/indices/commodity are very stable with their price movements, which you also would expect with obligations.

    When most of its area is on the right side (not sure if this can happen using your code), the stock is in an uptrend.  And vice versa, when most of the area is on the left side, the stock is in a downtrend.

     

    Looking forward for your comments what you can do with it and what the predictive value could be.

    KR Jan

     

    1 user thanked author for this post.
    #99529

    The indicator simply shows how balanced a market is. The shape of the curve tells us this and more. Remember that the curve is created by checking close to close price movements. If the bars near the centre are all tall and the rest of the curve is flat then we can see that prices (close to close) don’t move very far from where they started. If however the curve is more triangular shaped then we can see that the market has a different characteristic and price closes over a larger range. Each bar tells us the probability of price closing so far from where it started.

    The indicator is not really about trend as it needs a lot of candles to be analysed to get a curve so it is seriously lagging. If a curve is lop sided in shape then the we can see that maybe our downside risk is very different to our upside risk. If there are only one or two tall bars on the right of centre then we know that the probability of price closing at a distance of three or four bars away is seriously reduced and if there are lots of tall bars on the left of the centre line then we know that our downside risk is greater and deeper.

    I have now created a version where you can vary the bar size. Having bucket sizes fixed at 0 to 0.25% then 0.25% to 0.50% is not ideal for all instruments. I have also created an automatic bar size calculator that the indicator can call so that it works out the best bucket size for any instrument that you use it on.

    I have also been working on a similar indicator which I call ‘Distribution of Range’. On this indicator the right side of the curve shows distribution of high minus open and the left side open minus close. The number of bars has been increased to 82 and it also works with the automatic bar size indicator as well as manually sized bars.

    Hopefully I will finish these indicators and post them to the library later this week.

    1 user thanked author for this post.
    #111404

    Great coding!

     

    Did you find time and energy to finalise the adaptable indicator? One of my first thoughts would be to make bucket distribution automatic based on highest and lowest return values and a given number of buckets (which could be set in a variable).

    /F

    #111411

    I spent a lot of time on it and I did create something that was automatic but unfortunately any out of the ordinary candles created massive distortions in the bucket sizes calculated meaning that the output was not really of much use as the majority of results ended up being in just two bars – so I kind of gave up on the concept.

    I’ve attached the ITF file for as far as I got.

    If you set BarSize to zero then it automatically calculates the bar size (bucket size). I have added a variable called ‘factor’ which helps spread the bell curve out by dividing the automatically calculated bar size by its value. This helps to improve the curve and stops all the results being just in the middle two bars! It is a bit of a fudged work around which is the main reason why I did not post the indicator in the library.

    There is also the issue that the bar size calculation is always changing as time goes on and it is difficult to know exactly how much this effects the final results.

    There are three arrows – the blue one is where price is right now on the bell curve and the red and green are the extremes of where it has been for the current candle.

    At the bottom of the chart it shows the size in % of each bar and also what the extreme bars represent.

    Sorry if the code is a bit of a mess but it is an abandoned project for all the many reasons mentioned!

    #111438

    Thanks! Very interesting. I don’t feel I have time to dig deeper at the moment. If I had, I would of course have shared my findings. But thanks again for contributing creatively to spur my own creativity!

    /F

     

    #111755

    A great idea for an indicator Vonasi, as the distribution of returns shows the inherent bias/skew and volatility for any market. I was reading this very interesting quant traders ideas about Returns Distribution and Cumulative Probability here:

    https://www.quanttrader.com/index.php/money-for-nothing/KahlerPhilipp2018

    https://www.quanttrader.com/index.php/tradesignal-returns-distribution-indikator

    How hard would it be to convert Kahler’s code from the second link supplied above? I think it would be a great addition to the library and maybe it could solve some of the issues you’ve encountered?

    To save having translate his post from German:

    The Returns Distribution indicator makes it possible to show the distribution of the returns of a time series. The presentation and calculation of the returns is done in percent.

    If the input “returnperiod” is set to 0, the absolute price distribution is displayed.

    The smoothing of the curve can be determined via the Input Smooth.

    In addition to the distribution of the returns, the sum of the probabilities can also be displayed. This can be used to determine what percentage of events are above or below a certain value.

     

    #112309

    Hi @Vonasi, I’m unsure of the rules about double posting. Should I add my entire last post above to: https://www.prorealcode.com/free-code-conversion/

    or https://www.prorealcode.com/forum/prorealtime-english-forum/probuilder-support/

    and what is the real difference between these two links and how do you know when to post to one or the other? Thanks.

    #112336

    Everything is possible  – but sometimes an awful lot of hard work. I have seen those posts that you provided links to before and have actually already started coding something similar. Unfortunately that original indicator code uses arrays and PRT does not have arrays so to create a DOR line requires a separate piece of code just to allocate each result to the correct variable (or bucket) rather than just a couple of loops. Then we have to do this again to get the other two DOR lines. I have also found deciding on the size of each bucket is impossible at the start of an indicator run unless a loop is used to check all of history in reverse first then you have to do the whole lot of distributions counting in reverse with a massive loop which either fails or is painfully slow. Starting at the beginning of history is easier and faster but then you have no idea what bucket size to use. I did overcome this with a separate indicator that calculates bucket size but then you have to manually enter it for the three DOR lines which is not ideal. Calculating a smoothed average of all the individual variable results is also not a lot of fun unless one likes repetitive typing! After all that I then need to workout all the correct locations in an indicator window to draw all the segments from one variable result to the next. The biggest DOR chart I have created so far is just 80 bars and that was a mammoth task.

    I have shelved the project at the moment but might resurrect it if I thought that I could sell it! 🙂

Viewing 15 posts - 1 through 15 (of 20 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login