Series tests pass data type as string
This commit is contained in:
parent
306a2d730c
commit
9707c095b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
.env
|
.env
|
||||||
*egg-info
|
*egg-info
|
||||||
__pycache__
|
__pycache__
|
||||||
|
.vscode
|
@ -1,16 +1,19 @@
|
|||||||
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
import timeit
|
||||||
|
|
||||||
import pandas
|
import pandas
|
||||||
|
|
||||||
from fincal.fincal import AllFrequencies, Frequency, TimeSeries, create_date_series
|
from fincal.fincal import AllFrequencies, TimeSeries, create_date_series
|
||||||
|
|
||||||
dfd = pandas.read_csv('test_files/nav_history_daily - Copy.csv')
|
dfd = pandas.read_csv('test_files/msft.csv')
|
||||||
dfm = pandas.read_csv('test_files/nav_history_monthly.csv')
|
dfm = pandas.read_csv('test_files/nav_history_monthly.csv')
|
||||||
dfq = pandas.read_csv('test_files/nav_history_quarterly.csv')
|
dfq = pandas.read_csv('test_files/nav_history_quarterly.csv')
|
||||||
|
|
||||||
data_d = [(i.date, i.nav) for i in dfd.itertuples()]
|
data_d = [(i.date, i.nav) for i in dfd.itertuples()]
|
||||||
data_m = [{'date': i.date, 'value': i.nav} for i in dfm.itertuples()]
|
data_m = [{'date': i.date, 'value': i.nav} for i in dfm.itertuples()]
|
||||||
data_q = {i.date: i.nav for i in dfq.itertuples()}
|
data_q = {i.date: i.nav for i in dfq.itertuples()}
|
||||||
|
data_q.update({'14-02-2022': 93.7})
|
||||||
|
|
||||||
tsd = TimeSeries(data_d, frequency='D')
|
tsd = TimeSeries(data_d, frequency='D')
|
||||||
tsm = TimeSeries(data_m, frequency='M', date_format='%d-%m-%Y')
|
tsm = TimeSeries(data_m, frequency='M', date_format='%d-%m-%Y')
|
||||||
@ -18,6 +21,6 @@ tsq = TimeSeries(data_q, frequency='Q', date_format='%d-%m-%Y')
|
|||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
# ts.calculate_rolling_returns(datetime.datetime(2015, 1, 1), datetime.datetime(2022, 2, 1), years=1)
|
# ts.calculate_rolling_returns(datetime.datetime(2015, 1, 1), datetime.datetime(2022, 2, 1), years=1)
|
||||||
# fdata = tsd.ffill()
|
bdata = tsq.bfill()
|
||||||
# rr = tsd.calculate_rolling_returns(datetime.datetime(2022, 1, 1), datetime.datetime(2022, 2, 1), years=1)
|
# rr = tsd.calculate_rolling_returns(datetime.datetime(2022, 1, 1), datetime.datetime(2022, 2, 1), years=1)
|
||||||
print(time.time() - start)
|
print(time.time() - start)
|
||||||
|
35
test.py
Normal file
35
test.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# type: ignore
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
from fincal.fincal import TimeSeries
|
||||||
|
|
||||||
|
df = pd.read_csv('test_files/nav_history_daily.csv')
|
||||||
|
df = df.sort_values(by=['amfi_code', 'date']) # type: ignore
|
||||||
|
data_list = [(i.date, i.nav) for i in df[df.amfi_code == 118825].itertuples()]
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
ts_data = TimeSeries(data_list, frequency='M')
|
||||||
|
print(f"Instantiation took {round((time.time() - start)*1000, 2)} ms")
|
||||||
|
# ts_data.fill_missing_days()
|
||||||
|
start = time.time()
|
||||||
|
# ts_data.calculate_returns(as_on=datetime.datetime(2022, 1, 4), closest='next', years=1)
|
||||||
|
rr = ts_data.calculate_rolling_returns(datetime.datetime(2015, 1, 1),
|
||||||
|
datetime.datetime(2022, 1, 21),
|
||||||
|
frequency='M',
|
||||||
|
as_on_match='next',
|
||||||
|
prior_match='previous',
|
||||||
|
closest='previous',
|
||||||
|
years=1)
|
||||||
|
|
||||||
|
# ffill_data = ts_data.bfill()
|
||||||
|
print(f"Calculation took {round((time.time() - start)*1000, 2)} ms")
|
||||||
|
rr.sort()
|
||||||
|
for i in rr[:10]:
|
||||||
|
print(i)
|
||||||
|
# print(ffill_data)
|
||||||
|
# print(ts_data)
|
||||||
|
# print(repr(ts_data))
|
37
test2.py
Normal file
37
test2.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# type: ignore
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
from fincal.fincal import TimeSeries
|
||||||
|
|
||||||
|
df = pd.read_csv('test_files/msft.csv')
|
||||||
|
df = df.sort_values(by='Date') # type: ignore
|
||||||
|
data_list = [(i.Date, i.Close) for i in df.itertuples()]
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
ts_data = TimeSeries(data_list, frequency='D', date_format='%d-%m-%Y')
|
||||||
|
print(f"Instantiation took {round((time.time() - start)*1000, 2)} ms")
|
||||||
|
# ts_data.fill_missing_days()
|
||||||
|
start = time.time()
|
||||||
|
# ts_data.calculate_returns(as_on=datetime.datetime(2022, 1, 4), closest='next', years=1)
|
||||||
|
rr = ts_data.calculate_rolling_returns(datetime.datetime(1994, 1, 1),
|
||||||
|
datetime.datetime(2022, 2, 17),
|
||||||
|
frequency='D',
|
||||||
|
as_on_match='next',
|
||||||
|
prior_match='previous',
|
||||||
|
closest='previous',
|
||||||
|
years=1)
|
||||||
|
|
||||||
|
# ffill_data = ts_data.bfill()
|
||||||
|
print(f"Calculation took {round((time.time() - start)*1000, 2)} ms")
|
||||||
|
rr.sort()
|
||||||
|
for i in rr[:10]:
|
||||||
|
print(i)
|
||||||
|
# print(ffill_data)
|
||||||
|
# print(ts_data)
|
||||||
|
# print(repr(ts_data))
|
7560
test_files/msft.csv
Normal file
7560
test_files/msft.csv
Normal file
File diff suppressed because it is too large
Load Diff
25
test_series.py
Normal file
25
test_series.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
from fincal.core import Series
|
||||||
|
|
||||||
|
s1 = Series([2.5, 6.2, 5.6, 8.4, 7.4, 1.5, 9.6, 5])
|
||||||
|
|
||||||
|
dt_lst = [
|
||||||
|
datetime.datetime(2020, 12, 4, 0, 0),
|
||||||
|
datetime.datetime(2019, 5, 16, 0, 0),
|
||||||
|
datetime.datetime(2019, 9, 25, 0, 0),
|
||||||
|
datetime.datetime(2016, 2, 18, 0, 0),
|
||||||
|
datetime.datetime(2017, 8, 14, 0, 0),
|
||||||
|
datetime.datetime(2018, 1, 4, 0, 0),
|
||||||
|
datetime.datetime(2017, 5, 21, 0, 0),
|
||||||
|
datetime.datetime(2018, 7, 17, 0, 0),
|
||||||
|
datetime.datetime(2016, 4, 8, 0, 0),
|
||||||
|
datetime.datetime(2020, 1, 7, 0, 0),
|
||||||
|
datetime.datetime(2016, 12, 24, 0, 0),
|
||||||
|
datetime.datetime(2020, 6, 19, 0, 0),
|
||||||
|
datetime.datetime(2016, 3, 16, 0, 0),
|
||||||
|
datetime.datetime(2017, 4, 25, 0, 0),
|
||||||
|
datetime.datetime(2016, 7, 10, 0, 0)
|
||||||
|
]
|
||||||
|
|
||||||
|
s2 = Series(dt_lst)
|
7560
tests/data/msft.csv
Normal file
7560
tests/data/msft.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -40,10 +40,10 @@ class TestAllFrequencies:
|
|||||||
|
|
||||||
class TestSeries:
|
class TestSeries:
|
||||||
def test_creation(self):
|
def test_creation(self):
|
||||||
series = Series([1, 2, 3, 4, 5, 6, 7], data_type=int)
|
series = Series([1, 2, 3, 4, 5, 6, 7], data_type='number')
|
||||||
assert series.dtype == float
|
assert series.dtype == float
|
||||||
assert series[2] == 3
|
assert series[2] == 3
|
||||||
|
|
||||||
dates = create_date_series('2021-01-01', '2021-01-31', 'D')
|
dates = create_date_series('2021-01-01', '2021-01-31', frequency='D')
|
||||||
series = Series(dates, data_type=datetime.datetime)
|
series = Series(dates, data_type='date')
|
||||||
assert Series.dtype == datetime.datetime
|
assert series.dtype == datetime.datetime
|
||||||
|
Loading…
Reference in New Issue
Block a user