Пример #1
0
def trades_info(
    data=arg_not_supplied,
    calendar_days_back=1,
    end_date=arg_not_supplied,
    start_date=arg_not_supplied,
):
    """
    Report on system status

    :param: data blob
    :return: list of formatted output items
    """
    if data is arg_not_supplied:
        data = dataBlob()

    if end_date is arg_not_supplied:
        end_date = datetime.datetime.now()

    if start_date is arg_not_supplied:
        start_date = n_days_ago(calendar_days_back, date_ref=start_date)

    results_object = get_trades_report_data(data,
                                            start_date=start_date,
                                            end_date=end_date)
    formatted_output = format_trades_data(results_object)

    return formatted_output
Пример #2
0
def get_report_dates():

    end_date = arg_not_supplied
    start_date = arg_not_supplied
    start_period = arg_not_supplied
    end_period = arg_not_supplied

    input_end_date = get_datetime_input("End date for report?\n",
                                        allow_default=True,
                                        allow_period=True,
                                        allow_calendar_days=True)

    if type(input_end_date) is int:
        ## calendar days
        end_date = n_days_ago(input_end_date, datetime.datetime.now())
    elif type(input_end_date) is str:
        ## period
        end_period = input_end_date
    elif type(input_end_date) is datetime.datetime:
        end_date = input_end_date
    else:
        raise Exception("Don't recognise %s" % str(input_end_date))

    input_start_date = get_datetime_input("Start date for report? \n",
                                          allow_default=False,
                                          allow_period=True,
                                          allow_calendar_days=True)

    if type(input_start_date) is int:
        ## calendar days
        start_date = n_days_ago(input_start_date, end_date)
    elif type(input_start_date) is str:
        ## period
        start_period = input_start_date
    elif type(input_start_date) is datetime.datetime:
        start_date = input_start_date
    else:
        raise Exception("Don't recognise %s" % str(input_start_date))

    start_date, end_date = calculate_start_and_end_dates(
        calendar_days_back=arg_not_supplied,
        end_date=end_date,
        start_date=start_date,
        start_period=start_period,
        end_period=end_period)

    return start_date, end_date
Пример #3
0
    def _calculate_start_date(self) -> datetime.datetime:
        start_date = self._passed_start_date
        if start_date is arg_not_supplied:
            calendar_days_back = self._calendar_days_back
            end_date = self.end_date
            start_date = n_days_ago(calendar_days_back, date_ref=end_date)

        return start_date
Пример #4
0
def recent_average_price(data: dataBlob, instrument_code: str) -> float:
    diag_prices = diagPrices(data)
    prices = diag_prices.get_adjusted_prices(instrument_code)
    if len(prices) == 0:
        return np.nan
    one_year_ago = n_days_ago(365)
    recent_prices = prices[one_year_ago:]

    return recent_prices.mean(skipna=True)
Пример #5
0
def costs_report(data: dataBlob = arg_not_supplied,
                 calendar_days_back: int = 250,
                 end_date: datetime.datetime = arg_not_supplied,
                 start_date: datetime.datetime = arg_not_supplied):

    if data is arg_not_supplied:
        data = dataBlob()

    if end_date is arg_not_supplied:
        end_date = datetime.datetime.now()

    if start_date is arg_not_supplied:
        start_date = n_days_ago(calendar_days_back, date_ref=end_date)

    costs_report_data = get_costs_report_data(data,
                                              start_date=start_date,
                                              end_date=end_date)
    formatted_output = format_costs_data(costs_report_data)

    return formatted_output
Пример #6
0
    def average_spread_last_n_days(self, n_days: int = 14):
        recent_data = self[n_days_ago(n_days)]
        if len(recent_data) == 0:
            return missing_data

        return recent_data.mean(skipna=True)