-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified tests and added annualized return calculation
- Loading branch information
1 parent
00e5eb7
commit b427d9d
Showing
9 changed files
with
76 additions
and
200 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,7 @@ | ||
class frequency: | ||
second = 0 | ||
minutely = 1 | ||
hourly = 2 | ||
weekly = 3 | ||
monthly = 4 | ||
quarterly = 5 | ||
yearly = 6 | ||
class Frequency: | ||
def __init__(self, scale=None, label=None): | ||
self.label = label | ||
self.scale = scale | ||
|
||
def to_str(self, d): | ||
if d is frequency.second: | ||
name = "S" | ||
if d is frequency.minutely: | ||
name = "T" | ||
if d is frequency.hourly: | ||
name = "H" | ||
if d is frequency.weekly: | ||
name = "W" | ||
if d is frequency.monthly: | ||
name = "M" | ||
if d is frequency.quarterly: | ||
name = "Q" | ||
if d is frequency.yearly: | ||
name = "A" | ||
return name | ||
def __str__(self): | ||
return self.label |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import numpy as np | ||
from frequency import Frequency | ||
|
||
|
||
def periodicity(df): | ||
""" | ||
Frequencies higher than daily will not be available | ||
""" | ||
med = np.median(np.diff(df.index.values)) | ||
seconds = int(med.astype('timedelta64[s]').item().total_seconds()) | ||
freq = Frequency() | ||
if seconds < 60: | ||
freq.label = "S" | ||
freq.scale = None | ||
elif seconds < 3600: | ||
freq.label = "T" | ||
freq.scale = None | ||
elif seconds < 86400: | ||
freq.label = "H" | ||
freq.scale = None | ||
elif seconds == 86400: | ||
freq.label = "D" | ||
freq.scale = 252 | ||
elif seconds <= 604800: | ||
freq.label = "W" | ||
freq.scale = 52 | ||
elif seconds <= 2678400: | ||
freq.label = "M" | ||
freq.scale = 12 | ||
elif seconds <= 7948800: | ||
freq.label = "Q" | ||
freq.scale = 4 | ||
else: # anything lower than year is deemed as yearly | ||
freq.label = "A" | ||
freq.scale = 1 | ||
return freq |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
import sys | ||
|
||
|
||
sys.path.append(os.path.dirname(__file__)) |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
from PerformanceAnalytics import ratios | ||
import pandas as pd | ||
|
||
|
||
class TestRatios: | ||
def test_kelly_ratio(self): | ||
edhec = pd.read_csv("edhec.csv", parse_dates=[0]) | ||
edhec.index = edhec.ix[:, 0] | ||
edhec = edhec.ix[:, 1:] | ||
print ratios.returns(edhec.ix[:,0]) | ||
pass |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pandas as pd | ||
from PerformanceAnalytics import utils | ||
|
||
|
||
def test_utils(): | ||
dates = pd.date_range('1/1/2010', periods=12, freq="M") | ||
df = pd.DataFrame([0 for i in range(12)], index=dates) | ||
freq = utils.periodicity(df) | ||
assert freq.scale == 12 | ||
assert freq.label == "M" |
This file was deleted.
Oops, something went wrong.