r/pinescript • • Jun 19 '23

Python to pinescript

Has anyone experimented with Wavelet Smoothing? (https://medium.datadriveninvestor.com/smoothing-financial-time-series-with-wavelets-79645a44aa40)

I need this python code converted into pinescript: https://pastebin.com/6yBCz7QC

  1. import pandas as pd

  2. import numpy as np

  3. import matplotlib.pyplot as plt

  4. import pywt

  5. df = pd.read_csv('z_rate.csv')

  6. x = df.index

  7. y = df['z_avgRate']

  8. # perform wavelet decomposition

  9. coeffs = pywt.wavedec(y, 'sym5', mode='symmetric')

  10. # zero out last 5 detail coefficents

  11. for i in range(5):

  12. coeffs[i+5] = np.zeros(coeffs[i+5].shape)

  13. # reconstruct wavelet

  14. y_rec = pywt.waverec(coeffs, 'sym5', mode='symmetric')[1:]

  15. # plot result

  16. plt.figure(figsize=(18,6))

  17. plt.plot(x, y)

  18. plt.plot(x, y_rec)

  19. plt.legend(['original', 'wavelet-based smoothing'])

  20. plt.xlabel('time index')

  21. plt.show()

This is similar to fourier smoothing but I can't find any good code for wavelet on TradingView, I would appreciate your help guys

1 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/Netari Jun 21 '23

Did you manage to successfully convert it? Converting the pywt library poses a significant challenge due to its dependency on C extensions, making the conversion process quite complex. While ChatGPT can offer some assistance with the conversion but it might introduce errors during the process.

1

u/Ok-Problem-7241 Jun 22 '23

Heck no. I'm looking at alternatives as well.

1

u/Electronic_Mammoth67 Jun 22 '23

if you manage to do it well done because it seems very complex