| Overall Statistics |
|
Total Orders 105 Average Win 5.34% Average Loss -2.74% Compounding Annual Return 21.716% Drawdown 28.000% Expectancy 0.784 Start Equity 100000 End Equity 267239.85 Net Profit 167.240% Sharpe Ratio 0.746 Sortino Ratio 1.037 Probabilistic Sharpe Ratio 37.252% Loss Rate 40% Win Rate 60% Profit-Loss Ratio 1.95 Alpha 0.11 Beta 0.362 Annual Standard Deviation 0.182 Annual Variance 0.033 Information Ratio 0.337 Tracking Error 0.196 Treynor Ratio 0.374 Total Fees $637.87 Estimated Strategy Capacity $1000.00 Lowest Capacity Asset FLAG VDQK1SCYCW9X Portfolio Turnover 0.54% Drawdown Recovery 449 |
#region imports
from AlgorithmImports import *
#endregion
class PriceEarningsAnamoly(QCAlgorithm):
def initialize(self):
self.set_start_date(self.end_date - timedelta(5*365))
self.set_cash(100000)
self.set_benchmark("SPY")
self.settings.seed_initial_prices = True
# Define some parameters.
self._liquidity_filter_size = 200
self._universe_size = 10
# Add a universe of US Equities.
self._date_rule = self.date_rules.year_start('SPY')
self.universe_settings.schedule.on(self._date_rule)
self._universe = self.add_universe(self._select_assets)
# Add a warm-up period so the algorithm trades on deployment
# instead of waiting for the new year.
self.set_warm_up(timedelta(400))
def _select_assets(self, fundamentals):
# Select the least liquid stocks trading above $5/share.
filtered = [f for f in fundamentals if f.price > 5 and f.has_fundamental_data]
filtered = sorted(filtered, key=lambda x: x.dollar_volume)[:self._liquidity_filter_size]
# Select the subset of stocks with the lowest PE ratios.
filtered = [f for f in filtered if f.valuation_ratios.pe_ratio > 0]
filtered = sorted(filtered, key=lambda x: x.valuation_ratios.pe_ratio)[:self._universe_size]
return [f.symbol for f in filtered]
def on_warmup_finished(self):
# Add a Scheduled Event to rebalance the portfolio yearly.
self.schedule.on(self._date_rule, self.time_rules.at(8, 0), self._rebalance)
# Rebalance today too.
self._rebalance()
def _rebalance(self):
# Form an equal-weighted portfolio.
targets = [PortfolioTarget(symbol, 1/self._universe_size) for symbol in self._universe.selected]
self.set_holdings(targets, True)