Skip to content

Commit

Permalink
update gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-abuke committed Jun 20, 2024
1 parent 03bf707 commit 3e75319
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ celerybeat.pid
.env
.venv
env/
backtesting/**
venv/
backtest/
ENV/
Expand Down
104 changes: 104 additions & 0 deletions notebooks/backtesting.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\user\\Downloads\\ten_academy\\week9\\Scalable_Backtesting_Infrastructure_for_Crypto_Trading\\backtest\\lib\\site-packages\\backtesting\\test\\__init__.py:8: FutureWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n",
" return pd.read_csv(join(dirname(__file__), filename),\n",
"c:\\Users\\user\\Downloads\\ten_academy\\week9\\Scalable_Backtesting_Infrastructure_for_Crypto_Trading\\backtest\\lib\\site-packages\\backtesting\\test\\__init__.py:8: FutureWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n",
" return pd.read_csv(join(dirname(__file__), filename),\n"
]
}
],
"source": [
"import datetime\n",
"import pandas_ta as ta\n",
"import pandas as pd\n",
"\n",
"from backtesting import Backtest\n",
"from backtesting import Strategy\n",
"from backtesting.lib import crossover\n",
"from backtesting.test import GOOG\n",
"\n",
"class RsiOscillator(Strategy):\n",
"\n",
" upper_bound = 70\n",
" lower_bound = 30\n",
" rsi_window = 14\n",
"\n",
" # Do as much initial computation as possible\n",
" def init(self):\n",
" self.rsi = self.I(ta.rsi, pd.Series(self.data.Close), self.rsi_window)\n",
"\n",
" # Step through bars one by one\n",
" # Note that multiple buys are a thing here\n",
" def next(self):\n",
" if crossover(self.rsi, self.upper_bound):\n",
" self.position.close()\n",
" elif crossover(self.lower_bound, self.rsi):\n",
" self.buy()\n",
"\n",
"bt = Backtest(GOOG, RsiOscillator, cash=10_000, commission=.002)\n",
"stats = bt.run()\n",
"bt.plot()\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Open High Low Close Volume\n",
"2004-08-19 100.00 104.06 95.96 100.34 22351900\n",
"2004-08-20 101.01 109.08 100.50 108.31 11428600\n",
"2004-08-23 110.75 113.48 109.05 109.40 9137200\n",
"2004-08-24 111.24 111.60 103.57 104.87 7631300\n",
"2004-08-25 104.96 108.00 103.88 106.00 4598900\n",
"... ... ... ... ... ...\n",
"2013-02-25 802.30 808.41 790.49 790.77 2303900\n",
"2013-02-26 795.00 795.95 784.40 790.13 2202500\n",
"2013-02-27 794.80 804.75 791.11 799.78 2026100\n",
"2013-02-28 801.10 806.99 801.03 801.20 2265800\n",
"2013-03-01 797.80 807.14 796.15 806.19 2175400\n",
"\n",
"[2148 rows x 5 columns]\n"
]
}
],
"source": [
"print(GOOG)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "backtest",
"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.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3e75319

Please sign in to comment.