-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55bb032
commit 3cfb1ee
Showing
8 changed files
with
68 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pyBacktest.tradeTypes import InvalidCommissionTypeError | ||
|
||
def calculate_commission(commisionType: str, commision: float, price: float, numShares: int) -> float: | ||
if commisionType == "FLAT": | ||
return commision | ||
elif commisionType == "PERCENTAGE": | ||
return price * commision * numShares | ||
elif commisionType == "PERCENTAGE_PER_SHARE": | ||
return commision * numShares | ||
elif commisionType == "PER_SHARE": | ||
return commision * numShares | ||
else: | ||
raise InvalidCommissionTypeError(f"Invalid commission type: {commisionType}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pyBacktest.tradeTypes import TradeType, Order, Transaction | ||
from datetime import datetime | ||
|
||
def cancel_order(backtest, order_index: int) -> bool: | ||
if 0 <= order_index < len(backtest.pending_orders): | ||
order = backtest.pending_orders[order_index] | ||
order.active = False | ||
backtest.transactions.append( | ||
Transaction( | ||
tradeType=TradeType.Cancel, | ||
ticker=order.ticker, | ||
commission=0, | ||
executedSuccessfully=True, | ||
numShares=order.numShares, | ||
pricePerShare=order.targetPrice, | ||
totalCost=0, | ||
date=backtest.date, | ||
notes="Order canceled" | ||
) | ||
) | ||
return True | ||
return False | ||
|
||
def submit_gtc_order(backtest, tradeType: TradeType, numShares: int, targetPrice: float) -> Order: | ||
order = Order( | ||
tradeType=tradeType, | ||
ticker=backtest.ticker, | ||
numShares=numShares, | ||
targetPrice=targetPrice, | ||
duration='GTC', | ||
orderDate=backtest.date | ||
) | ||
backtest.pending_orders.append(order) | ||
return order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters