Overall Statistics |
Total Trades 2 Average Win 0% Average Loss 0.00% Compounding Annual Return 0.001% Drawdown 0.000% Expectancy -1 Net Profit 0.000% Sharpe Ratio 0.015 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.006 Beta 0.525 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -25.523 Tracking Error 0 Treynor Ratio 0 Total Fees $17.28 |
import numpy as np class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2013,10, 7) #Set Start Date self.SetEndDate(2013,10,11) #Set End Date self.SetCash(10000000) #Set Strategy Cash self.AddForex("EURUSD", Resolution.Second, Market.Oanda) self.Securities['EURUSD'].SetSlippageModel(CustomSlippageModel(self)) self.Securities['EURUSD'].SetFeeModel(CustomFeeModel(self)) def OnData(self, data): if not self.Portfolio.Invested: self.MarketOrder('EURUSD', -102000) self.MarketOrder('EURUSD', 42000) class CustomFeeModel(FeeModel): def __init__(self, algorithm): self.algorithm = algorithm def GetOrderFee(self, parameters): # custom fee math if parameters.Order.Quantity > 0: ## Buy order spread cost --> Ask - Mid spread_cost = (parameters.Security.AskPrice - parameters.Security.Price) * parameters.Order.AbsoluteQuantity else: ## Sell order spread cost --> Mid - Bid spread_cost = (parameters.Security.Price - parameters.Security.BidPrice) * parameters.Order.AbsoluteQuantity commission_fee = (parameters.Order.AbsoluteQuantity/100000) * 5.00 ## Assuming account is in USD fee = spread_cost + commission_fee self.algorithm.Log("CustomFeeModel: " + str(fee)) return OrderFee(CashAmount(fee, "USD")) class CustomSlippageModel: def __init__(self, algorithm): self.algorithm = algorithm def GetSlippageApproximation(self, asset, order): # custom slippage math slippage = asset.BidPrice * (0.0001 * np.log10(2*float(order.AbsoluteQuantity))) ## Uses midpoint (asset.Close) self.algorithm.Log("CustomSlippageModel: " + str(slippage)) return slippage