daily update
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Test persistance\n",
|
||||
"# Experiment with file persistence structure\n",
|
||||
"\n",
|
||||
"ohlcv and trades persistence with bar type and trade filtering and minsize support\n",
|
||||
"\n",
|
||||
1238
research/data/db_loader_saver.ipynb
Normal file
1238
research/data/db_loader_saver.ipynb
Normal file
File diff suppressed because one or more lines are too long
105
research/rolling_linreg_visualization.ipynb
Normal file
105
research/rolling_linreg_visualization.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -1,82 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import statsmodels.api as sm\n",
|
||||
"\n",
|
||||
"# Example time series data\n",
|
||||
"np.random.seed(0)\n",
|
||||
"dates = pd.date_range('2023-01-01', periods=100)\n",
|
||||
"data = pd.Series(np.random.randn(100).cumsum(), index=dates)\n",
|
||||
"\n",
|
||||
"# Parameters\n",
|
||||
"window_size = 20\n",
|
||||
"\n",
|
||||
"# Function to calculate rolling window linear regression\n",
|
||||
"def rolling_linreg(series, window):\n",
|
||||
" intercepts = []\n",
|
||||
" slopes = []\n",
|
||||
" for i in range(len(series) - window + 1):\n",
|
||||
" y = series[i:i + window]\n",
|
||||
" x = np.arange(window)\n",
|
||||
" x = sm.add_constant(x)\n",
|
||||
" model = sm.OLS(y, x).fit()\n",
|
||||
" intercepts.append(model.params[0])\n",
|
||||
" slopes.append(model.params[1])\n",
|
||||
" return intercepts, slopes\n",
|
||||
"\n",
|
||||
"# Calculate rolling linear regression parameters\n",
|
||||
"intercepts, slopes = rolling_linreg(data, window_size)\n",
|
||||
"\n",
|
||||
"# Create a DataFrame for plotting\n",
|
||||
"rolling_dates = dates[window_size - 1:]\n",
|
||||
"rolling_intercepts = pd.Series(intercepts, index=rolling_dates)\n",
|
||||
"rolling_slopes = pd.Series(slopes, index=rolling_dates)\n",
|
||||
"\n",
|
||||
"# Plot the original data and the rolling linear regression\n",
|
||||
"plt.figure(figsize=(14, 7))\n",
|
||||
"plt.plot(data, label='Original Data')\n",
|
||||
"for i in range(len(rolling_intercepts)):\n",
|
||||
" start_date = rolling_dates[i] - pd.DateOffset(days=window_size-1)\n",
|
||||
" end_date = rolling_dates[i]\n",
|
||||
" plt.plot([start_date, end_date],\n",
|
||||
" [rolling_intercepts[i], rolling_intercepts[i] + rolling_slopes[i] * (window_size - 1)],\n",
|
||||
" color='red', alpha=0.5)\n",
|
||||
"\n",
|
||||
"plt.legend()\n",
|
||||
"plt.title('Rolling Window Linear Regression')\n",
|
||||
"plt.xlabel('Date')\n",
|
||||
"plt.ylabel('Value')\n",
|
||||
"plt.show()\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"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",
|
||||
"version": "3.10.11"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user