renamed module to PyFacts

This commit is contained in:
Gourav Kumar 2022-06-05 23:06:12 +05:30
parent c605f71f10
commit 0bf1deac48
12 changed files with 44 additions and 44 deletions

View File

@ -1,4 +1,4 @@
from .core import *
from .fincal import *
from .pyfacts import *
from .statistics import *
from .utils import *

View File

@ -20,7 +20,7 @@ from typing import (
from dateutil.relativedelta import relativedelta
from .utils import FincalOptions, _parse_date, _preprocess_timeseries
from .utils import PyfactsOptions, _parse_date, _preprocess_timeseries
@dataclass(frozen=True)
@ -908,7 +908,7 @@ class TimeSeriesCore:
"""
if closest is None:
closest = FincalOptions.get_closest
closest = PyfactsOptions.get_closest
time_delta_dict = {"exact": 0, "previous": -1, "next": 1}
@ -983,7 +983,7 @@ class TimeSeriesCore:
return self.data
if string_date_format == "default":
string_date_format = FincalOptions.date_format
string_date_format = PyfactsOptions.date_format
data = {datetime.datetime.strftime(dt, string_date_format): val for dt, val in self.data.items()}
return data
@ -1006,7 +1006,7 @@ class TimeSeriesCore:
return list(self.data.items())
if string_date_format == "default":
string_date_format = FincalOptions.date_format
string_date_format = PyfactsOptions.date_format
data = [(datetime.datetime.strftime(dt, string_date_format), val) for dt, val in self.data.items()]
return data

View File

@ -11,7 +11,7 @@ from dateutil.relativedelta import relativedelta
from .core import AllFrequencies, Frequency, Series, TimeSeriesCore, date_parser
from .utils import (
FincalOptions,
PyfactsOptions,
_find_closest_date,
_interval_to_years,
_is_eomonth,
@ -540,7 +540,7 @@ class TimeSeries(TimeSeriesCore):
sd = statistics.stdev(rolling_returns.values)
if annualize_volatility:
if traded_days is None:
traded_days = FincalOptions.traded_days
traded_days = PyfactsOptions.traded_days
if return_period_unit == "months":
sd *= math.sqrt(12 / return_period_value)

View File

@ -2,9 +2,9 @@ import datetime
import statistics
from typing import Literal
from fincal.core import date_parser
from pyfacts.core import date_parser
from .fincal import TimeSeries
from .pyfacts import TimeSeries
from .utils import _interval_to_years

View File

@ -8,7 +8,7 @@ from .exceptions import DateNotFoundError, DateOutOfRangeError
@dataclass
class FincalOptions:
class PyfactsOptions:
date_format: str = "%Y-%m-%d"
closest: str = "previous" # next
traded_days: int = 365
@ -42,7 +42,7 @@ def _parse_date(date: str, date_format: str = None) -> datetime.datetime:
return datetime.datetime.fromordinal(date.toordinal())
if date_format is None:
date_format = FincalOptions.date_format
date_format = PyfactsOptions.date_format
try:
date = datetime.datetime.strptime(date, date_format)

View File

@ -3,8 +3,8 @@ from setuptools import find_packages, setup
license = open("LICENSE").read().strip()
setup(
name="Fincal",
version='0.0.1',
name="PyFacts",
version="0.0.1",
license=license,
author="Gourav Kumar",
author_email="gouravkr@outlook.in",

View File

@ -3,7 +3,7 @@ import math
import random
from typing import List
import fincal as fc
import pyfacts as pft
import pytest
from dateutil.relativedelta import relativedelta
@ -55,7 +55,7 @@ def create_prices(s0: float, mu: float, sigma: float, num_prices: int) -> list:
def sample_data_generator(
frequency: fc.Frequency,
frequency: pft.Frequency,
start_date: datetime.date = datetime.date(2017, 1, 1),
num: int = 1000,
skip_weekends: bool = False,
@ -90,11 +90,11 @@ def sample_data_generator(
timedelta_dict = {
frequency.freq_type: int(
frequency.value * num * (7 / 5 if frequency == fc.AllFrequencies.D and skip_weekends else 1)
frequency.value * num * (7 / 5 if frequency == pft.AllFrequencies.D and skip_weekends else 1)
)
}
end_date = start_date + relativedelta(**timedelta_dict)
dates = fc.create_date_series(start_date, end_date, frequency.symbol, skip_weekends=skip_weekends, eomonth=eomonth)
dates = pft.create_date_series(start_date, end_date, frequency.symbol, skip_weekends=skip_weekends, eomonth=eomonth)
values = create_prices(1000, mu, sigma, num)
ts = list(zip(dates, values))
return ts

View File

@ -3,9 +3,9 @@ import random
from typing import Literal, Mapping, Sequence
import pytest
from fincal.core import AllFrequencies, Frequency, Series, TimeSeriesCore
from fincal.fincal import create_date_series
from fincal.utils import FincalOptions
from pyfacts.core import AllFrequencies, Frequency, Series, TimeSeriesCore
from pyfacts.pyfacts import create_date_series
from pyfacts.utils import PyfactsOptions
class TestFrequency:
@ -141,9 +141,9 @@ class TestSlicing:
assert ts.get("2021-02-23", -1) == -1
assert ts.get("2021-02-10", closest="previous")[1] == 230
assert ts.get("2021-02-10", closest="next")[1] == 240
FincalOptions.get_closest = "previous"
PyfactsOptions.get_closest = "previous"
assert ts.get("2021-02-10")[1] == 230
FincalOptions.get_closest = "next"
PyfactsOptions.get_closest = "next"
assert ts.get("2021-02-10")[1] == 240
def test_contains(self):

View File

@ -1,14 +1,14 @@
import datetime
import pytest
from fincal import (
from pyfacts import (
AllFrequencies,
FincalOptions,
PyfactsOptions,
Frequency,
TimeSeries,
create_date_series,
)
from fincal.exceptions import DateNotFoundError
from pyfacts.exceptions import DateNotFoundError
class TestDateSeries:
@ -120,7 +120,7 @@ class TestTimeSeriesCreation:
class TestTimeSeriesBasics:
def test_fill(self, create_test_data):
FincalOptions.get_closest = "exact"
PyfactsOptions.get_closest = "exact"
ts_data = create_test_data(frequency=AllFrequencies.D, num=50, skip_weekends=True)
ts = TimeSeries(ts_data, frequency="D")
ffill_data = ts.ffill()
@ -253,7 +253,7 @@ class TestReturns:
def test_date_formats(self, create_test_data):
ts_data = create_test_data(AllFrequencies.D, skip_weekends=True)
ts = TimeSeries(ts_data, "D")
FincalOptions.date_format = "%d-%m-%Y"
PyfactsOptions.date_format = "%d-%m-%Y"
with pytest.raises(ValueError):
ts.calculate_returns(
"2020-04-10", annual_compounded_returns=True, return_period_unit="days", return_period_value=90
@ -265,7 +265,7 @@ class TestReturns:
returns2 = ts.calculate_returns("01-04-2020", return_period_unit="days", return_period_value=90)
assert round(returns1[1], 6) == round(returns2[1], 6) == 0.073632
FincalOptions.date_format = "%m-%d-%Y"
PyfactsOptions.date_format = "%m-%d-%Y"
with pytest.raises(ValueError):
ts.calculate_returns(
"2020-04-01", annual_compounded_returns=True, return_period_unit="days", return_period_value=90
@ -278,7 +278,7 @@ class TestReturns:
assert round(returns1[1], 6) == round(returns2[1], 6) == 0.073632
def test_limits(self, create_test_data):
FincalOptions.date_format = "%Y-%m-%d"
PyfactsOptions.date_format = "%Y-%m-%d"
ts_data = create_test_data(AllFrequencies.D)
ts = TimeSeries(ts_data, "D")
with pytest.raises(DateNotFoundError):
@ -468,7 +468,7 @@ class TestReturnsAgain:
def test_date_formats(self):
ts = TimeSeries(self.data, frequency="M")
FincalOptions.date_format = "%d-%m-%Y"
PyfactsOptions.date_format = "%d-%m-%Y"
with pytest.raises(ValueError):
ts.calculate_returns(
"2020-04-10", annual_compounded_returns=True, return_period_unit="days", return_period_value=90
@ -480,7 +480,7 @@ class TestReturnsAgain:
returns2 = ts.calculate_returns("10-04-2020", return_period_unit="days", return_period_value=90)
assert round(returns1[1], 4) == round(returns2[1], 4) == 5.727
FincalOptions.date_format = "%m-%d-%Y"
PyfactsOptions.date_format = "%m-%d-%Y"
with pytest.raises(ValueError):
ts.calculate_returns(
"2020-04-10", annual_compounded_returns=True, return_period_unit="days", return_period_value=90
@ -494,7 +494,7 @@ class TestReturnsAgain:
def test_limits(self):
ts = TimeSeries(self.data, frequency="M")
FincalOptions.date_format = "%Y-%m-%d"
PyfactsOptions.date_format = "%Y-%m-%d"
with pytest.raises(DateNotFoundError):
ts.calculate_returns("2020-04-25", return_period_unit="days", return_period_value=90, closest_max_days=10)

View File

@ -1,4 +1,4 @@
import fincal as fc
import pyfacts as pft
def test_conf(conf_fun):
@ -8,9 +8,9 @@ def test_conf(conf_fun):
class TestSharpe:
def test_sharpe_daily_freq(self, create_test_data):
data = create_test_data(num=1305, frequency=fc.AllFrequencies.D, skip_weekends=True)
ts = fc.TimeSeries(data, "D")
sharpe_ratio = fc.sharpe_ratio(
data = create_test_data(num=1305, frequency=pft.AllFrequencies.D, skip_weekends=True)
ts = pft.TimeSeries(data, "D")
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.06,
from_date="2017-02-04",
@ -20,7 +20,7 @@ class TestSharpe:
)
assert round(sharpe_ratio, 4) == 1.0502
sharpe_ratio = fc.sharpe_ratio(
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.06,
from_date="2017-01-09",
@ -30,7 +30,7 @@ class TestSharpe:
)
assert round(sharpe_ratio, 4) == 1.0701
sharpe_ratio = fc.sharpe_ratio(
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.06,
from_date="2018-01-02",
@ -40,7 +40,7 @@ class TestSharpe:
)
assert round(sharpe_ratio, 4) == 1.4374
sharpe_ratio = fc.sharpe_ratio(
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.06,
from_date="2017-07-03",
@ -51,9 +51,9 @@ class TestSharpe:
assert round(sharpe_ratio, 4) == 0.8401
def test_sharpe_weekly_freq(self, create_test_data):
data = create_test_data(num=261, frequency=fc.AllFrequencies.W, mu=0.6, sigma=0.7)
ts = fc.TimeSeries(data, "W")
sharpe_ratio = fc.sharpe_ratio(
data = create_test_data(num=261, frequency=pft.AllFrequencies.W, mu=0.6, sigma=0.7)
ts = pft.TimeSeries(data, "W")
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.052,
from_date="2017-01-08",
@ -63,7 +63,7 @@ class TestSharpe:
)
assert round(sharpe_ratio, 4) == 0.4533
sharpe_ratio = fc.sharpe_ratio(
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.052,
from_date="2017-02-05",
@ -73,7 +73,7 @@ class TestSharpe:
)
assert round(sharpe_ratio, 4) == 0.4898
sharpe_ratio = fc.sharpe_ratio(
sharpe_ratio = pft.sharpe_ratio(
ts,
risk_free_rate=0.052,
from_date="2018-01-01",