Esempio n. 1
0
def do_livetrade():
    dv = DataView()
    dv.load_dataview(folder_path=dataview_store_folder)

    props = {"period": "day", "strategy_no": 1044, "init_balance": 1e6}
    props.update(data_config)
    props.update(trade_config)

    strategy = AlphaStrategy(pc_method='market_value_weight')
    pm = PortfolioManager()

    bt = AlphaLiveTradeInstance()
    trade_api = RealTimeTradeApi(props)
    ds = RemoteDataService()

    context = model.Context(dataview=dv,
                            instance=bt,
                            strategy=strategy,
                            trade_api=trade_api,
                            pm=pm,
                            data_api=ds)

    bt.init_from_config(props)
    bt.run_alpha()

    goal_positions = strategy.goal_positions
    print("Length of goal positions:", len(goal_positions))
    task_id, msg = trade_api.goal_portfolio(goal_positions)
    print(task_id, msg)
Esempio n. 2
0
def do_livetrade():
    dv = DataView()
    dv.load_dataview(folder_path=dataview_store_folder)
    
    props = {"period": "day",
             "strategy_no": 1044,
             "init_balance": 1e6}
    props.update(data_config)
    props.update(trade_config)
    
    strategy = AlphaStrategy(pc_method='market_value_weight')
    pm = PortfolioManager()
    
    bt = AlphaLiveTradeInstance()
    trade_api = RealTimeTradeApi(props)
    ds = RemoteDataService()
    
    context = model.Context(dataview=dv, instance=bt, strategy=strategy, trade_api=trade_api, pm=pm, data_api=ds)
    
    bt.init_from_config(props)
    bt.run_alpha()
    
    goal_positions = strategy.goal_positions
    print("Length of goal positions:", len(goal_positions))
    task_id, msg = trade_api.goal_portfolio(goal_positions)
    print(task_id, msg)
Esempio n. 3
0
def test_livetrade():
    dv = DataView()
    dv.load_dataview(folder_path=dataview_dir_path)

    props = {
        "benchmark": BENCHMARK,
        "universe": ','.join(dv.symbol),
        "start_date": dv.start_date,
        "end_date": dv.end_date,
        "period": "day",
        "days_delay": 0,
        "init_balance": 1e8,
        "position_ratio": 1.0,
        "strategy_no": 44
    }
    props.update(data_config)
    props.update(trade_config)

    stock_selector = model.StockSelector()
    stock_selector.add_filter(name='rank_ret_top10', func=my_selector)

    strategy = AlphaStrategy(stock_selector=stock_selector,
                             pc_method='equal_weight')
    pm = PortfolioManager()
    bt = AlphaLiveTradeInstance()
    trade_api = RealTimeTradeApi(props)
    ds = RemoteDataService()

    context = model.Context(dataview=dv,
                            instance=bt,
                            strategy=strategy,
                            trade_api=trade_api,
                            pm=pm,
                            data_api=ds)
    stock_selector.register_context(context)

    bt.init_from_config(props)
    bt.run_alpha()

    goal_positions = strategy.goal_positions
    print(goal_positions)

    do_analyze()
Esempio n. 4
0
def test_livetrade():
    dv = DataView()
    dv.load_dataview(folder_path=dataview_dir_path)
    
    props = {
        "benchmark": BENCHMARK,
        "universe": ','.join(dv.symbol),
        
        "start_date": dv.start_date,
        "end_date": dv.end_date,
        
        "period": "day",
        "days_delay": 0,
        
        "init_balance": 1e8,
        "position_ratio": 1.0,
        "strategy_no": 1044
    }
    props.update(data_config)
    props.update(trade_config)
    
    stock_selector = model.StockSelector()
    stock_selector.add_filter(name='rank_ret_top10', func=my_selector)
    
    strategy = AlphaStrategy(stock_selector=stock_selector, pc_method='equal_weight')
    pm = PortfolioManager()
    bt = AlphaLiveTradeInstance()
    trade_api = RealTimeTradeApi(props)
    ds = RemoteDataService()
    
    context = model.Context(dataview=dv, instance=bt, strategy=strategy, trade_api=trade_api, pm=pm, data_api=ds)
    stock_selector.register_context(context)
    
    bt.init_from_config(props)
    bt.run_alpha()
    
    goal_positions = strategy.goal_positions
    print(goal_positions)
    
    do_analyze()
def do_livetrade():
    dv = DataView()
    dv.load_dataview(folder_path=dataview_store_folder)

    # print("total_mv", dv.get_ts('total_mv'))
    # print("float_mv", dv.get_ts('float_mv'))

    props = {"period": "day", "strategy_no": 1683, "init_balance": 1e6}
    props.update(data_config)
    props.update(trade_config)

    strategy = AlphaStrategy(pc_method='market_value_weight')
    pm = PortfolioManager()

    bt = AlphaLiveTradeInstance()
    trade_api = RealTimeTradeApi(props)
    ds = RemoteDataService()

    context = model.Context(dataview=dv,
                            instance=bt,
                            strategy=strategy,
                            trade_api=trade_api,
                            pm=pm,
                            data_api=ds)

    trade_api.set_ordstatus_callback(on_orderstatus)
    trade_api.set_trade_callback(on_trade)
    trade_api.set_task_callback(on_taskstatus)
    bt.init_from_config(props)
    bt.run_alpha()

    goal_positions = strategy.goal_positions
    # print("strategy.weights", strategy.weights)
    # print("Length of goal positions:", len(goal_positions))
    # print(goal_positions)
    task_id, msg = trade_api.goal_portfolio(goal_positions)
    print(task_id, msg)