| Overall Statistics |
|
Total Trades
719
Average Win
0.78%
Average Loss
-1.39%
Compounding Annual Return
6.369%
Drawdown
29.200%
Expectancy
0.285
Net Profit
324.897%
Sharpe Ratio
0.47
Probabilistic Sharpe Ratio
0.094%
Loss Rate
18%
Win Rate
82%
Profit-Loss Ratio
0.56
Alpha
0.032
Beta
0.3
Annual Standard Deviation
0.105
Annual Variance
0.011
Information Ratio
-0.062
Tracking Error
0.147
Treynor Ratio
0.164
Total Fees
$2583.21
Estimated Strategy Capacity
$12000000.00
Lowest Capacity Asset
EFA S79U6IHK5HLX
Portfolio Turnover
1.06%
|
# https://quantpedia.com/strategies/asset-class-trend-following/
#
# Use 5 ETFs (SPY - US stocks, EFA - foreign stocks, IEF - bonds, VNQ - REITs,
# GSG - commodities), equal weight the portfolio. Hold asset class ETF only when
# it is over its 10 month Simple Moving Average, otherwise stay in cash.
#
# QC implementation:
# - SMA with period of 210 days is used.
#region imports
from AlgorithmImports import *
#endregion
class AssetClassTrendFollowing(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2000, 1, 1)
self.SetCash(100000)
self.sma = {}
period = 10 * 21
self.SetWarmUp(period, Resolution.Daily)
self.symbols = ["SPY", "EFA", "IEF", "VNQ", "GSG"]
self.rebalance_flag = False
self.tracked_symbol = None
for symbol in self.symbols:
self.AddEquity(symbol, Resolution.Minute)
self.sma[symbol] = self.SMA(symbol, period, Resolution.Daily)
self.recent_month = -1
def OnData(self, data):
if self.IsWarmingUp: return
if not (self.Time.hour == 9 and self.Time.minute == 31):
return
# rebalance once a month
if self.Time.month == self.recent_month:
return
self.recent_month = self.Time.month
long = [ symbol for symbol in self.symbols if symbol in data and data[symbol] and self.sma[symbol].IsReady and data[symbol].Value > self.sma[symbol].Current.Value ]
# trade execution
invested = [x.Key.Value for x in self.Portfolio if x.Value.Invested]
for symbol in invested:
if symbol not in long:
self.Liquidate(symbol)
for symbol in long:
self.SetHoldings(symbol, 1 / len(long))