Overall Statistics
Total Trades
99
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
-0.169%
Drawdown
0.000%
Expectancy
-0.083
Net Profit
-0.021%
Sharpe Ratio
-2.09
Probabilistic Sharpe Ratio
7.328%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
0.67
Alpha
-0.001
Beta
0.003
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
0.674
Tracking Error
0.171
Treynor Ratio
-0.47
Total Fees
$212.85
Estimated Strategy Capacity
$710000000000.00
Lowest Capacity Asset
ES XKGCMV4QK9VL
#region imports
from datetime import datetime, timedelta
import datetime
from AlgorithmImports import *
import pandas as pd
from io import StringIO
from QuantConnect.Python import *
from QuantConnect.Indicators import RollingWindow

#


#endregion
class RetrospectiveTanButterfly(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 9, 17)  # Set Start Date
        #self.SetEndDate(2022, 9, 24)
        self.SetEndDate(2020, 11, 1)
        self.SetCash(1000000000)  # Set Strategy Cash
        self.symbolData = {}

        self.contract = self.AddFuture(Futures.Indices.SP500EMini , Resolution.Second, extendedMarketHours = False, dataNormalizationMode = DataNormalizationMode.BackwardsRatio, dataMappingMode = DataMappingMode.OpenInterest , contractDepthOffset = 0)
        symbol = self.contract.Symbol
        self.test1 = True
        self.trades_df = []


    def OnData(self, data):
        if self.test1 == True:
            self.test1 = False
            data = self.Download("https://docs.google.com/spreadsheets/d/1NIbICr3S13U1zavi5AxOO9s_4GAg1RRXICn48j17498/export?format=csv")
            rows = []
            
            #self.Log(f'data {data}')
            for row in data.split('\n'):
                rows.append(row.split(','))
            self.trades_df = pd.DataFrame(np.array(rows[1:]),columns=['entry','direction'])
            self.trades_df['direction'] = self.trades_df['direction'].str.strip('\r')
            self.trades_df = self.trades_df.head(100)
            self.Log(f'length of trades df {(self.trades_df)}')


        #loop through entries in google sheet to place them when self.Time matches
        for trade in self.trades_df.itertuples():
            if self.Time.strftime('%y/%m/%d %H:%M:%S') == str(trade.entry):
                self.Log(f'entry here')
                self.MarketOrder(self.contract.Mapped, trade.direction)