def raw_futures_roll(self, instrument_code): """ Returns the raw difference between price and carry :param instrument_code: instrument to get data for :type instrument_code: str :returns: Tx4 pd.DataFrame >>> from systems.tests.testfuturesrawdata import get_test_object_futures >>> from systems.basesystem import System >>> (data, config)=get_test_object_futures() >>> system=System([FuturesRawData()], data) >>> system.rawdata.raw_futures_roll("EDOLLAR").ffill().tail(2) 2015-12-11 17:08:14 -0.07 2015-12-11 19:33:39 -0.07 dtype: float64 """ carrydata = self.get_instrument_raw_carry_data(instrument_code) raw_roll = carrydata.PRICE - carrydata.CARRY raw_roll[raw_roll == 0] = np.nan raw_roll = uniquets(raw_roll) return raw_roll
def roll_differentials(self, instrument_code): """ Work out the annualisation factor :param instrument_code: instrument to get data for :type instrument_code: str :returns: Tx4 pd.DataFrame >>> from systems.tests.testfuturesrawdata import get_test_object_futures >>> from systems.basesystem import System >>> (data, config)=get_test_object_futures() >>> system=System([FuturesRawData()], data) >>> system.rawdata.roll_differentials("EDOLLAR").ffill().tail(2) 2015-12-11 17:08:14 -0.246407 2015-12-11 19:33:39 -0.246407 dtype: float64 """ carrydata = self.get_instrument_raw_carry_data(instrument_code) roll_diff = carrydata.apply( fraction_of_year_between_price_and_carry_expiries, floor_date_diff=1, axis=1) roll_diff = uniquets(roll_diff) return roll_diff
def roll_differentials(self, floor_date_diff: float = 1/CALENDAR_DAYS_IN_YEAR)\ -> pd.Series: raw_differential = self.raw_differential() floored_differential = apply_abs_min(raw_differential, floor_date_diff) unique_differential = uniquets(floored_differential) return unique_differential
def _calc_roll_differentials(system, instrument_code, this_stage): carrydata = this_stage.get_instrument_raw_carry_data(instrument_code) roll_diff = carrydata.apply(expiry_diff, 1) roll_diff = uniquets(roll_diff) return roll_diff
def _calc_roll_differentials(system, instrument_code, this_stage): carrydata = this_stage.get_instrument_raw_carry_data( instrument_code) roll_diff = carrydata.apply(expiry_diff, 1) roll_diff = uniquets(roll_diff) return roll_diff
def raw_futures_roll(self) -> pd.Series: raw_roll = self.price - self.carry raw_roll[raw_roll == 0] = np.nan raw_roll = uniquets(raw_roll) return raw_roll
def _calc_raw_futures_roll(system, instrument_code, this_stage): carrydata = this_stage.get_instrument_raw_carry_data(instrument_code) raw_roll = carrydata.PRICE - carrydata.CARRY raw_roll[raw_roll == 0] = np.nan raw_roll = uniquets(raw_roll) return raw_roll
def _calc_raw_futures_roll(system, instrument_code, this_stage): carrydata = this_stage.get_instrument_raw_carry_data( instrument_code) raw_roll = carrydata.PRICE - carrydata.CARRY raw_roll[raw_roll == 0] = np.nan raw_roll=uniquets(raw_roll) return raw_roll
def costs_pandl_in_instrument_currency(self) -> pd.Series: instrument_currency_costs_as_list = ( self.costs_from_trading_in_instrument_currency_as_list()) date_index = self.date_index_for_all_fills() costs_as_pd_series = pd.Series(instrument_currency_costs_as_list, date_index) costs_as_pd_series = costs_as_pd_series.sort_index() costs_as_pd_series = uniquets(costs_as_pd_series) normalised_costs = self.normalise_costs_in_instrument_currency( costs_as_pd_series) return normalised_costs
def _get_filtered_forecast( system, instrument_code, rule_variation_name, this_stage): raw_forecast = this_stage.get_actual_raw_forecast( instrument_code, rule_variation_name) (fit_dates, filter_data)=this_stage.get_fitted_values(instrument_code, rule_variation_name) filtered_list=[] for (fit_period, data_this_period) in zip(fit_dates, filter_data): (x_bins, fit_y)=data_this_period filtered_list.append(filtering_function(raw_forecast, startdate=fit_period.period_start, enddate=fit_period.period_end, x_bins=x_bins, fit_y=fit_y)) filtered_forecast=pd.concat(filtered_list, axis=0) return uniquets(filtered_forecast)
def roll_differentials(self, instrument_code): """ Work out the annualisation factor :param instrument_code: instrument to get data for :type instrument_code: str :returns: Tx4 pd.DataFrame >>> from systems.tests.testfuturesrawdata import get_test_object_futures >>> from systems.basesystem import System >>> (data, config)=get_test_object_futures() >>> system=System([FuturesRawData()], data) >>> system.rawdata.roll_differentials("EDOLLAR").ffill().tail(2) 2015-12-11 17:08:14 -0.246407 2015-12-11 19:33:39 -0.246407 dtype: float64 """ carrydata = self.get_instrument_raw_carry_data(instrument_code) roll_diff = carrydata.apply(expiry_diff, 1) roll_diff = uniquets(roll_diff) return roll_diff
def get_capital_pd_series_for_strategy(self, strategy_name: str) -> pd.Series: capital_series = self.get_capital_series_for_strategy(strategy_name) pd_series = capital_series.as_pd_df() pd_series = uniquets(pd_series).squeeze() return pd_series