Skip to content

Commit 9b227f2

Browse files
committed
CHanges
1 parent ac066f4 commit 9b227f2

File tree

6 files changed

+76
-48
lines changed

6 files changed

+76
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ IntradayData_2018/*
33
.idea/
44
result.csv
55
*.pyc
6+
NIFTY50_APR2019/*

classes/MinuteEntry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utils.TimeUtil import convertTime
1+
from utils.TimeUtil import convertTime, revConvertTime
22

33

44
def parseMinuteData(minuteData, shortTerm, longTerm):
@@ -18,3 +18,7 @@ class Minute:
1818
def __init__(self, minuteData, shortTerm = 0, longTerm = 0):
1919
self.time, self.openingPrice, self.low, self.high, self.closingPrice, self.diff = parseMinuteData(minuteData, shortTerm, longTerm)
2020
self.listPrice = 0.5 * (self.openingPrice + self.closingPrice)
21+
22+
def toString(self, verbose):
23+
if verbose:
24+
print 'Time: {}, Low: {}, High: {}'.format(revConvertTime(self.time), self.low, self.high)

classes/RenkoEntry.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
class Renko:
2-
def __init__(self, low, high):
2+
def __init__(self, low, high, renkoType):
33
self.low = low
44
self.high = high
5-
self.renkoType = self.getRenkoType()
5+
self.renkoType = renkoType
66

7-
def getRenkoType(self):
8-
if self.low > self.high:
9-
renkoType = -1
10-
elif self.high > self.low:
11-
renkoType = 1
12-
else:
13-
renkoType = 0
14-
return renkoType
15-
16-
def toString(self):
17-
print('low - {}, high - {}, type - {}'.format(self.low, self.high, self.renkoType))
7+
def toString(self, verbose):
8+
if verbose:
9+
print('low: {}, high: {}, type: {}'.format(self.low, self.high, self.renkoType))

eom_renko_multiStock.ipynb

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 23,
5+
"execution_count": 37,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 24,
27+
"execution_count": 38,
2828
"metadata": {
2929
"scrolled": false
3030
},
@@ -45,13 +45,12 @@
4545
" for date in dateList:\n",
4646
" new_df = df[(df.date == date)]\n",
4747
" day = renkoScript(new_df, paramEntry, newDay, renkoDeque, stockType, verbose)\n",
48-
" if verbose:\n",
49-
" print(date, newDay.money, day.money, day.dailyTrades)\n",
50-
" day.printOpenTrade()\n",
48+
"# if verbose:\n",
49+
"# print(date, newDay.money, day.money, day.dailyTrades)\n",
50+
"# day.printOpenTrade()\n",
5151
" sellEndOfDay = getSellEndOfDay(date, stockType)\n",
5252
" newDay = day.initializeNextDay(sellEndOfDay) \n",
5353
" yearlyProfitPercentage = (day.money - 1) * 100\n",
54-
" print(yearlyProfitPercentage)\n",
5554
" paramEntry.profitPercentage = yearlyProfitPercentage\n",
5655
" paramEntry.toString()\n",
5756
" \n",
@@ -60,7 +59,7 @@
6059
},
6160
{
6261
"cell_type": "code",
63-
"execution_count": 25,
62+
"execution_count": 39,
6463
"metadata": {
6564
"scrolled": true
6665
},
@@ -69,7 +68,7 @@
6968
"def bruteAnalysis(stockName, parameterDict, pool, threadPoolSize):\n",
7069
" csvList = []\n",
7170
" parameterGrid = getParameterGrid(parameterDict)\n",
72-
" folderName = \"IntradayData_2018\"\n",
71+
" folderName = \"NIFTY50_APR2019\"\n",
7372
" df, dateList = preProcessData(folderName, stockName, [], [], 'blah')\n",
7473
" parameterGridSize = len(parameterGrid)\n",
7574
" print('param combination = ' , parameterGridSize)\n",
@@ -94,7 +93,7 @@
9493
},
9594
{
9695
"cell_type": "code",
97-
"execution_count": 29,
96+
"execution_count": 43,
9897
"metadata": {},
9998
"outputs": [],
10099
"source": [
@@ -105,6 +104,9 @@
105104
"def getRenkoParameterDict():\n",
106105
" brickHeightPercentage = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3]\n",
107106
" stepCount = [3,4,5,7]\n",
107+
"# brickHeightPercentage = [0.1]\n",
108+
"# stepCount = [3]\n",
109+
"\n",
108110
" parameterDict = {\n",
109111
" 'brickHeightPercentage' : brickHeightPercentage, \n",
110112
" 'stepCount': stepCount\n",
@@ -114,16 +116,17 @@
114116
},
115117
{
116118
"cell_type": "code",
117-
"execution_count": 30,
119+
"execution_count": 44,
118120
"metadata": {},
119121
"outputs": [],
120122
"source": [
121-
"stockList = futuresList"
123+
"# stockList = futuresList\n",
124+
"stockList= ['RELIANCE']"
122125
]
123126
},
124127
{
125128
"cell_type": "code",
126-
"execution_count": 28,
129+
"execution_count": 45,
127130
"metadata": {
128131
"scrolled": false
129132
},
@@ -132,11 +135,33 @@
132135
"name": "stdout",
133136
"output_type": "stream",
134137
"text": [
135-
"('param combination = ', 1)\n",
136-
"-31.373428498947497\n",
137-
"Stock Name: INFRATEL_F1, brickHeightPercentage: 0.01, stepCount: 3, ProfitPer: -31.3734284989\n",
138-
"('Time - ', 13.298845052719116)\n",
139-
"(1, 1)\n"
138+
"('param combination = ', 24)\n",
139+
"Stock Name: RELIANCE, brickHeightPercentage: 0.05, stepCount: 3, ProfitPer: 10.8800270526\n",
140+
"Stock Name: RELIANCE, brickHeightPercentage: 0.05, stepCount: 4, ProfitPer: 11.1136777732\n",
141+
"Stock Name: RELIANCE, brickHeightPercentage: 0.05, stepCount: 7, ProfitPer: 8.17639153333\n",
142+
"Stock Name: RELIANCE, brickHeightPercentage: 0.05, stepCount: 5, ProfitPer: 8.17698244068\n",
143+
"Stock Name: RELIANCE, brickHeightPercentage: 0.1, stepCount: 3, ProfitPer: 3.16982711066\n",
144+
"Stock Name: RELIANCE, brickHeightPercentage: 0.1, stepCount: 4, ProfitPer: 2.99321250018\n",
145+
"Stock Name: RELIANCE, brickHeightPercentage: 0.1, stepCount: 5, ProfitPer: 3.673524544\n",
146+
"Stock Name: RELIANCE, brickHeightPercentage: 0.15, stepCount: 3, ProfitPer: 0.656039089039\n",
147+
"Stock Name: RELIANCE, brickHeightPercentage: 0.1, stepCount: 7, ProfitPer: 5.37036767574\n",
148+
"Stock Name: RELIANCE, brickHeightPercentage: 0.15, stepCount: 4, ProfitPer: 1.34306333272\n",
149+
"Stock Name: RELIANCE, brickHeightPercentage: 0.2, stepCount: 3, ProfitPer: 2.6812010044\n",
150+
"Stock Name: RELIANCE, brickHeightPercentage: 0.25, stepCount: 3, ProfitPer: 0.949150597136\n",
151+
"Stock Name: RELIANCE, brickHeightPercentage: 0.3, stepCount: 4, ProfitPer: 1.3982007996\n",
152+
"Stock Name: RELIANCE, brickHeightPercentage: 0.25, stepCount: 4, ProfitPer: -1.55801819262\n",
153+
"Stock Name: RELIANCE, brickHeightPercentage: 0.3, stepCount: 5, ProfitPer: -1.85965765906\n",
154+
"Stock Name: RELIANCE, brickHeightPercentage: 0.2, stepCount: 4, ProfitPer: 1.32914882046\n",
155+
"Stock Name: RELIANCE, brickHeightPercentage: 0.3, stepCount: 3, ProfitPer: -0.342861582287\n",
156+
"Stock Name: RELIANCE, brickHeightPercentage: 0.15, stepCount: 5, ProfitPer: 1.99747764747\n",
157+
"Stock Name: RELIANCE, brickHeightPercentage: 0.2, stepCount: 5, ProfitPer: 0.22987113645\n",
158+
"Stock Name: RELIANCE, brickHeightPercentage: 0.25, stepCount: 5, ProfitPer: -0.0522027992085\n",
159+
"Stock Name: RELIANCE, brickHeightPercentage: 0.2, stepCount: 7, ProfitPer: 2.02072316558\n",
160+
"Stock Name: RELIANCE, brickHeightPercentage: 0.25, stepCount: 7, ProfitPer: -0.394424572498\n",
161+
"Stock Name: RELIANCE, brickHeightPercentage: 0.3, stepCount: 7, ProfitPer: -2.27922991042\n",
162+
"Stock Name: RELIANCE, brickHeightPercentage: 0.15, stepCount: 7, ProfitPer: 0.62004189417\n",
163+
"('Time - ', 8.692453145980835)\n",
164+
"(24, 24)\n"
140165
]
141166
}
142167
],

eom_renko_multiStock.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# coding: utf-8
33

4-
# In[23]:
4+
# In[37]:
55

66

77
import time
@@ -20,7 +20,7 @@
2020
# import copy
2121

2222

23-
# In[24]:
23+
# In[38]:
2424

2525

2626
def getSellEndOfDay(currentDate, stockType):
@@ -38,26 +38,25 @@ def renkoExperiment(paramList, stockType = 'FUTURES', verbose=False):
3838
for date in dateList:
3939
new_df = df[(df.date == date)]
4040
day = renkoScript(new_df, paramEntry, newDay, renkoDeque, stockType, verbose)
41-
if verbose:
42-
print(date, newDay.money, day.money, day.dailyTrades)
43-
day.printOpenTrade()
41+
# if verbose:
42+
# print(date, newDay.money, day.money, day.dailyTrades)
43+
# day.printOpenTrade()
4444
sellEndOfDay = getSellEndOfDay(date, stockType)
4545
newDay = day.initializeNextDay(sellEndOfDay)
4646
yearlyProfitPercentage = (day.money - 1) * 100
47-
print(yearlyProfitPercentage)
4847
paramEntry.profitPercentage = yearlyProfitPercentage
4948
paramEntry.toString()
5049

5150
return paramEntry
5251

5352

54-
# In[25]:
53+
# In[39]:
5554

5655

5756
def bruteAnalysis(stockName, parameterDict, pool, threadPoolSize):
5857
csvList = []
5958
parameterGrid = getParameterGrid(parameterDict)
60-
folderName = "IntradayData_2018"
59+
folderName = "NIFTY50_APR2019"
6160
df, dateList = preProcessData(folderName, stockName, [], [], 'blah')
6261
parameterGridSize = len(parameterGrid)
6362
print('param combination = ' , parameterGridSize)
@@ -80,7 +79,7 @@ def bruteAnalysis(stockName, parameterDict, pool, threadPoolSize):
8079
return csvList
8180

8281

83-
# In[29]:
82+
# In[43]:
8483

8584

8685
def getParameterGrid(parameterDict):
@@ -90,20 +89,24 @@ def getParameterGrid(parameterDict):
9089
def getRenkoParameterDict():
9190
brickHeightPercentage = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3]
9291
stepCount = [3,4,5,7]
92+
# brickHeightPercentage = [0.1]
93+
# stepCount = [3]
94+
9395
parameterDict = {
9496
'brickHeightPercentage' : brickHeightPercentage,
9597
'stepCount': stepCount
9698
}
9799
return parameterDict
98100

99101

100-
# In[30]:
102+
# In[44]:
101103

102104

103-
stockList = futuresList
105+
# stockList = futuresList
106+
stockList= ['RELIANCE']
104107

105108

106-
# In[28]:
109+
# In[45]:
107110

108111

109112
threadPoolSize = 24

scripts/dayScript.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def dayScript(df, param, day, stockType, verbose = False):
5757

5858
def getNewRenko(lastRenko, minute, brickHeight):
5959
if minute.high > lastRenko.high + brickHeight:
60-
renko = Renko(lastRenko.high, lastRenko.high + brickHeight)
60+
renko = Renko(lastRenko.high, lastRenko.high + brickHeight, 1)
6161
elif minute.low < lastRenko.low - brickHeight:
62-
renko = Renko(lastRenko.low - brickHeight, lastRenko.low)
62+
renko = Renko(lastRenko.low - brickHeight, lastRenko.low, -1)
6363
else:
6464
return None
6565
return renko
@@ -73,11 +73,12 @@ def printRenkoDeque(renkoDeque):
7373
print('empty')
7474

7575

76-
def generateRenko(minute, renkoDeque, brickHeight, stepCount):
76+
def generateRenko(minute, renkoDeque, brickHeight, stepCount, verbose):
7777
# import pdb;pdb.set_trace()
7878
size = len(renkoDeque)
7979
if size == 0:
80-
newRenko = Renko(minute.openingPrice, minute.openingPrice)
80+
newRenko = Renko(minute.openingPrice, minute.openingPrice, 0)
81+
newRenko.toString(verbose)
8182
renkoDeque.append(newRenko)
8283
else:
8384
lastRenko = renkoDeque[-1]
@@ -86,6 +87,7 @@ def generateRenko(minute, renkoDeque, brickHeight, stepCount):
8687
if size == stepCount:
8788
renkoDeque.popleft()
8889
renkoDeque.append(newRenko)
90+
newRenko.toString(verbose)
8991
return renkoDeque
9092

9193
def getEmotion(renkoDeque):
@@ -109,7 +111,8 @@ def renkoScript(df, param, day, renkoDeque, stockType, verbose = False):
109111
marketOpen, marketClose = getMarketDetails(stockType)
110112
for row in df.iterrows():
111113
minute = Minute(row)
112-
renkoDeque = generateRenko(minute, renkoDeque, param.brickHeight, param.stepCount)
114+
minute.toString(verbose)
115+
renkoDeque = generateRenko(minute, renkoDeque, param.brickHeight, param.stepCount, verbose)
113116
if len(renkoDeque) == param.stepCount:
114117
if marketOpen <= minute.time < marketClose:
115118
if day.boughtFlag == 0:

0 commit comments

Comments
 (0)