{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "5c63d04f", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import datetime\n", "import numpy as np\n", "#import plotly as pl\n", "\n", "#import plotly.graph_objs as go\n", "#from plotly.offline import init_notebook_mode, iplot\n", "#from plotly.subplots import make_subplots\n", "#init_notebook_mode()\n", "\n", "import CoreTraidMath \n", "import CoreDraw\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "1ad5c45d", "metadata": {}, "outputs": [], "source": [ "class coreIndicator():\n", " def __init__(self,\n", " data=pd.DataFrame(),\n", " options={},\n", " showMode='None',\n", " ):\n", " '''\n", " showMode = None/Ind/PartOf \n", " '''\n", " self.data=data\n", " self.showMode=showMode\n", " self.options=options\n", " self.overlayInd=None #True/False\n", " self.ans=None\n", " self.figDict=None\n", " \n", " def getAns(self,data=None):\n", " if type(data)!=type(None):\n", " self.data=data\n", " self.ans=self.getCalculate()\n", " if self.showMode=='Ind' or self.showMode=='PartOf':\n", " self.figDict=self.getFigDict()\n", " if self.showMode=='Ind':\n", " self.getFig()\n", " return self.ans\n", " def getFig(self,row=1):\n", " CoreDraw.coreDraw(self.figDict,True)\n", " def getCalculate(self):\n", " return \"Error\"\n", " def getFigDict(self):\n", " return \"Error\"\n", "\n", "class indicatorAgrigator():\n", " '''\n", " Тема чисто для отладки\n", " jj=indicatorAgrigator().runAll([o1,o2],df_candle[:30])\n", " #jj.createIndFromList([o1,o2])\n", " #jj.calculateInd(df_candle[:30])\n", " \n", " '''\n", " def __init__(self):\n", " self.indList=None\n", " self.data=None\n", " def createInd(self,classDict):\n", " return classDict['name'](\n", " options=classDict['params'],\n", " showMode=classDict['showMode']\n", " )\n", " \n", " \n", " def createIndFromList(self,indList):\n", " self.indList=indList\n", " ans=[]\n", " for i in self.indList:\n", " ans.append(self.createInd(i))\n", " self.indList=ans\n", " return ans\n", " \n", " def calculateInd(self,data):\n", " self.data=data\n", " for i in self.indList:\n", " #i.getAns(data)\n", " i.data=self.data\n", " i.ans=i.getCalculate()\n", " i.figDict=i.getFigDict()\n", " #i.getFig()\n", " def agrigateFig(self):\n", " req=[[]]\n", " \n", " for i in self.indList:\n", " if i.overlayInd==True:\n", " req[0].append(i)\n", " else:\n", " req.append([i])\n", " CoreDraw.agrigateFig(req,True)\n", " def runAll(self,indList,df,needDraw=False):\n", " self.createIndFromList(indList)\n", " self.calculateInd(df)\n", " if needDraw:\n", " self.agrigateFig()\n", "\n", " \n", " " ] }, { "cell_type": "code", "execution_count": 4, "id": "15a63ff4", "metadata": {}, "outputs": [], "source": [ "class ind_BB(coreIndicator):\n", " \n", " def getCalculate(self):\n", " self.overlayInd=True\n", " ans={}\n", " opMA={'dataType':'ohcl',\n", " 'action':'findMean',\n", " 'actionOptions':{\n", " 'MeanType':self.options['MeanType'],\n", " 'valueType':self.options['valueType'],\n", " 'window':self.options['window']\n", " }\n", " }\n", " ans['BB']=CoreTraidMath.CoreMath(self.data,opMA).ans\n", " opSTD={'dataType':'ohcl',\n", " 'action':'findSTD',\n", " 'actionOptions':{'valueType':self.options['valueType'],'window':self.options['window']}\n", " }\n", " ans['STD']=CoreTraidMath.CoreMath(self.data,opSTD).ans\n", " ans['pSTD']=ans['BB']+ans['STD']*self.options['kDev']\n", " ans['mSTD']=ans['BB']-ans['STD']*self.options['kDev']\n", " ans['x']=np.array(self.data['date'][self.options['window']-1:].to_list())\n", " return ans\n", " def getFigDict(self,row=1):\n", " req=[]\n", " \n", " req.append({\n", " 'vtype':'Scatter',\n", " 'df':pd.DataFrame(\n", " {'value':self.ans['BB'],'date':self.ans['x']}) ,\n", " 'row':row,\n", " 'col':1,\n", " 'name':'BB'\n", " \n", " })\n", " req.append({\n", " 'vtype':'Scatter',\n", " 'df':pd.DataFrame(\n", " {'value':self.ans['pSTD'],'date':self.ans['x']}) ,\n", " 'row':row,\n", " 'col':1,\n", " 'name':'pSTD'\n", " \n", " })\n", " req.append({\n", " 'vtype':'Scatter',\n", " 'df':pd.DataFrame(\n", " {'value':self.ans['mSTD'],'date':self.ans['x']}) ,\n", " 'row':row,\n", " 'col':1,\n", " 'name':'mSTD'\n", " \n", " })\n", " \n", " return req" ] }, { "cell_type": "code", "execution_count": 5, "id": "4fcf359d", "metadata": {}, "outputs": [], "source": [ "class ind_OCHL(coreIndicator):\n", " def getCalculate(self):\n", " self.overlayInd=True\n", " def getFigDict(self,row=1):\n", " req=[]\n", " \n", " req.append({\n", " 'vtype':'OCHL',\n", " 'df':self.data,\n", " 'row':1,\n", " 'col':1,\n", " 'name':'OHCL'\n", "\n", " })\n", " return req" ] }, { "cell_type": "code", "execution_count": 7, "id": "f2ff80ce", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | date | \n", "open | \n", "close | \n", "high | \n", "low | \n", "
|---|---|---|---|---|---|
| 0 | \n", "2020-09-01 03:00:00+03:00 | \n", "1.19370 | \n", "1.19388 | \n", "1.19391 | \n", "1.19368 | \n", "
| 1 | \n", "2020-09-01 03:00:05+03:00 | \n", "1.19387 | \n", "1.19388 | \n", "1.19391 | \n", "1.19383 | \n", "
| 2 | \n", "2020-09-01 03:00:10+03:00 | \n", "1.19387 | \n", "1.19384 | \n", "1.19389 | \n", "1.19382 | \n", "
| 3 | \n", "2020-09-01 03:00:15+03:00 | \n", "1.19384 | \n", "1.19384 | \n", "1.19386 | \n", "1.19382 | \n", "
| 4 | \n", "2020-09-01 03:00:20+03:00 | \n", "1.19387 | \n", "1.19390 | \n", "1.19391 | \n", "1.19383 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 99995 | \n", "2020-09-06 21:52:55+03:00 | \n", "1.18382 | \n", "1.18382 | \n", "1.18393 | \n", "1.18371 | \n", "
| 99996 | \n", "2020-09-06 21:53:00+03:00 | \n", "1.18382 | \n", "1.18382 | \n", "1.18393 | \n", "1.18371 | \n", "
| 99997 | \n", "2020-09-06 21:53:05+03:00 | \n", "1.18382 | \n", "1.18382 | \n", "1.18393 | \n", "1.18371 | \n", "
| 99998 | \n", "2020-09-06 21:53:10+03:00 | \n", "1.18382 | \n", "1.18382 | \n", "1.18393 | \n", "1.18371 | \n", "
| 99999 | \n", "2020-09-06 21:53:15+03:00 | \n", "1.18382 | \n", "1.18382 | \n", "1.18393 | \n", "1.18371 | \n", "
100000 rows × 5 columns
\n", "