def calculate_ret_stats(self, returns_df, ann_factor): """ calculate_ret_stats - Calculates return statistics for an asset's returns including IR, vol, ret and drawdowns Parameters ---------- returns_df : DataFrame asset returns ann_factor : int annualisation factor to use on return statistics Returns ------- DataFrame """ calculations = Calculations() self._rets = returns_df.mean(axis=0) * ann_factor self._vol = returns_df.std(axis=0) * math.sqrt(ann_factor) self._inforatio = self._rets / self._vol self._kurtosis = returns_df.kurtosis(axis=0) / math.sqrt(ann_factor) index_df = calculations.create_mult_index(returns_df) # max2here = pandas.expanding_max(index_df) max2here = index_df.expanding(min_periods=1).max() dd2here = index_df / max2here - 1 self._dd = dd2here.min() self._yoy_rets = index_df.resample('A').mean().pct_change()
def report_single_var_regression(self, y, x, y_variable_names, x_variable_names, statistic, pretty_index = None): if not(isinstance(statistic, list)): statistic = [statistic] # conduct the regression stats = Calculations.linear_regression_single_vars(y, x, y_variable_names, x_variable_names) if pretty_index is None: pretty_index = x_variable_names # strip out the field(s) from the regression output which we want stats_df = Calculations.strip_linear_regression_output(pretty_index, stats, statistic) # stats_df = stats_df.sort_index() return stats_df
def calculate_ret_stats_from_prices(self, prices_df, ann_factor): """Calculates return statistics for an asset's price Parameters ---------- prices_df : DataFrame asset prices ann_factor : int annualisation factor to use on return statistics Returns ------- DataFrame """ calculations = Calculations() self.calculate_ret_stats(calculations.calculate_returns(prices_df), ann_factor)
def report_single_var_regression(self, y, x, y_variable_names, x_variable_names, statistic, pretty_index=None): if not (isinstance(statistic, list)): statistic = [statistic] # conduct the regression stats = Calculations.linear_regression_single_vars( y, x, y_variable_names, x_variable_names) if pretty_index is None: pretty_index = x_variable_names # strip out the field(s) from the regression output which we want stats_df = Calculations.strip_linear_regression_output( pretty_index, stats, statistic) return stats_df
# # Copyright 2020 Cuemacro # # See the License for the specific language governing permissions and limitations under the License. # import pandas as pd import dask.dataframe as dd from findatapy.timeseries.calculations import Calculations from tcapy.util.loggermanager import LoggerManager from tcapy.util.utilfunc import UtilFunc util_func = UtilFunc() calculations = Calculations() file_extension = 'parquet' csv_output = '/data/csv_output/' ticker_mkt = ['EURUSD', 'GBPUSD', 'AUDUSD', 'NZDUSD', 'USDCAD', 'USDCHF', 'EURNOK', 'EURSEK', 'USDJPY'] ticker_combined_mkt = ['EURUSD', 'GBPUSD', 'AUDUSD', 'NZDUSD', 'USDCAD', 'USDJPY'] def create_resampled_spot_data(resample_freq='1min', data_vendor='dukascopy'): logger = LoggerManager.getLogger(__name__) csv_input_folder = '/data/csv_dump/' + data_vendor + '/' for ticker in ticker_mkt: