def _pandl_for_subsystem_with_cash_costs( self, instrument_code, delayfill=True, roundpositions=True) -> accountCurve: if not roundpositions: self.log.warn( "Using roundpositions=False with cash costs may lead to inaccurate costs (fixed costs, eg commissions will be overstated!!!" ) raw_costs = self.get_raw_cost_data(instrument_code) price = self.get_daily_price(instrument_code) positions = self.get_subsystem_position(instrument_code) fx = self.get_fx_rate(instrument_code) value_of_price_point = self.get_value_of_block_price_move( instrument_code) capital = self.get_notional_capital() pandl_calculator = pandlCalculationWithCashCostsAndFills( price, raw_costs=raw_costs, positions=positions, capital=capital, value_per_point=value_of_price_point, delayfill=delayfill, fx=fx, roundpositions=roundpositions) account_curve = accountCurve(pandl_calculator) return account_curve
def pandl_for_instrument_forecast( forecast: pd.Series, price: pd.Series, daily_returns_volatility: pd.Series = arg_not_supplied, target_abs_forecast: float = 10.0, SR_cost=0.0, delayfill=True) -> accountCurve: if daily_returns_volatility is arg_not_supplied: daily_returns_volatility = robust_daily_vol_given_price(price) normalised_forecast = _get_normalised_forecast( forecast, target_abs_forecast=target_abs_forecast) average_notional_position = -_get_average_notional_position( daily_returns_volatility) notional_position = _get_notional_position_for_forecast( normalised_forecast, average_notional_position=average_notional_position) pandl_calculator = pandlCalculationWithSRCosts( price, SR_cost=SR_cost, positions=notional_position, daily_returns_volatility=daily_returns_volatility, average_position=average_notional_position, capital=ARBITRARY_FORECAST_CAPITAL, value_per_point=ARBITRARY_VALUE_OF_PRICE_POINT, delayfill=delayfill) account_curve = accountCurve(pandl_calculator) return account_curve
def account_curve_for_asset(self, asset_name: str, account_curve_group: 'accountCurveGroup' = arg_not_supplied, freq_str: str = "daily", curve_type_str = "net", is_percentage = True ) -> accountCurve: if account_curve_group is arg_not_supplied: account_curve_group = self.account_curve_group frequency = _from_freq_str_to_frequency(freq_str) curve_type = _from_curve_str_to_curve_type(curve_type_str) account_curve = accountCurve(account_curve_group.get_pandl_calculator_for_item(asset_name), curve_type=curve_type, is_percentage= is_percentage, frequency=frequency) return account_curve
def _pandl_for_instrument_with_SR_costs( self, instrument_code: str, delayfill: bool = True, roundpositions: bool = True) -> accountCurve: price = self.get_daily_price(instrument_code) positions = self.get_buffered_position(instrument_code, roundpositions=roundpositions) fx = self.get_fx_rate(instrument_code) value_of_price_point = self.get_value_of_block_price_move( instrument_code) daily_returns_volatility = self.get_daily_returns_volatility( instrument_code) capital = self.get_notional_capital() SR_cost_per_trade = self.get_SR_cost_per_trade_for_instrument( instrument_code) instrument_turnover = self.instrument_turnover( instrument_code, roundpositions=roundpositions) annualised_SR_cost = SR_cost_per_trade * instrument_turnover average_position = self.get_average_position_for_instrument_at_portfolio_level( instrument_code) pandl_calculator = pandlCalculationWithSRCosts( price, SR_cost=annualised_SR_cost, positions=positions, average_position=average_position, daily_returns_volatility=daily_returns_volatility, capital=capital, value_per_point=value_of_price_point, delayfill=delayfill, fx=fx, roundpositions=roundpositions) account_curve = accountCurve(pandl_calculator, weighted=True) return account_curve
def _pandl_for_instrument_with_cash_costs( self, instrument_code: str, positions: pd.Series, delayfill: bool = True, roundpositions: bool = True, ) -> accountCurve: if not roundpositions: self.log.warn( "Using roundpositions=False with cash costs may lead to inaccurate costs (fixed costs, eg commissions will be overstated!!!" ) raw_costs = self.get_raw_cost_data(instrument_code) price = self.get_daily_price(instrument_code) fx = self.get_fx_rate(instrument_code) value_of_price_point = self.get_value_of_block_price_move( instrument_code) capital = self.get_notional_capital() vol_normalise_currency_costs = self.config.vol_normalise_currency_costs rolls_per_year = self.get_rolls_per_year(instrument_code) pandl_calculator = pandlCalculationWithCashCostsAndFills( price, raw_costs=raw_costs, positions=positions, capital=capital, value_per_point=value_of_price_point, delayfill=delayfill, fx=fx, roundpositions=roundpositions, vol_normalise_currency_costs=vol_normalise_currency_costs, rolls_per_year=rolls_per_year, ) account_curve = accountCurve(pandl_calculator, weighted=True) return account_curve
def _pandl_for_subsystem_with_SR_costs( self, instrument_code, delayfill=True, roundpositions=False) -> accountCurve: price = self.get_daily_price(instrument_code) positions = self.get_subsystem_position(instrument_code) fx = self.get_fx_rate(instrument_code) value_of_price_point = self.get_value_of_block_price_move( instrument_code) daily_returns_volatility = self.get_daily_returns_volatility( instrument_code) average_position = self.get_volatility_scalar(instrument_code) SR_cost_per_trade = self.get_SR_cost_per_trade_for_instrument( instrument_code) subsystem_turnover = self.subsystem_turnover(instrument_code) annualised_SR_cost = SR_cost_per_trade * subsystem_turnover capital = self.get_notional_capital() pandl_calculator = pandlCalculationWithSRCosts( price, SR_cost=annualised_SR_cost, positions=positions, average_position=average_position, daily_returns_volatility=daily_returns_volatility, capital=capital, value_per_point=value_of_price_point, delayfill=delayfill, fx=fx, roundpositions=roundpositions) account_curve = accountCurve(pandl_calculator) return account_curve
def __getitem__(self, item): kwargs = self.kwargs return accountCurve(self.get_pandl_calculator_for_item(item), **kwargs)