Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pair-trading.py #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions contrib/samples/pair-trading/pair-trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def next(self):
print('y + self.qty2 is', y + self.qty2)

# Placing the order
self.log('SELL CREATE %s, price = %.2f, qty = %d' % ("PEP", self.data0.close[0], x + self.qty1))
self.log('SELL CREATE %s, price = %.2f, qty = %d' % (self.data0._name, self.data0.close[0], x + self.qty1))
self.sell(data=self.data0, size=(x + self.qty1)) # Place an order for buying y + qty2 shares
self.log('BUY CREATE %s, price = %.2f, qty = %d' % ("KO", self.data1.close[0], y + self.qty2))
self.log('BUY CREATE %s, price = %.2f, qty = %d' % (self.data1._name, self.data1.close[0], y + self.qty2))
self.buy(data=self.data1, size=(y + self.qty2)) # Place an order for selling x + qty1 shares

# Updating the counters with new value
Expand All @@ -132,9 +132,9 @@ def next(self):
print('y + self.qty2 is', y + self.qty2)

# Place the order
self.log('BUY CREATE %s, price = %.2f, qty = %d' % ("PEP", self.data0.close[0], x + self.qty1))
self.log('BUY CREATE %s, price = %.2f, qty = %d' % (self.data0._name, self.data0.close[0], x + self.qty1))
self.buy(data=self.data0, size=(x + self.qty1)) # Place an order for buying x + qty1 shares
self.log('SELL CREATE %s, price = %.2f, qty = %d' % ("KO", self.data1.close[0], y + self.qty2))
self.log('SELL CREATE %s, price = %.2f, qty = %d' % (self.data1._name, self.data1.close[0], y + self.qty2))
self.sell(data=self.data1, size=(y + self.qty2)) # Place an order for selling y + qty2 shares

# Updating the counters with new value
Expand Down Expand Up @@ -177,7 +177,7 @@ def runstrategy():
todate=todate)

# Add the 1st data to cerebro
cerebro.adddata(data0)
cerebro.adddata(data0, name="PEP")

# Create the 2nd data
data1 = btfeeds.YahooFinanceCSVData(
Expand All @@ -186,7 +186,7 @@ def runstrategy():
todate=todate)

# Add the 2nd data to cerebro
cerebro.adddata(data1)
cerebro.adddata(data1, name="KO")

# Add the strategy
cerebro.addstrategy(PairTradingStrategy,
Expand Down