当前位置: 首页>>代码示例>>Python>>正文


Python LightTimeSeriesFactory.harvest_time_series方法代码示例

本文整理汇总了Python中pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory.harvest_time_series方法的典型用法代码示例。如果您正苦于以下问题:Python LightTimeSeriesFactory.harvest_time_series方法的具体用法?Python LightTimeSeriesFactory.harvest_time_series怎么用?Python LightTimeSeriesFactory.harvest_time_series使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory的用法示例。


在下文中一共展示了LightTimeSeriesFactory.harvest_time_series方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: StrategyFXCTA_Example

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
class StrategyFXCTA_Example(StrategyTemplate):

    def __init__(self):
        super(StrategyTemplate, self).__init__()
        self.logger = LoggerManager().getLogger(__name__)

        ##### FILL IN WITH YOUR OWN PARAMETERS FOR display, dumping, TSF etc.
        self.tsfactory = LightTimeSeriesFactory()
        self.DUMP_CSV = 'output_data/'
        self.DUMP_PATH = 'output_data/' + datetime.date.today().strftime("%Y%m%d") + ' '
        self.FINAL_STRATEGY = 'Thalesians FX CTA'
        self.SCALE_FACTOR = 3
        
        return

    ###### Parameters and signal generations (need to be customised for every model)
    def fill_backtest_request(self):

        ##### FILL IN WITH YOUR OWN BACKTESTING PARAMETERS
        br = BacktestRequest()

        # get all asset data
        br.start_date = "04 Jan 1989"
        br.finish_date = datetime.datetime.utcnow()
        br.spot_tc_bp = 0.5
        br.ann_factor = 252

        br.plot_start = "01 Apr 2015"
        br.calc_stats = True
        br.write_csv = False
        br.plot_interim = True
        br.include_benchmark = True

        # have vol target for each signal
        br.signal_vol_adjust = True
        br.signal_vol_target = 0.1
        br.signal_vol_max_leverage = 5
        br.signal_vol_periods = 20
        br.signal_vol_obs_in_year = 252
        br.signal_vol_rebalance_freq = 'BM'
        br.signal_vol_resample_freq = None

        # have vol target for portfolio
        br.portfolio_vol_adjust = True
        br.portfolio_vol_target = 0.1
        br.portfolio_vol_max_leverage = 5
        br.portfolio_vol_periods = 20
        br.portfolio_vol_obs_in_year = 252
        br.portfolio_vol_rebalance_freq = 'BM'
        br.portfolio_vol_resample_freq = None

        # tech params
        br.tech_params.sma_period = 200

        return br

    def fill_assets(self):
        ##### FILL IN WITH YOUR ASSET DATA

        # for FX basket
        full_bkt    = ['EURUSD', 'USDJPY', 'GBPUSD', 'AUDUSD', 'USDCAD',
                       'NZDUSD', 'USDCHF', 'USDNOK', 'USDSEK']

        basket_dict = {}

        for i in range(0, len(full_bkt)):
            basket_dict[full_bkt[i]] = [full_bkt[i]]

        basket_dict['Thalesians FX CTA'] = full_bkt

        br = self.fill_backtest_request()

        self.logger.info("Loading asset data...")

        vendor_tickers = ['FRED/DEXUSEU', 'FRED/DEXJPUS', 'FRED/DEXUSUK', 'FRED/DEXUSAL', 'FRED/DEXCAUS',
                          'FRED/DEXUSNZ', 'FRED/DEXSZUS', 'FRED/DEXNOUS', 'FRED/DEXSDUS']

        time_series_request = TimeSeriesRequest(
                    start_date = br.start_date,                     # start date
                    finish_date = br.finish_date,                   # finish date
                    freq = 'daily',                                 # daily data
                    data_source = 'quandl',                         # use Quandl as data source
                    tickers = full_bkt,                             # ticker (Thalesians)
                    fields = ['close'],                                 # which fields to download
                    vendor_tickers = vendor_tickers,                    # ticker (Quandl)
                    vendor_fields = ['close'],                          # which Bloomberg fields to download
                    cache_algo = 'internet_load_return')                # how to return data

        asset_df = self.tsfactory.harvest_time_series(time_series_request)

        # signalling variables
        spot_df = asset_df
        spot_df2 = None

        return asset_df, spot_df, spot_df2, basket_dict

    def construct_signal(self, spot_df, spot_df2, tech_params, br):

        ##### FILL IN WITH YOUR OWN SIGNALS

#.........这里部分代码省略.........
开发者ID:BryanFletcher,项目名称:pythalesians,代码行数:103,代码来源:strategyfxcta_example.py

示例2: TimeSeriesRequest

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
if True:
    time_series_request = TimeSeriesRequest(
                start_date = "01 Jan 2013",                     # start date
                finish_date = datetime.date.today(),            # finish date
                freq = 'daily',                                 # daily data
                data_source = 'google',                         # use Bloomberg as data source
                tickers = ['Apple', 'S&P500 ETF'],                  # ticker (Thalesians)
                fields = ['close'],                                 # which fields to download
                vendor_tickers = ['aapl', 'spy'],                   # ticker (Google)
                vendor_fields = ['Close'],                          # which Bloomberg fields to download
                cache_algo = 'internet_load_return')                # how to return data

    ltsf = LightTimeSeriesFactory()
    tsc = TimeSeriesCalcs()

    df = tsc.create_mult_index_from_prices(ltsf.harvest_time_series(time_series_request))

    gp = GraphProperties()
    gp.html_file_output = "output_data/apple.htm"
    gp.title = "S&P500 vs Apple"

    # plot first with PyThalesians and then Bokeh
    # just needs 1 word to change
    gp.display_legend = False

    pf = PlotFactory()
    pf.plot_generic_graph(df, type = 'line', adapter = 'pythalesians', gp = gp)
    pf.plot_generic_graph(df, type = 'line', adapter = 'bokeh', gp = gp)

# test simple Bokeh bar charts - monthly returns over past 6 months
if True:
开发者ID:BryanFletcher,项目名称:pythalesians,代码行数:33,代码来源:bokeh_examples.py

示例3: TimeSeriesRequest

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
###### calculate seasonal moves in EUR/USD and GBP/USD (using Quandl data)
if True:
    time_series_request = TimeSeriesRequest(
                start_date = "01 Jan 1970",                     # start date
                finish_date = datetime.date.today(),            # finish date
                freq = 'daily',                                 # daily data
                data_source = 'quandl',                         # use Quandl as data source
                tickers = ['EURUSD',                            # ticker (Thalesians)
                           'GBPUSD'],
                fields = ['close'],                                 # which fields to download
                vendor_tickers = ['FRED/DEXUSEU', 'FRED/DEXUSUK'],  # ticker (Quandl)
                vendor_fields = ['close'],                          # which Bloomberg fields to download
                cache_algo = 'internet_load_return')                # how to return data

    ltsf = LightTimeSeriesFactory()

    df = ltsf.harvest_time_series(time_series_request)

    df_ret = tsc.calculate_returns(df)

    day_of_month_seasonality = seasonality.bus_day_of_month_seasonality(df_ret, partition_by_month = False)
    day_of_month_seasonality = tsc.convert_month_day_to_date_time(day_of_month_seasonality)

    gp = GraphProperties()
    gp.date_formatter = '%b'
    gp.title = 'FX spot moves by time of year'
    gp.scale_factor = 3
    gp.file_output = "output_data/20150724 FX spot seas.png"

    pf.plot_line_graph(day_of_month_seasonality, adapter='pythalesians', gp = gp)
开发者ID:humdings,项目名称:pythalesians,代码行数:32,代码来源:seasonality_examples.py

示例4: TimeSeriesRequest

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
    time_series_request = TimeSeriesRequest(
        start_date="01 Jan 1970",  # start date
        finish_date=datetime.date.today(),  # finish date
        freq='daily',  # daily data
        data_source='quandl',  # use Quandl as data source
        tickers=['EURUSD',  # ticker (Thalesians)
                 'GBPUSD'],
        fields=['close'],  # which fields to download
        vendor_tickers=['FRED/DEXUSEU', 'FRED/DEXUSUK'],  # ticker (Quandl)
        vendor_fields=['close'],  # which Bloomberg fields to download
        cache_algo='internet_load_return')  # how to return data

    ltsf = LightTimeSeriesFactory()

    daily_vals = ltsf.harvest_time_series(time_series_request)

    techind = TechIndicator()
    tech_params = TechParams()
    tech_params.sma_period = 20

    techind.create_tech_ind(daily_vals, 'SMA', tech_params=tech_params)

    sma = techind.get_techind()
    signal = techind.get_signal()

    combine = daily_vals.join(sma, how='outer')

    pf = PlotFactory()
    pf.plot_line_graph(combine, adapter='pythalesians')
开发者ID:NunoEdgarGub1,项目名称:pythalesians,代码行数:31,代码来源:techindicator_examples.py

示例5: LightTimeSeriesFactory

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
        # tickers for overnight deposit data, which is necessary for computing total return indices
        time_series_request_deposit = copy.copy(time_series_request_spot)
        time_series_request_deposit.tickers = ['EURON', 'USDON', 'GBPON', 'AUDON']
        time_series_request_deposit.vendor_tickers = ['EUDR1T CMPN Curncy', 'USDR1T CMPN Curncy',
                                                      'BPDR1T CMPN Curncy', 'ADDR1T CMPN Curncy']

        # tickers for getting total return indices from Bloomberg directly
        time_series_request_total_ret = copy.copy(time_series_request_spot)
        time_series_request_total_ret.tickers = ['EURUSD', 'GBPUSD', 'AUDUSD']
        time_series_request_total_ret.vendor_tickers = ['EURUSDCR BGN Curncy', 'GBPUSDCR BGN Curncy', 'AUDUSDCR BGN Curncy']

        ltsf = LightTimeSeriesFactory()

        df = None
        spot_df = ltsf.harvest_time_series(time_series_request_spot)
        deposit_df = ltsf.harvest_time_series(time_series_request_deposit)

        deposit_df = deposit_df.fillna(method = 'ffill')
        deposit_df = deposit_df.fillna(method = 'bfill') # bit of a hack - because some deposit data sparse
        tot_df = ltsf.harvest_time_series(time_series_request_total_ret)
        tsc = TimeSeriesCalcs()

        tot_df = tsc.create_mult_index_from_prices(tot_df) # rebase index at 100

        # we can change the
        tenor = 'ON'

        # plot total return series comparison for all our crosses
        # in practice, we would typically make a set of xxxUSD total return indices
        # and use them to compute all other crosses (assuming we are USD denominated investor)
开发者ID:hedgefair,项目名称:pythalesians,代码行数:32,代码来源:indicesfx_examples.py

示例6: TimeSeriesRequest

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
        time_series_request = TimeSeriesRequest(
                start_date = start_date,                # start date
                finish_date = finish_date,              # finish date
                category = "events",
                freq = 'daily',                         # daily data
                data_source = 'bloomberg',              # use Bloomberg as data source
                tickers = ['NFP'],
                fields = ['release-date-time-full'],                    # which fields to download
                vendor_tickers = ['NFP TCH Index'], # ticker (Bloomberg)
                vendor_fields = ['ECO_FUTURE_RELEASE_DATE_LIST'],   # which Bloomberg fields to download
                cache_algo = 'internet_load_return')                # how to return data

        ltsf = LightTimeSeriesFactory()
        ts_filter = TimeSeriesFilter()

        df_event_times = ltsf.harvest_time_series(time_series_request)

        utc_time = pytz.utc
        df_event_times = pandas.DataFrame(index = df_event_times['NFP.release-date-time-full'])
        df_event_times.index = df_event_times.index.tz_localize(utc_time)    # work in UTC time
        df_event_times = ts_filter.filter_time_series_by_date(start_date, finish_date, df_event_times)

        # get last NFP time
        start_date = df_event_times.index[-1] - timedelta(minutes=1)
        finish_date = start_date + timedelta(minutes=4)

        tickers = ['EURUSD', 'JPYUSD', 'GBPUSD']
        vendor_tickers = ['EURUSD BGN Curncy', 'USDJPY BGN Curncy', 'GBPUSD BGN Curncy']

        # Bloomberg will give tick data which is downsampled within the LightTimeSeriesFactory class
        time_series_request = TimeSeriesRequest(
开发者ID:NunoEdgarGub1,项目名称:pythalesians,代码行数:33,代码来源:tick_examples.py

示例7: __init__

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
class HistEconDataFactory:
    def __init__(self):
        self.logger = LoggerManager().getLogger(__name__)

        self._all_econ_tickers = pandas.read_csv(Constants().all_econ_tickers)
        self._econ_country_codes = pandas.read_csv(Constants().econ_country_codes)
        self._econ_country_groups = pandas.read_csv(Constants().econ_country_groups)

        self.time_series_factory = LightTimeSeriesFactory()

        # if Constants().default_time_series_factory == 'lighttimeseriesfactory':
        #     self.time_series_factory = LightTimeSeriesFactory()
        # else:
        #     self.time_series_factory = CachedTimeSeriesFactory()
        # return

    def get_economic_data_history(
        self, start_date, finish_date, country_group, data_type, source="fred", cache_algo="internet_load_return"
    ):

        # vendor_country_codes = self.fred_country_codes[country_group]
        # vendor_pretty_country = self.fred_nice_country_codes[country_group]

        if isinstance(country_group, list):
            pretty_country_names = country_group
        else:
            # get all the country names in the country_group
            pretty_country_names = list(
                self._econ_country_groups[self._econ_country_groups["Country Group"] == country_group]["Country"]
            )

        # construct the pretty tickers
        pretty_tickers = [x + "-" + data_type for x in pretty_country_names]

        # get vendor tickers
        vendor_tickers = []

        for pretty_ticker in pretty_tickers:
            vendor_ticker = list(
                self._all_econ_tickers[self._all_econ_tickers["Full Code"] == pretty_ticker][source].values
            )

            if vendor_ticker == []:
                vendor_ticker = None
                self.logger.error("Could not find match for " + pretty_ticker)
            else:
                vendor_ticker = vendor_ticker[0]

            vendor_tickers.append(vendor_ticker)

        vendor_fields = ["close"]

        if source == "bloomberg":
            vendor_fields = ["PX_LAST"]

        time_series_request = TimeSeriesRequest(
            start_date=start_date,  # start date
            finish_date=finish_date,  # finish date
            category="economic",
            freq="daily",  # intraday data
            data_source=source,  # use Bloomberg as data source
            cut="LOC",
            tickers=pretty_tickers,
            fields=["close"],  # which fields to download
            vendor_tickers=vendor_tickers,
            vendor_fields=vendor_fields,  # which Bloomberg fields to download
            cache_algo=cache_algo,
        )  # how to return data

        return self.time_series_factory.harvest_time_series(time_series_request)

    def grasp_coded_entry(self, df, index):
        df = df.ix[index:].stack()
        df = df.reset_index()
        df.columns = ["Date", "Name", "Val"]

        countries = df["Name"]

        countries = [x.split("-", 1)[0] for x in countries]

        df["Code"] = sum(
            [list(self._econ_country_codes[self._econ_country_codes["Country"] == x]["Code"]) for x in countries], []
        )

        return df
开发者ID:swaraj007,项目名称:pythalesians,代码行数:87,代码来源:histecondatafactory.py

示例8: str

# 需要导入模块: from pythalesians.market.loaders.lighttimeseriesfactory import LightTimeSeriesFactory [as 别名]
# 或者: from pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory import harvest_time_series [as 别名]
            thread_no = [1,2,3,4]

            thread_technique = ["thread", "multiprocessor"]
            diag = []

            for tech in thread_technique:
                # change the static variable in Constants which govern the threading we use
                Constants.time_series_factory_thread_technique = tech

                for no in thread_no:
                    for key in Constants.time_series_factory_thread_no:
                        Constants.time_series_factory_thread_no[key] = no

                    import time
                    start = time.time();
                    df = ltsf.harvest_time_series(time_series_request);
                    end = time.time()
                    duration = end - start

                    diag.append("With " + str(no) + " " + tech + " no: " + str(duration) + " seconds")

            for d in diag:
                logger.info(d)

        ###### download intraday data from Bloomberg for FX, with different threading techniques
        if True:

            from datetime import timedelta

            time_series_request = TimeSeriesRequest(
                    start_date = datetime.date.today() - timedelta(days=10),    # start date
开发者ID:BryanFletcher,项目名称:pythalesians,代码行数:33,代码来源:paralleldata_examples.py


注:本文中的pythalesians.market.loaders.lighttimeseriesfactory.LightTimeSeriesFactory.harvest_time_series方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。