2022-02-21 02:52:04 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 1,
|
2022-02-21 02:52:04 +00:00
|
|
|
"id": "3f7938c0-98e3-43b8-86e8-4f000cda7ce5",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"import datetime\n",
|
|
|
|
"import pandas as pd\n",
|
|
|
|
"\n",
|
|
|
|
"from fincal.fincal import TimeSeries\n",
|
|
|
|
"from fincal.core import Series"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 2,
|
|
|
|
"id": "4b8ccd5f-dfff-4202-82c4-f66a30c122b6",
|
2022-02-21 02:52:04 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2022-02-21 07:41:38 +00:00
|
|
|
"dfd = pd.read_csv('test_files/nav_history_daily - copy.csv')\n",
|
|
|
|
"\n",
|
2022-02-21 02:52:04 +00:00
|
|
|
"dfd = dfd[dfd['amfi_code'] == 118825].reset_index(drop=True)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 3,
|
|
|
|
"id": "c52b0c2c-dd01-48dd-9ffa-3147ec9571ef",
|
2022-02-21 02:52:04 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"Warning: The input data contains duplicate dates which have been ignored.\n"
|
|
|
|
]
|
2022-02-21 07:41:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
|
|
|
"TimeSeries([(datetime.datetime(2013, 1, 2, 0, 0), 18.972),\n",
|
|
|
|
"\t (datetime.datetime(2013, 1, 3, 0, 0), 19.011),\n",
|
|
|
|
"\t (datetime.datetime(2013, 1, 4, 0, 0), 19.008)\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",
|
2022-02-21 17:18:24 +00:00
|
|
|
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
2022-02-21 07:41:38 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"execution_count": 3,
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
2022-02-21 02:52:04 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-02-21 07:41:38 +00:00
|
|
|
"ts = TimeSeries([(i.date, i.nav) for i in dfd.itertuples()], frequency='D')\n",
|
|
|
|
"\n",
|
|
|
|
"ts"
|
2022-02-21 02:52:04 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 4,
|
|
|
|
"id": "9e8ff6c6-3a36-435a-ba87-5b9844c18779",
|
2022-02-21 02:52:04 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"[(datetime.datetime(2022, 1, 31, 0, 0), 85.18),\n",
|
|
|
|
" (datetime.datetime(2021, 5, 31, 0, 0), 74.85)]"
|
2022-02-21 02:52:04 +00:00
|
|
|
]
|
|
|
|
},
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 4,
|
2022-02-21 02:52:04 +00:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"ts[['2022-01-31', '2021-05-31']]"
|
2022-02-21 02:52:04 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 07:41:38 +00:00
|
|
|
"execution_count": 5,
|
|
|
|
"id": "4d927a61-0f90-4b47-89b7-0e0d3ab1b442",
|
2022-02-21 02:52:04 +00:00
|
|
|
"metadata": {},
|
2022-02-21 07:41:38 +00:00
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"s = ts.dates > '2020-01-01'"
|
2022-02-21 07:41:38 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 17:18:24 +00:00
|
|
|
"execution_count": 6,
|
|
|
|
"id": "f90074f8-5173-49a9-a7d6-ceac01e92431",
|
2022-02-21 07:41:38 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"TimeSeries([(datetime.datetime(2020, 1, 2, 0, 0), 58.285),\n",
|
|
|
|
"\t (datetime.datetime(2020, 1, 3, 0, 0), 58.056999999999995),\n",
|
|
|
|
"\t (datetime.datetime(2020, 1, 6, 0, 0), 56.938)\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')"
|
2022-02-21 07:41:38 +00:00
|
|
|
]
|
|
|
|
},
|
2022-02-21 17:18:24 +00:00
|
|
|
"execution_count": 6,
|
2022-02-21 07:41:38 +00:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"ts[s]"
|
2022-02-21 07:41:38 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-02-21 17:18:24 +00:00
|
|
|
"execution_count": 14,
|
2022-02-21 07:41:38 +00:00
|
|
|
"id": "dc469722-c816-4b57-8d91-7a3b865f86be",
|
|
|
|
"metadata": {
|
|
|
|
"tags": []
|
|
|
|
},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"CPU times: total: 15.6 ms\n",
|
|
|
|
"Wall time: 13 ms\n"
|
2022-02-21 02:52:04 +00:00
|
|
|
]
|
2022-02-21 17:18:24 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"%%time\n",
|
|
|
|
"from_date = datetime.date(2020, 1, 1)\n",
|
|
|
|
"to_date = datetime.date(2021, 1, 1)\n",
|
|
|
|
"# print(ts.calculate_returns(to_date, years=7))\n",
|
|
|
|
"rr = ts.calculate_rolling_returns(from_date, to_date)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 15,
|
|
|
|
"id": "086d4377-d1b1-4e51-84c0-39dee28ef75e",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
2022-02-21 07:41:38 +00:00
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"list"
|
2022-02-21 07:41:38 +00:00
|
|
|
]
|
|
|
|
},
|
2022-02-21 17:18:24 +00:00
|
|
|
"execution_count": 15,
|
2022-02-21 07:41:38 +00:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
2022-02-21 02:52:04 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-02-21 17:18:24 +00:00
|
|
|
"type(rr)"
|
2022-02-21 02:52:04 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
2022-02-21 17:18:24 +00:00
|
|
|
"display_name": "Python 3 (ipykernel)",
|
2022-02-21 02:52:04 +00:00
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2022-02-21 17:18:24 +00:00
|
|
|
"version": "3.8.3"
|
2022-02-21 02:52:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|