forked from arikaufman/algorithmicTrading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (30 loc) · 1.38 KB
/
main.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
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import backtrader as bt
import strategies.PairsTradingStrategy as Pairs
import common.AnalyzerSuite as AnalyzerSuite
import common.DataCollection as DataCollection
if __name__ == '__main__':
# ------------------------------------------------------------------------------------
# Create a cerebro entity
cerebro = bt.Cerebro()
# Add a strategy
cerebro.addstrategy(Pairs.PairsTradingStrategy)
DataCollection.DataCollection.collectData(DataCollection, cerebro)
# Set our desired cash start
cerebro.broker.setcash(100000.0)
# Set the commission
#cerebro.broker.setcommission(commission=0.001)
# ------------------------------------------------------------------------------------
# Print out the starting conditions
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
# Analyzer
AnalyzerSuite.AnalyzerSuite.defineAnalyzers(AnalyzerSuite, cerebro)
# Run over everything
thestrats = cerebro.run(stdstats=True)
# -----------------------------------------------------------------------------------
print(AnalyzerSuite.AnalyzerSuite.returnAnalyzers(AnalyzerSuite, thestrats))
# Print out the final result
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
# Plot the result
cerebro.plot()