-
Notifications
You must be signed in to change notification settings - Fork 0
/
backTest.py
53 lines (38 loc) · 1.59 KB
/
backTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy
from prettytable import PrettyTable
from crypto import Crypto
from strategies import RsiBasic, RsiParabolic
def calcGain(start, end):
return ((end - start) / start) * 100
# data = numpy.genfromtxt(
# './historical/2020_01_01-2021-02-07.csv', delimiter=',')
# data = numpy.genfromtxt(
# './historical/2020_01_01-2020-02-01.csv', delimiter=',')
# data = numpy.genfromtxt('./historical/1month30min.csv', delimiter=',')
data = numpy.genfromtxt('./historical/1month5min.csv', delimiter=',')
closePrices = data[:, 4]
crypto = Crypto()
for close in closePrices:
crypto.addClose(float(close))
RsiBasic(crypto, close)
# RsiParabolic(crypto, close)
# If still in position, sell.
if (crypto.position):
crypto.sell(float(data[len(data) - 1, 4]))
startMarketPrice = data[0, 4]
endMarketPrice = data[len(data) - 1, 4]
marketPercentage = calcGain(startMarketPrice, endMarketPrice)
balancePercentage = calcGain(crypto.startBalance, crypto.balance)
t = PrettyTable(['', 'Start Price', 'End Price', '%'])
t.add_row(['Market', round(startMarketPrice, 2), round(endMarketPrice, 2),
(round(marketPercentage, 2))])
t.add_row(['Balance', round(crypto.startBalance, 2), round(crypto.balance, 2),
(round(balancePercentage, 2))])
t.add_row(['', '', '', ''])
t.add_row(['', 'Num Trades', 'Cost', ''])
t.add_row(['', crypto.numTrades, crypto.tradeCost, ''])
t.add_row(['', '', '', ''])
balanceWithFees = round(crypto.balance, 2) - round(crypto.tradeCost, 2)
t.add_row(['Balance', '', balanceWithFees, round(
calcGain(crypto.startBalance, balanceWithFees), 2)])
print(t)