Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: #568

Closed
amitgupta16033 opened this issue Nov 1, 2022 · 11 comments · Fixed by #575
Closed

Bug Report: #568

amitgupta16033 opened this issue Nov 1, 2022 · 11 comments · Fixed by #575
Labels
bug Something isn't working released code merged into repo AND released to Pypi

Comments

@amitgupta16033
Copy link

amitgupta16033 commented Nov 1, 2022

Hi,

The calculation of 'pnf_counts' is incorrect. Hence, leading to incorrect plotting. I am attaching the out of mplfinance as well the correct chart from 'Stockcharts.com'. Following parameters were used -

Box Size = 180
Reversal =3

Code excerpts -

data1 = data.loc[:, ['Date', 'Open', 'High', 'Low', 'Close', 'Volume']]
datanew = data1.set_index(['Date']).astype(float)
pnf_kwargs = dict(type='pnf', volume=True, figratio=(1, 1), figscale=5)
cv = {} # blank dict to hold return_calculated_values values
close_last_value = int(data1['Close'].iloc[-1])
pnf_box_size = round(close_last_value * 0.01)
print("Box_Size is - " + str(pnf_box_size))
pnf_reversal = 3
print("Reversal is - " + str(pnf_reversal))
mf.plot(datanew, **pnf_kwargs, style='starsandstripes', pnf_params=dict(box_size=pnf_box_size, reversal=pnf_reversal),
return_calculated_values=cv)
col_value = cv.get('pnf_counts')
print(col_value)

Could you please provide us a solution? I am also attaching images and for your reference.
https://drive.google.com/file/d/1vpa8e7mI3GGpQTnQdJE5YpLWyNWHh8Pu/view?usp=share_link
https://drive.google.com/file/d/1_ZpgnahDxZGLQpVIH2kNML_zBxLN_VqH/view?usp=share_link
https://docs.google.com/spreadsheets/d/16SpG7Waq19as98-5CnME9EyefPzdGoRG/edit?usp=share_link&ouid=115874185577837631247&rtpof=true&sd=true

@amitgupta16033 amitgupta16033 added the bug Something isn't working label Nov 1, 2022
@DanielGoldfarb
Copy link
Collaborator

Please provide all of your input data that you passed into mpf.plot(). Thank you.

@amitgupta16033
Copy link
Author

Hi Daniel, please find below all the parameters I used within mpf.plot(). I imported mplfinance as mf

mf.plot(datanew, **pnf_kwargs, style='starsandstripes', pnf_params=dict(box_size=pnf_box_size, reversal=pnf_reversal), return_calculated_values=cv)

I defined pnf_box_size as 1% of last close price
reversal was set to 3.

I have not modified or added anything else. Thank you !

@DanielGoldfarb
Copy link
Collaborator

Amit,
Thanks. I will try to reproduce in the next day or so and let you know what I find. --Daniel

@DanielGoldfarb
Copy link
Collaborator

This line of code:

datanew = data1.set_index(['Date']).astype(float)

makes no sense. mplfinance will fail because the index is not a datetime index.

@DanielGoldfarb
Copy link
Collaborator

I am able to reproduce the chart you have posted here and the chart closely matches a chart that I can see on another system.

However the other image you have posted here does not make sense to me given the data you have posted. Notice on this chart that it starts and ends in the month of October (where as the data is year-to-date: Jan 2022 to Oct 2022). If I ignore the first few months, the chart more closely resembles the mplfinance pnf chart, however not quite, possibly because the results depend in part on when the data starts. What evidence do you have that this chart is using the same data (it seems that it may not be).

I did not personally write the code that calculates PNF for mplfinance, however I did test it agains some other systems at the time it was written and it did match. I don't much time to look into this now, however you are welcome to review the code here and see if you think it is correct. That said, you have not yet convinced me that this is not just a case of different input data to the different PNF charts. Let me know how you want to continue. I will help out in any way that I can to the extent that I have time.

@DanielGoldfarb
Copy link
Collaborator

@amitgupta16033
Amit, I got a chance to take a closer look at this, and indeed I am convinced that mplfinance point-and-figure calculations are definitely wrong (at lease in some cases). I am however not convinced that stockcharts.com is correct, or at least the image and data that you posted supposedly from stockcharts.com do not match each other.

I have re-written the mplfinance point-and-figure algorithm, and I am putting on the finishing touches and rewriting the regression tests, and hope to enter a PR for the corrected algorithm sometime in the next few days.

I cannot compare the stockcharts.com results to mplfinance, but I have confirmed (for at least a dozen cases) that the corrected mplfinance algorithm matches the point and figure results on both Schwab and Bloomberg. Again, I hope to have the code updated in this repository in a few more days. Sorry for any inconvenience.

@amit7702
Copy link

Hi Daniel,

Once again thank you for your response. I appreciate that you have invested time and effort in updating the logic. Honestly, I do not know much about python but I can help you with the Point and Figure logic (based on High/low/Close price). I can even help you with percentage/fixed box sizes for point and figure. Please let me know if I can help you with these ideas.

I am eagerly waiting to work on the new update logic. Thanks again for working on this request.

@DanielGoldfarb
Copy link
Collaborator

Amit,

Thanks. If you specify the box size as a percentage, do you want to see a box size as a percent of (a) the most recent close price, (b) the average close price of the entire data set, or (c) something else?

If seems to me, just glancing around, that most systems use the percent of the most recent close price. Is that what you expect?

@amit7702
Copy link

Yes Daniel, box size as a percent of the most recent close price. This is the most preferred approach.

DanielGoldfarb added a commit that referenced this issue Dec 8, 2022
Rewrite (fix/correct) Point and Figure algorithm for #568
@DanielGoldfarb DanielGoldfarb added released code merged into repo AND released to Pypi and removed in progress labels Dec 8, 2022
@DanielGoldfarb
Copy link
Collaborator

@amit7702
Amit,
Please upgrade and test the latest version of mplfinance: pip install --upgrade mplfinance.

This should behave much better. One thing I did discover is that no two systems match each other exactly (because there are so many nuances as to how to run the algorith), however for a given chunk of time (say 6 months) and identical box sizes and reversal sizes, most of the chart should match relatively closely. The main differences between systems tend to be at the beginning of the chart, because that is where there appears to be the most variation in algorithms in terms of how to "kick start" the chart.

Please let me know how the new mplfinance type='pnf' works for you. Thanks. --Daniel

@amitgupta16033
Copy link
Author

@DanielGoldfarb

Thank you for fixing this. The plots are perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released code merged into repo AND released to Pypi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants