Added Python 2.7.x and 3.4.x compatibility to the code. Disabled HTTPS security warning in urllib3 package of 'requests' package.

This commit is contained in:
Michael Halls-Moore
2015-05-11 17:30:28 +01:00
parent 8e74edb4f7
commit a03bc7a1fb
9 changed files with 67 additions and 39 deletions
+6 -3
View File
@@ -1,3 +1,5 @@
from __future__ import print_function
from copy import deepcopy
from decimal import Decimal, getcontext, ROUND_HALF_DOWN
import os
@@ -73,7 +75,7 @@ class Portfolio(object):
out_file = os.path.join(OUTPUT_RESULTS_DIR, filename)
df_equity = pd.DataFrame.from_records(self.equity, index='time')
df_equity.to_csv(out_file)
print "Simulation complete and results exported to %s" % filename
print("Simulation complete and results exported to %s" % filename)
def execute_signal(self, signal_event):
side = signal_event.side
@@ -123,5 +125,6 @@ class Portfolio(object):
order = OrderEvent(currency_pair, units, "market", side)
self.events.put(order)
print "Balance: %0.2f" % self.balance
self.append_equity_row(time, self.balance)
print("Balance: %0.2f" % self.balance)
self.append_equity_row(time, self.balance)
+4 -2
View File
@@ -92,7 +92,8 @@ class Position(object):
self.update_position_price()
# Calculate PnL
pnl = self.calculate_pips() * qh_close * dec_units
return pnl.quantize(Decimal("0.01", ROUND_HALF_DOWN))
getcontext().rounding = ROUND_HALF_DOWN
return pnl.quantize(Decimal("0.01"))
def close_position(self):
ticker_cp = self.ticker.prices[self.currency_pair]
@@ -106,4 +107,5 @@ class Position(object):
self.update_position_price()
# Calculate PnL
pnl = self.calculate_pips() * qh_close * self.units
return pnl.quantize(Decimal("0.01", ROUND_HALF_DOWN))
getcontext().rounding = ROUND_HALF_DOWN
return pnl.quantize(Decimal("0.01"))
+1 -5
View File
@@ -1,4 +1,4 @@
from decimal import Decimal, getcontext
from decimal import Decimal
import unittest
from position import Position
@@ -28,7 +28,6 @@ class TestLongGBPUSDPosition(unittest.TestCase):
denominated currency of GBP, using 2,000 units of GBP/USD.
"""
def setUp(self):
getcontext.prec = 2
home_currency = "GBP"
position_type = "long"
currency_pair = "GBPUSD"
@@ -78,7 +77,6 @@ class TestShortGBPUSDPosition(unittest.TestCase):
denominated currency of GBP, using 2,000 units of GBP/USD.
"""
def setUp(self):
getcontext.prec = 2
home_currency = "GBP"
position_type = "short"
currency_pair = "GBPUSD"
@@ -132,7 +130,6 @@ class TestLongEURUSDPosition(unittest.TestCase):
denominated currency of GBP, using 2,000 units of EUR/USD.
"""
def setUp(self):
getcontext.prec = 2
home_currency = "GBP"
position_type = "long"
currency_pair = "EURUSD"
@@ -183,7 +180,6 @@ class TestLongEURUSDPosition(unittest.TestCase):
denominated currency of GBP, using 2,000 units of EUR/USD.
"""
def setUp(self):
getcontext.prec = 2
home_currency = "GBP"
position_type = "short"
currency_pair = "EURUSD"