Overall Statistics
Total Trades
6
Average Win
0.63%
Average Loss
-0.05%
Compounding Annual Return
6.848%
Drawdown
0.300%
Expectancy
6.357
Net Profit
1.144%
Sharpe Ratio
3.637
Probabilistic Sharpe Ratio
89.892%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
13.71
Alpha
0.047
Beta
-0.027
Annual Standard Deviation
0.012
Annual Variance
0
Information Ratio
-0.17
Tracking Error
0.107
Treynor Ratio
-1.649
Total Fees
$9.12
Estimated Strategy Capacity
$740000000.00
Lowest Capacity Asset
MGC VOFJUCDY9XNH
#region imports
from AlgorithmImports import *
#endregion
from datetime import timedelta
from AlgorithmImports import *


class USFuturesDataAlgorithm(QCAlgorithm):

    def Initialize(self) -> None:
        self.SetStartDate(2013, 12, 20) 
        self.SetEndDate(2014, 2, 20)
        self.SetCash(1000000) 
        
        # Requesting data
        self.mini_gold = self.AddFuture(Futures.Metals.Gold) 
        self.mini_gold.SetFilter(0, 90)
        
        self.micro_gold = self.AddFuture(Futures.Metals.MicroGold) 
        self.micro_gold.SetFilter(0, 90)
        
        self.contract = {self.mini_gold.Symbol: None, self.micro_gold.Symbol: None}
    
    def OnData(self, slice: Slice) -> None:
        for kvp in slice.FutureChains:
            symbol = kvp.Key
            
            if symbol in self.contract:
                chain = kvp.Value
                
                # Select the contract with the greatest open interest
                most_liquid_contract = sorted(chain, key=lambda contract: contract.OpenInterest, reverse=True)[0]
                
                if self.contract[symbol] is None or most_liquid_contract.Symbol != self.contract[symbol].Symbol:
                    if self.contract[symbol] is not None:
                        self.Liquidate(self.contract[symbol].Symbol)
                    self.contract[symbol] = most_liquid_contract
                    
                    if symbol == self.mini_gold.Symbol:
                        self.MarketOrder(self.contract[symbol].Symbol, 1)
                    elif symbol == self.micro_gold.Symbol:
                        self.MarketOrder(self.contract[symbol].Symbol, -1)
                
                
    def OnSecuritiesChanged(self, changes: SecurityChanges) -> None:
        for security in changes.AddedSecurities:
            # Historical data
            history = self.History(security.Symbol, 10, Resolution.Minute)
            
            self.Debug(f"We got {len(history)} from our history request for{security.Symbol.Value} {security.SymbolProperties.Description}")