Overall Statistics |
Total Trades 6287 Average Win 0.00% Average Loss 0.00% Compounding Annual Return 3.933% Drawdown 1.000% Expectancy 0.246 Net Profit 0.763% Sharpe Ratio 1.487 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 1.49 Alpha 0.078 Beta -3.004 Annual Standard Deviation 0.021 Annual Variance 0 Information Ratio 0.721 Tracking Error 0.021 Treynor Ratio -0.01 Total Fees $0.00 |
import io, requests import numpy as np import pandas as pd from datetime import timedelta assets = ['AUDUSD', 'EURUSD', 'GBPUSD', 'NZDUSD', 'USDCAD', 'USDCHF', 'USDJPY', 'USDNOK', 'USDSEK', 'USDSGD'] No_Channels = 10 Input_Size = 256 class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2019,1,1) #Set Start Date self.SetEndDate(2019,3,13) #Set End Date self.SetCash(100000) #Set Strategy Cash self.SetBrokerageModel(BrokerageName.OandaBrokerage) for asset in assets: self.AddForex(asset, Resolution.Hour, Market.Oanda, True, 1.0) self.History(512, Resolution.Hour) def OnData(self, data): cc = None for asset in assets: df = self.History([asset], timedelta(14), Resolution.Hour).loc[asset] df = df['bidclose'].resample('1H').interpolate(method='cubic') if asset[-3:] != 'USD': df = 1.0 / df df = np.log((df/df.shift(1)).tail(Input_Size)) cc = df if cc is None else pd.concat([cc, df], axis=1) stdarr = np.exp(cc.abs().quantile(0.25).values) self.Debug(stdarr) X = np.swapaxes(cc.values, 0, 1) data = {'arr': X.reshape(-1).tolist()} response = requests.post('https://rota.serveo.net/test', json=data) try: weights = np.array(response.json()['arr']) except: self.Debug('JSONDecodeError') return #self.Debug(weights) for i, asset in enumerate(assets): ratio = weights[i] if asset[-3:] == 'USD' else (-1.0*weights[i]) #self.SetHoldings(asset, ratio) self.Transactions.CancelOpenOrders(asset) oq = self.CalculateOrderQuantity(asset, ratio) lp = self.Securities[asset].AskPrice * stdarr[i] if oq > 0: lp = self.Securities[asset].BidPrice / stdarr[i] if oq != 0: self.LimitOrder(asset, oq, lp)