Skip to content

Commit

Permalink
ENH: Remove duplicate rolling hist vol function
Browse files Browse the repository at this point in the history
  • Loading branch information
David Stephens committed Sep 29, 2019
1 parent 9a0cdf2 commit bcea2c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions pandas_finance/api.py
Expand Up @@ -102,11 +102,12 @@ def hist_vol(self, days, end_date=None):
return data.std() * math.sqrt(TRADING_DAYS)

def rolling_hist_vol(self, days, end_date=None):
days = int(days)
if end_date:
data = self.returns[:end_date]
else:
data = self.returns
return pd.rolling_std(data, window=days) * math.sqrt(TRADING_DAYS)
return data.rolling(days).std() * math.sqrt(TRADING_DAYS)

@property
def profile(self):
Expand Down Expand Up @@ -178,10 +179,6 @@ def vwap(self, end_date=None, days=30):
data = data.iloc[-days:]
return (data['Close'] * data['Volume']).sum() / data['Volume'].sum()

def hist_vol_over_time(self, days=20):
days = int(days)
return self.returns.rolling(days).std()*math.sqrt(TRADING_DAYS)

def hist_vol_by_days(self, end_date=None, min_days=10, max_days=600):
"Returns the historical vol for a range of trading days ending on end_date."
min_days = int(min_days)
Expand Down
6 changes: 3 additions & 3 deletions pandas_finance/tests/test_api.py
Expand Up @@ -67,9 +67,9 @@ def test_closed(self):
def test_currency(self):
self.assertEqual(self.aapl.currency, 'USD')

def test_hist_vol_over_time(self):
self.assertIsInstance(self.aapl.hist_vol_over_time(), pd.Series)
self.assertAlmostEqual(self.aapl.hist_vol_over_time(20)[self.date], 0.562, 3)
def test_rolling_hist_vol(self):
self.assertIsInstance(self.aapl.rolling_hist_vol(20), pd.Series)
self.assertAlmostEqual(self.aapl.rolling_hist_vol(20)[self.date], 0.562, 3)

def test_hist_vol_by_days(self):
self.assertIsInstance(self.aapl.hist_vol_by_days(), pd.Series)
Expand Down

0 comments on commit bcea2c9

Please sign in to comment.