| Overall Statistics |
|
Total Orders 131 Average Win 5.12% Average Loss -4.38% Compounding Annual Return -29.012% Drawdown 88.400% Expectancy -0.633 Start Equity 1000000 End Equity 142563.96 Net Profit -85.744% Sharpe Ratio -0.922 Sortino Ratio -0.4 Probabilistic Sharpe Ratio 0.000% Loss Rate 83% Win Rate 17% Profit-Loss Ratio 1.17 Alpha -0.219 Beta 0.022 Annual Standard Deviation 0.236 Annual Variance 0.056 Information Ratio -1.042 Tracking Error 0.292 Treynor Ratio -9.973 Total Fees $323.57 Estimated Strategy Capacity $0 Lowest Capacity Asset PA YVB1F0QVMMKH Portfolio Turnover 2.99% Drawdown Recovery 52 |
# region imports
from AlgorithmImports import *
# endregion
class BasicFutureAlgorithm(QCAlgorithm):
def initialize(self):
self.universe_settings.asynchronous = True
self.set_start_date(2020, 1, 1)
self.set_cash(1_000_000)
self._future = self.add_future(Futures.Metals.PALLADIUM,
extended_market_hours=True,
data_mapping_mode=DataMappingMode.LAST_TRADING_DAY,
data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
contract_depth_offset=0)
self._future.set_filter(0,62)
def on_data(self, data):
if self.portfolio.invested:
return
continuous_trade_bar = data.bars.get(self._future.symbol)
mapped_trade_bar = data.bars.get(self._future.mapped)
self.market_order(self._future.mapped, 1)
# Track events when security changes its ticker allowing algorithm to adapt to these changes.
def on_symbol_changed_events(self, symbol_changed_events):
for symbol, changed_event in symbol_changed_events.items():
old_symbol = changed_event.old_symbol
new_symbol = changed_event.new_symbol
quantity = self.portfolio[old_symbol].quantity
# Rolling over: to liquidate any position of the old mapped contract and switch to the newly mapped contract
tag = f"Rollover - Symbol changed at {self.time}: {old_symbol} -> {new_symbol}"
self.liquidate(old_symbol, tag=tag)
if quantity: self.market_order(new_symbol, quantity, tag=tag)