PyFacts/my_test.py

27 lines
957 B
Python
Raw Permalink Normal View History

2022-02-22 07:35:54 +00:00
import datetime
2022-02-20 06:06:56 +00:00
import time
2022-02-22 07:35:54 +00:00
import timeit
2022-02-20 06:06:56 +00:00
import pandas
2022-02-22 07:35:54 +00:00
from fincal.fincal import AllFrequencies, TimeSeries, create_date_series
2022-02-20 06:06:56 +00:00
2022-02-22 07:35:54 +00:00
dfd = pandas.read_csv('test_files/msft.csv')
2022-02-20 06:06:56 +00:00
dfm = pandas.read_csv('test_files/nav_history_monthly.csv')
dfq = pandas.read_csv('test_files/nav_history_quarterly.csv')
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_q = {i.date: i.nav for i in dfq.itertuples()}
2022-02-22 07:35:54 +00:00
data_q.update({'14-02-2022': 93.7})
2022-02-20 06:06:56 +00:00
tsd = TimeSeries(data_d, frequency='D')
tsm = TimeSeries(data_m, frequency='M', date_format='%d-%m-%Y')
tsq = TimeSeries(data_q, frequency='Q', date_format='%d-%m-%Y')
start = time.time()
# ts.calculate_rolling_returns(datetime.datetime(2015, 1, 1), datetime.datetime(2022, 2, 1), years=1)
2022-02-22 07:35:54 +00:00
bdata = tsq.bfill()
2022-02-20 06:06:56 +00:00
# rr = tsd.calculate_rolling_returns(datetime.datetime(2022, 1, 1), datetime.datetime(2022, 2, 1), years=1)
print(time.time() - start)