Tests for beta and bug fixes
This commit is contained in:
parent
569f20709b
commit
e9bb795ecf
@ -140,7 +140,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
self,
|
self,
|
||||||
data: List[Iterable] | Mapping,
|
data: List[Iterable] | Mapping,
|
||||||
frequency: Literal["D", "W", "M", "Q", "H", "Y"] = None,
|
frequency: Literal["D", "W", "M", "Q", "H", "Y"] = None,
|
||||||
validate_frequency: bool = False,
|
validate_frequency: bool = True,
|
||||||
date_format: str = "%Y-%m-%d",
|
date_format: str = "%Y-%m-%d",
|
||||||
):
|
):
|
||||||
"""Instantiate a TimeSeriesCore object"""
|
"""Instantiate a TimeSeriesCore object"""
|
||||||
@ -448,7 +448,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
)
|
)
|
||||||
rolling_returns.append(returns)
|
rolling_returns.append(returns)
|
||||||
rolling_returns.sort()
|
rolling_returns.sort()
|
||||||
return self.__class__(rolling_returns, self.frequency.symbol)
|
return self.__class__(rolling_returns, frequency.symbol)
|
||||||
|
|
||||||
@date_parser(1, 2)
|
@date_parser(1, 2)
|
||||||
def volatility(
|
def volatility(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import statistics
|
import statistics
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
@ -82,3 +82,37 @@ class TestSharpe:
|
|||||||
return_period_value=12,
|
return_period_value=12,
|
||||||
)
|
)
|
||||||
assert round(sharpe_ratio, 4) == 0.3199
|
assert round(sharpe_ratio, 4) == 0.3199
|
||||||
|
|
||||||
|
|
||||||
|
class TestBeta:
|
||||||
|
def test_beta_daily_freq(self, create_test_data):
|
||||||
|
market_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D)
|
||||||
|
stock_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D, mu=0.12, sigma=0.08)
|
||||||
|
sts = pft.TimeSeries(stock_data, "D")
|
||||||
|
mts = pft.TimeSeries(market_data, "D")
|
||||||
|
beta = pft.beta(sts, mts, frequency="D", return_period_unit="days", return_period_value=1)
|
||||||
|
assert round(beta, 4) == 1.6001
|
||||||
|
|
||||||
|
def test_beta_daily_freq_daily_returns(self, create_test_data):
|
||||||
|
market_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D)
|
||||||
|
stock_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D, mu=0.12, sigma=0.08)
|
||||||
|
sts = pft.TimeSeries(stock_data, "D")
|
||||||
|
mts = pft.TimeSeries(market_data, "D")
|
||||||
|
beta = pft.beta(sts, mts)
|
||||||
|
assert round(beta, 4) == 1.6292
|
||||||
|
|
||||||
|
def test_beta_monthly_freq(self, create_test_data):
|
||||||
|
market_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D)
|
||||||
|
stock_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D, mu=0.12, sigma=0.08)
|
||||||
|
sts = pft.TimeSeries(stock_data, "D")
|
||||||
|
mts = pft.TimeSeries(market_data, "D")
|
||||||
|
beta = pft.beta(sts, mts, frequency="M")
|
||||||
|
assert round(beta, 4) == 1.629
|
||||||
|
|
||||||
|
def test_beta_monthly_freq_monthly_returns(self, create_test_data):
|
||||||
|
market_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D)
|
||||||
|
stock_data = create_test_data(num=3600, frequency=pft.AllFrequencies.D, mu=0.12, sigma=0.08)
|
||||||
|
sts = pft.TimeSeries(stock_data, "D")
|
||||||
|
mts = pft.TimeSeries(market_data, "D")
|
||||||
|
beta = pft.beta(sts, mts, frequency="M", return_period_unit="months", return_period_value=1)
|
||||||
|
assert round(beta, 4) == 1.6023
|
||||||
|
Loading…
Reference in New Issue
Block a user