Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import pandas as pd
  2.  
  3.  
  4. class BB():
  5.  
  6. def __init__(self, df):
  7. self.data = df
  8. self.periods = 30
  9. self.length = 30
  10. self.mult = 2.0
  11. self.calculate_bollinger_width()
  12.  
  13. def calculate_bollinger_width(self):
  14. df = self.data
  15.  
  16. MA = pd.Series(df['close'].rolling(window=self.periods).mean())
  17. MSD = pd.Series(df['close'].rolling(
  18. window=self.periods).std() * self.mult)
  19.  
  20. BB_UPPER = pd.Series(MA + MSD)
  21. BB_LOWER = pd.Series(MA - MSD)
  22.  
  23. BB_WIDTH = pd.Series(((BB_UPPER - BB_LOWER) / MA)
  24. * 100, name='BB_WIDTH')
  25.  
  26. df = df.join(BB_WIDTH)
  27. self.data = df
  28.  
  29. def get_bollinger_width(self):
  30. return self.data
Add Comment
Please, Sign In to add comment