Created
June 16, 2018 14:22
-
-
Save dgnsrekt/15ce4989ff8de9641b77d5b78f6573f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
class BB(): | |
def __init__(self, df): | |
self.data = df | |
self.periods = 30 | |
self.length = 30 | |
self.mult = 2.0 | |
self.calculate_bollinger_width() | |
def calculate_bollinger_width(self): | |
df = self.data | |
MA = pd.Series(df['close'].rolling(window=self.periods).mean()) | |
MSD = pd.Series(df['close'].rolling( | |
window=self.periods).std() * self.mult) | |
BB_UPPER = pd.Series(MA + MSD) | |
BB_LOWER = pd.Series(MA - MSD) | |
BB_WIDTH = pd.Series(((BB_UPPER - BB_LOWER) / MA) | |
* 100, name='BB_WIDTH') | |
df = df.join(BB_WIDTH) | |
self.data = df | |
def get_bollinger_width(self): | |
return self.data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment