business-science / tidyquant

Bringing financial analysis to the tidyverse
https://business-science.github.io/tidyquant/
Other
852 stars 175 forks source link

geom_candlestick OHLC same value #34

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi, I dont know if this is done intentionally but I have some data where open/high/low/close has the same value.

When I plot with geom_candlestick the plot renders empty.

Somebody told me the standard way to plot this is to have a horizontal dash/line (black)? Just a suggestion.

regards, Lars Nygaard

cpfiffer commented 7 years ago

Could you share which stock you're talking about? Chances are good that no stock was traded on those days, and thus it cannot plot a candlestick because each value is the same.

ghost commented 7 years ago

Its a small Norwegian company. A bank Indre Sogn Sparebank (ISSG) . You probably dont know it.

The data looks like this

A tibble: 14 × 6

symbol date open high low close

1 ISSG 2017-03-03 76.79630 76.79630 76.79630 76.79630 2 ISSG 2017-03-06 77.03704 77.03704 77.03704 77.03704 3 ISSG 2017-03-09 77.03704 77.03704 77.03704 77.03704 4 ISSG 2017-03-10 77.03704 77.03704 77.03704 77.03704 5 ISSG 2017-03-13 77.03704 77.03704 77.03704 77.03704 6 ISSG 2017-03-14 77.03704 77.03704 77.03704 77.03704 7 ISSG 2017-03-20 76.55556 76.55556 76.55556 76.55556 8 ISSG 2017-03-22 77.03704 77.03704 77.03704 77.03704 9 ISSG 2017-03-24 76.55556 76.55556 76.55556 76.55556 10 ISSG 2017-03-27 78.00000 78.00000 77.51852 77.51852 11 ISSG 2017-03-28 77.75926 77.75926 77.51852 77.51852 12 ISSG 2017-03-29 77.51852 77.51852 77.51852 77.51852 13 ISSG 2017-03-30 77.51852 78.96296 77.51852 78.00000 14 ISSG 2017-03-31 77.50000 77.50000 77.25000 77.25000 So for some days ohlc is the same, while for other days there are different values for ohlc. On the days where open/high/low/close has the same value, the plot is blank. 2017-04-12 11:26 GMT+02:00 Cameron Pfiffer : > Could you share which stock you're talking about? Chances are good that no > stock was traded on those days, and thus it cannot plot a candlestick > because each value is the same. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > , > or mute the thread > > . >
cpfiffer commented 7 years ago

The reason your plot is not working is because there are either few securities traded on many of the days. For example, in the first row, each value is the same. This is because the stock's value did not change at any point throughout the day, most likely due to it not being traded. You can verify this by looking at the stock's volume on each day.

This is not really a tidyquant problem, it has more to do with the fact that candlesticks work best for actively traded securities in liquid markets. They're not really best for sporadically traded illiquid assets. Hopefully this has answered your question.

ghost commented 7 years ago

Hi Cameron, Yes, I understand your point. This is probably a problem with my data. I guess if open/high/low/close has the same value, the data point shouldnt be there at all.

Have to ask my data provider why they have registered this data point. Thanks for your comment.

2017-04-12 11:41 GMT+02:00 Cameron Pfiffer notifications@github.com:

The reason your plot is not working is because there are either few securities traded on many of the days. For example, in the first row, each value is the same. This is because the stock's value did not change at any point throughout the day, most likely due to it not being traded. You can verify this by looking at the stock's volume on each day.

This is not really a tidyquant problem, it has more to do with the fact that candlesticks work best for actively traded securities in liquid markets. They're not really best for sporadically traded illiquid assets. Hopefully this has answered your question.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/business-science/tidyquant/issues/34#issuecomment-293526484, or mute the thread https://github.com/notifications/unsubscribe-auth/AXL1ENGUm3m381Cmq37Ro_ZeeWUG72Ufks5rvJxCgaJpZM4M7G6t .

cpfiffer commented 7 years ago

There is no issue with your data provider, and this data is indeed supposed to be present. There are many securities similar to yours that are not actively traded, and their values tend to stay the same throughout. The fact that the values haven't changed is valuable in itself, and many models make use of the fact that securities are unchanged in price and are not traded. The data reflects reality accurately, that this security is not traded.

ghost commented 7 years ago

Yes but it changes from day to day. For example first two rows have different values, so I think they have only registered close prices and filled this out for ohlc.

ghost commented 7 years ago

If I add, volume columns, the data looks like this. So the stock gets traded on those days, but they havent registered ohlc correctly I think.

A tibble: 14 × 6

symbol date open high low close volume

1 ISSG 2017-03-03 76.79630 76.79630 76.79630 76.79630 104 2 ISSG 2017-03-06 77.03704 77.03704 77.03704 77.03704 1981 3 ISSG 2017-03-09 77.03704 77.03704 77.03704 77.03704 68 4 ISSG 2017-03-10 77.03704 77.03704 77.03704 77.03704 228 5 ISSG 2017-03-13 77.03704 77.03704 77.03704 77.03704 254 6 ISSG 2017-03-14 77.03704 77.03704 77.03704 77.03704 5 7 ISSG 2017-03-20 76.55556 76.55556 76.55556 76.55556 475 8 ISSG 2017-03-22 77.03704 77.03704 77.03704 77.03704 171 9 ISSG 2017-03-24 76.55556 76.55556 76.55556 76.55556 571 10 ISSG 2017-03-27 78.00000 78.00000 77.51852 77.51852 223 11 ISSG 2017-03-28 77.75926 77.75926 77.51852 77.51852 260 12 ISSG 2017-03-29 77.51852 77.51852 77.51852 77.51852 130 13 ISSG 2017-03-30 77.51852 78.96296 77.51852 78.00000 358 14 ISSG 2017-03-31 77.50000 77.50000 77.25000 77.25000 600
cpfiffer commented 7 years ago

I believe there is a fundamental misunderstanding here about how these values are recorded.

Take for example the difference between the first and second row on your data set. On the second row, one or more stocks was traded at the open call auction at the beginning of the day, and the open price was changed from the previous close of 76.79630 (on day 1) to the open of 77.03704 (on day 2). Because the security was traded only at the open and at no other point during the day, the open, the high, the low, and the close are all the same price. Not a single security was traded from this day through the sixth row, and a similar event happened on the seventh row, where a security was traded at the open call auction at the beginning of the day.

If you go here and look at the historical pricing and volume, you will notice that very, very small amounts of securities are being traded. Chances are good that these trades are all being performed at the midpoint or limit orders set at the open price, and hence the OHLC data does not change, because the price remains the same throughout the day.

Compare this to a more active stock like Apple, and you will see millions of stocks trade hands during the day, many of which at different prices. ISSG is simply not active enough to display intraday price differentials. Your data is accurate, and the problem has more to due with the nature of small-cap securities like this.

ghost commented 7 years ago

Yes, I understand. The volume is very small indeed so probably no significant change during the days.

ghost commented 7 years ago

but back to my initial suggestion. If you look at the candlestick plot on the link you sent me. You will see a horizontal dash on days where ohlc is the same. https://markets.ft.com/data/equities/tearsheet/charts?s=ISSG:OSL

I dont think this is the case in tidyquant candletick.

ghost commented 7 years ago

Great link by the way. Thanks!

mdancho84 commented 7 years ago

Thanks @Nygdat and @cpfiffer for identifying and working through some of the issues with the OHLC data that has the same values throughout the day. I'll have to see what I can do here. I do think its a case that really is better suited for a geom_line plot if direction is not changing. However, maybe there is something we can do to at least show a small line segment indicating the price. I agree with @cpfiffer that this is technically not a bug, but probably something to look into as a feature enhancement.

ghost commented 7 years ago

thanks @mdancho84 for your reply. I agree with you that this is not a bug.

When open/close are virtually the same, this is called a Doji candlestick. It is a special case. Here you can find the description.

https://www.dailyfx.com/forex/education/trading_tips/post_of_the_day/2012/03/21/Did_You_Know_That_There_are_Five_Different_Types_of_Doji_Candlesticks.html

Looking at some of my plots, Im not sure if this isn't already implemented though..it looks correct.