amatttei
Posts: 3
Joined: Tue Apr 18, 2023 9:27 am

YTD return (compared to 12/31/yyyy)

Hello, I would like to calculate the YTD return (compared to 12/31/yyyy). How can I do?

Currently I have been using this code(https://jsfiddle.net/amatttei/d5zxkba4/5/); unfortunately it calculates the yield against November (and not against December).

Thanks very much for the assistance!
jedrzej.r
Posts: 725
Joined: Tue Jan 24, 2023 11:21 am

Re: YTD return (compared to 12/31/yyyy)

Hi!

Welcome to our forum and thanks for reaching out to us with your question!

YTD (year-to-date) returns a range from 01.01.YYYY to current date, where YYYY is current year. The reason it doesn't work as intended is because of minRange default setting:
The default minRange for the x axis is five times the smallest interval between any of the data points.

In order to enable smaller range selection, you should set minRange to a fixed number, for example one week. Secondly, you can override selected button function by setting extremes on both xAxis with desired values.

Live demo: https://jsfiddle.net/BlackLabel/6u8hbk2v/

API:
https://api.highcharts.com/highcharts/xAxis.minRange
https://api.highcharts.com/highstock/ra ... ents.click
https://api.highcharts.com/class-refere ... etExtremes

Let me know if that was what you were looking for.
Best regards!
Jędrzej Ruta
Highcharts Developer
amatttei
Posts: 3
Joined: Tue Apr 18, 2023 9:27 am

Re: YTD return (compared to 12/31/yyyy)

Thanks a lot for the answer.
My goal was to build a graph where, by pressing the YTD button, I would get the YTD NAV rate of return.

Let me explain: as can be seen from the image, currently pressing the YTD button, I get the values ​​shown in the fourth column (highlighted in yellow).
However, these values ​​are incorrect, as they do not represent year-to-date performance.

How can I get the correct values ​​reported in column 5 "YTD (desired)", highlighted in green, which are the correct ones?

[img]
NAV.png
NAV.png (21.5 KiB) Viewed 418 times
[img]

Is it possible to set buttons also for QTD, MTD returns? How?

Thanks in advance
jedrzej.r
Posts: 725
Joined: Tue Jan 24, 2023 11:21 am

Re: YTD return (compared to 12/31/yyyy)

Hi!

If you take a closer look at deafult YTD button behaviour, you'll notice that it does exactly what you mentioned, as it takes the value from the last day of 2022 as the base value for year-to-date range and calculates the difference. Same goes to other ranges selected, as their purpose is to show difference between visible points. In order to create a button for custom data range, it would require a bit of code customization.

Live demo: https://jsfiddle.net/BlackLabel/L8147f5g/

Let me know if this explanation suits your needs!
Best regards!
Jędrzej Ruta
Highcharts Developer

Return to “Highcharts Stock”