Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions Trading_Using_CNN.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from pandas import DataFrame # specify datatype while passing df object"
"from pandas import DataFrame # specify datatype while passing df object\\"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
" #df = pd.read_csv('WMT.csv')\n",
" #Uncomment this and read the WMT csv file wherever its stored on your local device"
"#df = pd.read_csv('WMT.csv')#Uncomment this and read the WMT csv file wherever its stored on your local device"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 39,
"metadata": {},
"outputs": [
{
"ename": "IndentationError",
"evalue": "expected an indented block (<ipython-input-5-cae2ff3fa008>, line 5)",
"output_type": "error",
"ename": "IndentationError",
"evalue": "expected an indented block (<ipython-input-39-2e1955fcb271>, line 5)",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-5-cae2ff3fa008>\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m def cmo():\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-39-2e1955fcb271>\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m def cmo():\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n"
]
}
],
Expand Down Expand Up @@ -87,6 +86,7 @@
" return df\n",
" \n",
"def ppo():\n",
" \n",
" \n",
"def ema(df: DataFrame):\n",
" '''\n",
Expand All @@ -109,7 +109,34 @@
" \n",
"def cmfi():\n",
"\n",
"def hma():\n",
"def hma(df):\n",
" '''\n",
" HMA: Hull Moving Average is a much faster and smoother moving average.\n",
" Computed over periods 6 to 20 (both inclusive)\n",
" \n",
" Arguement: \n",
" df: DataFrame object initialised from the csv data\n",
" Returns:\n",
" df: Modified DataFrame object\n",
" '''\n",
"\n",
" for len in range(6,21):\n",
" col_name = f'hma_{len}'\n",
" half_len = len//2\n",
" k = int(np.sqrt(len))\n",
"\n",
" half_weights = np.arange(1, half_len+1)\n",
" weights = np.arange(1, len+1)\n",
" \n",
" half_wma = df['Adj Close'].rolling(half_len).apply(lambda x: np.dot(x, half_weights)/half_weights.sum(), raw=True)\n",
" full_wma = df['Adj Close'].rolling(len).apply(lambda x: np.dot(x, weights)/weights.sum(), raw=True)\n",
"\n",
" diff = (2*half_wma) - full_wma\n",
"\n",
" w = np.arange(1, k+1)\n",
" df[col_name] = diff.rolling(k).apply(lambda x: np.dot(x, w)/w.sum(), raw=True)\n",
"\n",
" return df\n",
" \n",
"def dmi():\n",
" \n",
Expand All @@ -128,15 +155,15 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 40,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "unexpected EOF while parsing (<ipython-input-6-c7c1a64e3c53>, line 1)",
"output_type": "error",
"ename": "SyntaxError",
"evalue": "unexpected EOF while parsing (<ipython-input-40-c7c1a64e3c53>, line 1)",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-6-c7c1a64e3c53>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m def label_data():\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-40-c7c1a64e3c53>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m def label_data():\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected EOF while parsing\n"
]
}
],
Expand Down Expand Up @@ -168,7 +195,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9-final"
}
},
"nbformat": 4,
Expand Down