def curve(self, **kw): """ Returns an AccountCurve for this Portfolio. """ kw2={'portfolio_weights': self.valid_weights()} kw2.update(kw) return accountCurve(list(self.valid_instruments().values()), **kw2)
def curve(self, **kw): """ Returns an AccountCurve for this Portfolio. """ kw2 = {'portfolio_weights': self.valid_weights()} kw2.update(kw) return accountCurve(list(self.valid_instruments().values()), **kw2)
def forecast_returns(self, **kw): """ Estimated returns for individual trading rules """ f = self.forecasts(**kw) positions = self.position(forecasts=f).dropna() curves = positions.apply(lambda x: accountCurve([self], positions=x, panama_prices = self.panama_prices())) return curves.apply(lambda x: x.returns()[self.name]).transpose()
def bootstrap(self, **kw): """ Optimize rule weights using bootstrapping """ import trading.bootstrap print("Bootstrap", self.name, "starting") result = trading.bootstrap.bootstrap(self, **kw) self.bootstrapped_weights = result.mean() print(accountCurve([self], positions=self.position(forecasts=weight_forecast( self.forecasts(), result.mean())), panama_prices=self.panama_prices())) return result.mean()
def function(w, instrument, sample): """This is the function that is minimized iteratively using scipy.optimize.minimize to find the best weights (w)""" wf = weight_forecast(sample, w) # We introduce a capital term, as certain currencies like HKD are very 'numerate', which means we need millions of HKD to get a # significant position position = instrument.position(forecasts = wf, nofx=True, capital=10E7).rename(instrument.name).to_frame().dropna() # position = instrument.position(forecasts = wf, nofx=True).rename(instrument.name).to_frame().dropna() l = accountCurve([instrument], positions = position, panama_prices=instrument.panama_prices().dropna(), nofx=True) s = l.sortino() try: assert np.isnan(s) == False except: print(sample, position) raise return -s
def function(w, instrument, sample): """This is the function that is minimized iteratively using scipy.optimize.minimize to find the best weights (w)""" wf = weight_forecast(sample, w) # We introduce a capital term, as certain currencies like HKD are very 'numerate', which means we need millions of HKD to get a # significant position position = instrument.position( forecasts=wf, nofx=True, capital=10E7).rename(instrument.name).to_frame().dropna() # position = instrument.position(forecasts = wf, nofx=True).rename(instrument.name).to_frame().dropna() l = accountCurve([instrument], positions=position, panama_prices=instrument.panama_prices().dropna(), nofx=True) s = l.sortino() try: assert np.isnan(s) == False except: print(sample, position) raise return -s
def curve(self, **kw): return accountCurve([self], **kw)