| Overall Statistics |
|
Total Trades 721 Average Win 4.95% Average Loss 0.85% Compounding Annual Return -35.377% Drawdown 73.800% Expectancy 1.356 Net Profit -58.328% Sharpe Ratio -0.378 Probabilistic Sharpe Ratio 0.796% Loss Rate 65% Win Rate 35% Profit-Loss Ratio 5.81 Alpha -0.177 Beta 0.047 Annual Standard Deviation 0.464 Annual Variance 0.215 Information Ratio -0.262 Tracking Error 0.809 Treynor Ratio -3.697 Total Fees $94736.14 Estimated Strategy Capacity $1100000.00 Lowest Capacity Asset BTCUSD E3 |
from tensorflow.keras.models import Sequential
import json
class SmoothSkyBlueMosquito(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 1, 1) # Set Start Date
self.SetEndDate(2020, 1, 1) # Set Start Date
model_key = 'bitcoing_price_predictor'
if self.ObjectStore.ContainsKey(model_key):
model_str = self.ObjectStore.Read(model_key)
config = json.loads(model_str)['config']
self.model = Sequential.from_config(config)
self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin) # crypto brokerage
self.SetCash(100000) # Set Strategy Cash
self.symbol = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
# self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
self.SetBenchmark(self.symbol)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
if self.GetPrediction() == "Up":
self.SetHoldings(self.symbol, 1)
else:
self.SetHoldings(self.symbol, -0.5)
def GetPrediction(self):
# instead of history requests, use rolling window for more efficiency
df = self.History(self.symbol, 40).loc[self.symbol]
df_change = df[["close", "open", "high", "low", "volume"]].pct_change().dropna()
model_input = []
for index, row in df_change.tail(30).iterrows():
model_input.append(np.array(row))
model_input = np.array([model_input])
if round(self.model.predict(model_input)[0][0]) == 0:
return "Up"
else:
return "Down"