| Overall Statistics |
|
Total Trades 195 Average Win 11.67% Average Loss -3.44% Compounding Annual Return 20.379% Drawdown 47.500% Expectancy 0.360 Net Profit 140.245% Sharpe Ratio 0.571 Loss Rate 69% Win Rate 31% Profit-Loss Ratio 3.40 Alpha 0.333 Beta -6.562 Annual Standard Deviation 0.4 Annual Variance 0.16 Information Ratio 0.531 Tracking Error 0.4 Treynor Ratio -0.035 Total Fees $0.00 |
import numpy as np
from datetime import datetime
import decimal
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2013,10, 7) #Set Start Date
#self.SetEndDate(2016,6,11) #Set End Date
self.SetCash(1000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.forex = self.AddForex("AUDUSD", Resolution.Daily, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.ema = self.EMA("AUDUSD", 30, Resolution.Daily)
self.__previous = datetime.min
self.PlotIndicator("AUDUSD", self.ema)
# self.setBenchmark(SecurityType.Forex, "AUDUSD")
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
# only once per day
if self.__previous.date() == self.Time.date():
return
self.__previous = self.Time
holdings = self.Portfolio["AUDUSD"].Quantity
if holdings == 0:
#initiate new position
if self.ema.Current.Value < data["AUDUSD"].Ask.Close:
self.MarketOrder(self.forex.Symbol, 10000)
#self.LimitOrder(self.forex.Symbol, -10000, data["AUDUSD"].Ask.Close+decimal.Decimal(0.0040))
elif self.ema.Current.Value > data["AUDUSD"].Ask.Close:
self.MarketOrder(self.forex.Symbol, -10000)
#self.LimitOrder(self.forex.Symbol, 10000, data["AUDUSD"].Ask.Close-decimal.Decimal(0.0040))
return
# We have holdings, so determine if we liquidate
# if long and we drop below EMA, close it
if holdings > 0 and self.ema.Current.Value > data["AUDUSD"].Ask.Close:
self.Liquidate()
# if short and we go above EMA, close it
elif holdings < 0 and self.ema.Current.Value < data["AUDUSD"].Ask.Close:
self.Liquidate()