Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 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()
Exemple #4
0
 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()
Exemple #5
0
 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
Exemple #6
0
 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
Exemple #7
0
 def curve(self, **kw):
     return accountCurve([self], **kw)