Updated test file
This commit is contained in:
parent
c713e3283b
commit
569f20709b
@ -485,7 +485,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import random\n",
|
"import random\n",
|
||||||
"import math\n",
|
"import math\n",
|
||||||
"import fincal as fc\n",
|
"import pyfacts as pft\n",
|
||||||
"from typing import List\n",
|
"from typing import List\n",
|
||||||
"import datetime\n",
|
"import datetime\n",
|
||||||
"from dateutil.relativedelta import relativedelta"
|
"from dateutil.relativedelta import relativedelta"
|
||||||
@ -536,7 +536,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def sample_data_generator(\n",
|
"def sample_data_generator(\n",
|
||||||
" frequency: fc.Frequency,\n",
|
" frequency: pft.Frequency,\n",
|
||||||
" num: int = 1000,\n",
|
" num: int = 1000,\n",
|
||||||
" skip_weekends: bool = False,\n",
|
" skip_weekends: bool = False,\n",
|
||||||
" mu: float = 0.1,\n",
|
" mu: float = 0.1,\n",
|
||||||
@ -571,11 +571,11 @@
|
|||||||
" start_date = datetime.datetime(2017, 1, 1)\n",
|
" start_date = datetime.datetime(2017, 1, 1)\n",
|
||||||
" timedelta_dict = {\n",
|
" timedelta_dict = {\n",
|
||||||
" frequency.freq_type: int(\n",
|
" frequency.freq_type: int(\n",
|
||||||
" frequency.value * num * (7 / 5 if frequency == fc.AllFrequencies.D and skip_weekends else 1)\n",
|
" frequency.value * num * (7 / 5 if frequency == pft.AllFrequencies.D and skip_weekends else 1)\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" }\n",
|
" }\n",
|
||||||
" end_date = start_date + relativedelta(**timedelta_dict)\n",
|
" end_date = start_date + relativedelta(**timedelta_dict)\n",
|
||||||
" dates = fc.create_date_series(start_date, end_date, frequency.symbol, skip_weekends=skip_weekends, eomonth=eomonth)\n",
|
" dates = pft.create_date_series(start_date, end_date, frequency.symbol, skip_weekends=skip_weekends, eomonth=eomonth)\n",
|
||||||
" values = create_prices(1000, mu, sigma, num)\n",
|
" values = create_prices(1000, mu, sigma, num)\n",
|
||||||
" ts = list(zip(dates, values))\n",
|
" ts = list(zip(dates, values))\n",
|
||||||
" return ts\n"
|
" return ts\n"
|
||||||
@ -583,40 +583,36 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": 6,
|
||||||
"id": "c85b5dd9-9a88-4608-ac58-1a141295f63f",
|
"id": "c85b5dd9-9a88-4608-ac58-1a141295f63f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"data = sample_data_generator(num=261, frequency=fc.AllFrequencies.W)\n",
|
"market_data = sample_data_generator(num=3600, frequency=pft.AllFrequencies.D)\n",
|
||||||
"ts = fc.TimeSeries(data, \"W\")"
|
"mts = pft.TimeSeries(market_data, \"D\")\n",
|
||||||
|
"stock_data = sample_data_generator(num=3600, frequency=pft.AllFrequencies.D, mu=0.12, sigma=0.05)\n",
|
||||||
|
"sts = pft.TimeSeries(stock_data, 'D')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 13,
|
"execution_count": 8,
|
||||||
"id": "0488a4d0-bca1-4341-9fae-1fd254adc0dc",
|
"id": "0488a4d0-bca1-4341-9fae-1fd254adc0dc",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"TimeSeries([(datetime.datetime(2017, 1, 1, 0, 0), 1003.03),\n",
|
"1.020217253491451"
|
||||||
"\t (datetime.datetime(2017, 1, 8, 0, 0), 1002.71),\n",
|
|
||||||
"\t (datetime.datetime(2017, 1, 15, 0, 0), 1008.77)\n",
|
|
||||||
"\t ...\n",
|
|
||||||
"\t (datetime.datetime(2021, 12, 12, 0, 0), 1107.21),\n",
|
|
||||||
"\t (datetime.datetime(2021, 12, 19, 0, 0), 1106.66),\n",
|
|
||||||
"\t (datetime.datetime(2021, 12, 26, 0, 0), 1104.32)], frequency='W')"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 13,
|
"execution_count": 8,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"ts"
|
"pft.beta(sts, mts)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -708,7 +704,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.2"
|
"version": "3.10.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
Loading…
Reference in New Issue
Block a user