| Overall Statistics |
|
Total Trades 205 Average Win 2.50% Average Loss -3.19% Compounding Annual Return 13.178% Drawdown 30.700% Expectancy 0.103 Net Profit 28.137% Sharpe Ratio 0.455 Probabilistic Sharpe Ratio 17.701% Loss Rate 38% Win Rate 62% Profit-Loss Ratio 0.79 Alpha 0.117 Beta 0.047 Annual Standard Deviation 0.266 Annual Variance 0.071 Information Ratio 0.128 Tracking Error 0.288 Treynor Ratio 2.595 Total Fees $0.00 |
import numpy as np
### <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):
self.SetStartDate(2017,7, 31) #Set Start Date
self.SetEndDate(2019,7,31) #Set End Date
self.SetCash(5000) #Set Strategy Cash
#This algorithm trades EURGBP on the Hour Resolution
self.AddForex("EURGBP", Resolution.Hour, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
#We add our RSI 14 period indicator
self.rsi = self.RSI("EURGBP", 14)
def OnData(self, data):
#Make sure our indicator is ready before we can use it
if not self.rsi.IsReady:
return
#If RSI signals oversold
if self.rsi.Current.Value < 30:
#if we are not currently in a trade
if not self.Portfolio["EURGBP"].Invested:
#we place a long market order
self.SetHoldings("EURGBP", 5)
else:
# if we are already in a short trade we liquidate
if self.Portfolio["EURGBP"].IsShort:
self.Liquidate()
#if RSI signals overbought
if self.rsi.Current.Value > 70:
if not self.Portfolio["EURGBP"].Invested:
#enter short position
self.SetHoldings("EURGBP", -5)
else:
#if we already in a long trade we liquidate
if self.Portfolio["EURGBP"].IsLong:
#We liquidate our position
self.Liquidate()