diff --git a/fincal/fincal.py b/fincal/fincal.py index d7b8eed..ba9d9ce 100644 --- a/fincal/fincal.py +++ b/fincal/fincal.py @@ -225,7 +225,7 @@ class TimeSeries(TimeSeriesCore): ) rolling_returns.append((i, returns)) rolling_returns.sort() - return rolling_returns + return self.__class__(rolling_returns, self.frequency.symbol) if __name__ == "__main__": diff --git a/testing.ipynb b/testing.ipynb index 3edcdf8..67fb39e 100644 --- a/testing.ipynb +++ b/testing.ipynb @@ -22,7 +22,6 @@ "outputs": [], "source": [ "dfd = pd.read_csv('test_files/nav_history_daily - copy.csv')\n", - "\n", "dfd = dfd[dfd['amfi_code'] == 118825].reset_index(drop=True)" ] }, @@ -58,7 +57,6 @@ ], "source": [ "ts = TimeSeries([(i.date, i.nav) for i in dfd.itertuples()], frequency='D')\n", - "\n", "ts" ] }, @@ -86,18 +84,35 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "4d927a61-0f90-4b47-89b7-0e0d3ab1b442", + "execution_count": 16, + "id": "086d4377-d1b1-4e51-84c0-39dee28ef75e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "TimeSeries([(datetime.datetime(2021, 2, 15, 0, 0), 73.483),\n", + "\t (datetime.datetime(2021, 2, 16, 0, 0), 73.237),\n", + "\t (datetime.datetime(2021, 2, 17, 0, 0), 72.98)\n", + "\t ...\n", + "\t (datetime.datetime(2022, 2, 10, 0, 0), 86.5),\n", + "\t (datetime.datetime(2022, 2, 11, 0, 0), 85.226),\n", + "\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "s = ts.dates > '2020-01-01'" + "ts[ts.dates>'2021-02-14']" ] }, { "cell_type": "code", - "execution_count": 6, - "id": "f90074f8-5173-49a9-a7d6-ceac01e92431", + "execution_count": 5, + "id": "6f1226a3-2327-435b-88e7-fd0fdcc8cc1c", "metadata": {}, "outputs": [ { @@ -112,18 +127,49 @@ "\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "s = ts.dates > '2020-01-01'\n", "ts[s]" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, + "id": "e815edc9-3746-4192-814e-bd27b2771a0c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(datetime.datetime(2013, 1, 2, 0, 0), 18.972),\n", + " (datetime.datetime(2013, 1, 3, 0, 0), 19.011),\n", + " (datetime.datetime(2013, 1, 4, 0, 0), 19.008),\n", + " (datetime.datetime(2013, 1, 7, 0, 0), 18.95),\n", + " (datetime.datetime(2013, 1, 8, 0, 0), 18.954),\n", + " (datetime.datetime(2013, 1, 9, 0, 0), 18.94),\n", + " (datetime.datetime(2013, 1, 10, 0, 0), 18.957),\n", + " (datetime.datetime(2013, 1, 11, 0, 0), 18.948),\n", + " (datetime.datetime(2013, 1, 14, 0, 0), 19.177),\n", + " (datetime.datetime(2013, 1, 15, 0, 0), 19.272000000000002)]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ts.iloc[:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, "id": "dc469722-c816-4b57-8d91-7a3b865f86be", "metadata": { "tags": [] @@ -134,7 +180,7 @@ "output_type": "stream", "text": [ "CPU times: total: 15.6 ms\n", - "Wall time: 13 ms\n" + "Wall time: 14 ms\n" ] } ], @@ -148,24 +194,11 @@ }, { "cell_type": "code", - "execution_count": 15, - "id": "086d4377-d1b1-4e51-84c0-39dee28ef75e", + "execution_count": null, + "id": "e5d357b4-4fe5-4a0a-8107-0ab6828d7c41", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(rr)" - ] + "outputs": [], + "source": [] } ], "metadata": {