本文整理汇总了Python中zipline.api.order函数的典型用法代码示例。如果您正苦于以下问题:Python order函数的具体用法?Python order怎么用?Python order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了order函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle_data
def handle_data(context, data):
# Skip first 300 days to get full windows
context.i += 1
if context.i < context.N:
return
# Compute averages
# history() has to be called with the same params
# from above and returns a pandas dataframe.
c = history(context.N, '1d', 'close')
o = history(context.N, '1d', 'open')
h = history(context.N, '1d', 'high')
l = history(context.N, '1d', 'low')
for sym in data:
# Trading logic
hh = h[sym].ix[:-1].max()
hc = c[sym].ix[:-1].max()
lc = c[sym].ix[:-1].min()
ll = l[sym].ix[:-1].min()
r = max(hh-lc, hc-ll)
upper = data[sym].open + context.k * r
lower = data[sym].open - context.k * r
if short_mavg[sym] > long_mavg[sym] and not context.invested:
# order_target orders as many shares as needed to
# achieve the desired number of shares.
order(sym, 10000, limit_price=data[sym].price)
context.invested = True
elif short_mavg[sym] < long_mavg[sym] and context.invested:
order(sym, -10000, limit_price=data[sym].price)
context.invested = False
开发者ID:zhoubug,项目名称:stock,代码行数:31,代码来源:dual_thrust.py
示例2: handle_data
def handle_data(context, data):
if context.traded:
return
print data
order(context.stock, 10000)
order(context.stock, - 10000, style=LimitOrder(data[context.stock]['close'] * 1.1))
context.traded = True
开发者ID:liangcai2012,项目名称:savant-torrey-ranch,代码行数:7,代码来源:ipo.py
示例3: handle_data
def handle_data(context, data):
curr_price = data[symbol('USCRWTIC INDEX')].price
curr_positions = context.portfolio.positions[symbol('USCRWTIC INDEX')].amount
cash = context.portfolio.cash
print cash, curr_positions, curr_price
# context.counter += 1
# if context.counter > 500:
# print "Cancelou"
# cancel_order(context.order_id)
# else:
# print 'ola'
random_order = np.random.rand()
if random_order > 0.5 and curr_positions == 0:
order(symbol('USCRWTIC INDEX'), 100)
elif random_order < 0.5 and curr_positions != 0:
order(symbol('USCRWTIC INDEX'), -100)
开发者ID:ricardompassos,项目名称:backtest,代码行数:26,代码来源:oil_example_simple.py
示例4: func0
def func0(context, data):
order(symbol('AAPL UW EQUITY'), 10)
print 'price: ', data[symbol('AAPL UW EQUITY')].price
# order(symbol('AAPL UW EQUITY'), -10)
print context.portfolio.cash
print context.get_datetime().date()
print "==========================="
开发者ID:ricardompassos,项目名称:backtest,代码行数:7,代码来源:buy_and_hold_my.py
示例5: handle_data
def handle_data(context, data):
curr_price = data[symbol('USCRWTIC INDEX')].price
curr_date = data[symbol('USCRWTIC INDEX')].datetime
curr_positions = context.portfolio.positions[symbol('USCRWTIC INDEX')].amount
cash = context.portfolio.cash
local_historical_data = context.oil_historical_data
local_historical_data = local_historical_data['USCRWTIC INDEX'][['price']]
df_to_forecast = local_historical_data[local_historical_data.index <= curr_date]
result = forecast_ts.run(df = df_to_forecast, ts_list = None, freq = 'B', forecast_horizon = 6, start_date = curr_date.strftime('%Y-%m-%d'), method = context.method, processing_params = context.processing_params, expert_params = context.expert_params)
estimated_return = result.iloc[-1].values[-1]
# estimated_return = np.random.rand()-1
print cash, curr_positions, curr_price, curr_date, estimated_return
if estimated_return < 0 and curr_positions == 0:
order(symbol('USCRWTIC INDEX'), -100)
elif estimated_return > 0 and curr_positions != 0:
order(symbol('USCRWTIC INDEX'), 100)
开发者ID:ricardompassos,项目名称:backtest,代码行数:30,代码来源:oil_example_2.py
示例6: handle_data
def handle_data(context, data):
# context.i+=1
# if context.i<=5:
# return
# 循环每只股票
closeprice= history(5,'1d','close')
for security in context.stocks:
vwap=(closeprice[symbol(security)][-2]+closeprice[symbol(security)][-3]+closeprice[symbol(security)][-4])/3
price = closeprice[symbol(security)][-2]
print get_datetime(),security,vwap,price
# # 如果上一时间点价格小于三天平均价*0.995,并且持有该股票,卖出
if price < vwap * 0.995:
# 下入卖出单
order(symbol(security),-300)
print get_datetime(),("Selling %s" % (security))
# 记录这次卖出
#log.info("Selling %s" % (security))
# 如果上一时间点价格大于三天平均价*1.005,并且有现金余额,买入
elif price > vwap * 1.005:
# 下入买入单
order(symbol(security),300)
# 记录这次买入
print get_datetime(),("Buying %s" % (security))
开发者ID:liyizheng0513,项目名称:zipline-chinese,代码行数:25,代码来源:stock_select.py
示例7: handle_data
def handle_data(context, data):
short_ema = context.short_ema_trans.handle_data(data)
long_ema = context.long_ema_trans.handle_data(data)
if short_ema is None or long_ema is None:
return
buy = False
sell = False
if (short_ema > long_ema).all() and not context.invested:
order(context.asset, 100)
context.invested = True
buy = True
elif (short_ema < long_ema).all() and context.invested:
order(context.asset, -100)
context.invested = False
sell = True
record(
AAPL=data[context.asset].price,
short_ema=short_ema[context.asset],
long_ema=long_ema[context.asset],
buy=buy,
sell=sell,
)
开发者ID:runtBlue,项目名称:zipline,代码行数:25,代码来源:dual_ema_talib.py
示例8: handle_data
def handle_data(context, data):
print "================================="
print "New iteration"
print data
order(symbol('AAPL'), 10)
record(AAPL=data[symbol('AAPL')].price)
开发者ID:ricardompassos,项目名称:backtest,代码行数:8,代码来源:buyapple.py
示例9: handle_data
def handle_data(context, data):
hist = data.history(context.smb, bar_count=5, frequency='1m', fields='open')
if not context.ordered:
print("ordering")
order(context.smb, 100, limit_price=5.00)
context.ordered = True
cancle_open_orders(context,data)
print(hist)
开发者ID:huangzhengyong,项目名称:zipline,代码行数:8,代码来源:live_strategy.py
示例10: handle_data
def handle_data(context, data):
context.i += 1
stock_name = context.panel.axes[0][0]
if context.i == 60:
order(symbol(stock_name), 10)
if context.i == 150:
order(symbol(stock_name), -10)
record(Prices=data[symbol(stock_name)].price)
开发者ID:skye17,项目名称:newfront,代码行数:8,代码来源:order_then_sell.py
示例11: _handle_data
def _handle_data(self, context, data):
for movimiento in context.movimientos:
clave_emisora = movimiento.emisora
fecha_movimiento = movimiento.fecha
fecha = data[symbol(clave_emisora)].dt
delta = fecha_movimiento - fecha.replace(tzinfo=None)
num_acciones = movimiento.num_acciones
if(delta.days == 0):
order(symbol(clave_emisora), num_acciones)
开发者ID:ivansabik,项目名称:tradinglab-mexico,代码行数:9,代码来源:modelos.py
示例12: handle_data_api
def handle_data_api(context, data):
if context.incr == 0:
assert 0 not in context.portfolio.positions
else:
assert context.portfolio.positions[0]["amount"] == context.incr, "Orders not filled immediately."
assert context.portfolio.positions[0]["last_sale_price"] == data[0].price, "Orders not filled at current price."
context.incr += 1
order(0, 1)
record(incr=context.incr)
开发者ID:humdings,项目名称:zipline,代码行数:10,代码来源:test_algorithms.py
示例13: handle_data
def handle_data(self, data):
from zipline.api import (
order_percent,
order_target,
order_target_percent,
order_target_value,
order_value,
)
for style in [MarketOrder(), LimitOrder(10),
StopOrder(10), StopLimitOrder(10, 10)]:
with assert_raises(UnsupportedOrderParameters):
order(self.asset, 10, limit_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order(self.asset, 10, stop_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_value(self.asset, 300, limit_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_value(self.asset, 300, stop_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_percent(self.asset, .1, limit_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_percent(self.asset, .1, stop_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_target(self.asset, 100, limit_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_target(self.asset, 100, stop_price=10, style=style)
with assert_raises(UnsupportedOrderParameters):
order_target_value(self.asset, 100,
limit_price=10,
style=style)
with assert_raises(UnsupportedOrderParameters):
order_target_value(self.asset, 100,
stop_price=10,
style=style)
with assert_raises(UnsupportedOrderParameters):
order_target_percent(self.asset, .2,
limit_price=10,
style=style)
with assert_raises(UnsupportedOrderParameters):
order_target_percent(self.asset, .2,
stop_price=10,
style=style)
开发者ID:chaoyeung,项目名称:zipline,代码行数:55,代码来源:test_algorithms.py
示例14: handle_data
def handle_data(context, data):
for stock in data:
print stock, sid(stock)
if not context.has_ordered:
for stock in data:
print stock
order(sid(stock), 100)
context.has_ordered = True
print "==================="
开发者ID:ricardompassos,项目名称:backtest,代码行数:11,代码来源:buy_and_hold.py
示例15: handle_data_api
def handle_data_api(context, data):
if context.incr == 0:
assert 0 not in context.portfolio.positions
else:
assert context.portfolio.positions[0].amount == context.incr, "Orders not filled immediately."
assert context.portfolio.positions[0].last_sale_price == data.current(
sid(0), "price"
), "Orders not filled at current price."
context.incr += 1
order(sid(0), 1)
record(incr=context.incr)
开发者ID:AtwooTM,项目名称:zipline,代码行数:12,代码来源:test_algorithms.py
示例16: handle_data
def handle_data(context, data):
context.panel # Here we have access to training data also.
# Make solution using the result of learning:
if not int(data[symbol('AAPL')].price) % context.result:
order(symbol('AAPL'), 10)
# Record some values for analysis in 'analyze()'.
sids = context.panel.axes[0].values
prices = [data[symbol(sid)].price for sid in sids]
record(Prices=prices)
record(Prediction=3 * data[symbol('AAPL')].price - 2.2 * context.previous)
# Record current price to use it in future.
context.previous = data[symbol('AAPL')].price
开发者ID:skye17,项目名称:frontopolar_site,代码行数:12,代码来源:default.py
示例17: handle_data
def handle_data(context, data):
average_price = data[context.security].mavg(5)
current_price = data[context.security].price
cash = context.portfolio.cash
if current_price > 1.01*average_price and cash > current_price:
number_of_shares = int(cash/current_price)
order(context.security, +number_of_shares)
log.info("Buying %s" % (context.security.symbol))
elif current_price < average_price:
order_target(context.security, 0)
log.info("Selling %s" % (context.security.symbol))
record(stock_price=data[context.security].price)
开发者ID:mequanta,项目名称:z-runner,代码行数:15,代码来源:basic_algorithm.py
示例18: handle_data_api
def handle_data_api(context, data):
if context.incr == 0:
assert 0 not in context.portfolio.positions
else:
assert (
context.portfolio.positions[0].amount ==
context.incr
), "Orders not filled immediately."
assert (
context.portfolio.positions[0].last_sale_date ==
context.get_datetime()
), "Orders not filled at current datetime."
context.incr += 1
order(sid(0), 1)
record(incr=context.incr)
开发者ID:zhou,项目名称:zipline,代码行数:16,代码来源:test_algorithms.py
示例19: handle_data
def handle_data(context, data):
stock_name = context.panel.axes[0][0]
def normalize(price):
return 1 / (1 + np.exp((context.mean - price) / context.scale))
def unnormalize(prediction):
return context.mean - context.scale * (np.log((1 / prediction) - 1))
context.current_day += 1
context.trash_days_counter += 1
current_price = data[symbol(stock_name)].price
context.history.push(current_price)
current_mean = context.history.get_mean()
X = normalize(current_price)
X_2 = context.history.get_norm_mean()
input_ = np.array([[X, X_2]]).astype(theano.config.floatX).reshape(1, 1, 2)
prediction = context.get_output(input_)[0][0]
next_day_norm_price = context.history.calc_next_day_norm_price(prediction)
unnorm_prediction = unnormalize(prediction)
day2_input_ = np.array([[next_day_norm_price, prediction]])
day2_input_ = day2_input_.astype(theano.config.floatX).reshape(1, 1, 2)
prediction_2_day = context.get_output(day2_input_)[0][0]
day2_norm_price = prediction_2_day * 5 - \
sum(context.history.norm_queue[2:]) - \
next_day_norm_price
if context.current_day % 14 == 0:
if max(context.history.norm_queue) < next_day_norm_price - 0.08:
# print('buy',day2_norm_price, next_day_norm_price,
# max(context.history.norm_queue))
order(symbol(stock_name), int(10000 * (next_day_norm_price - max(context.history.norm_queue))))
elif next_day_norm_price + 0.08 < min(context.history.norm_queue):
# print('sell', day2_norm_price, next_day_norm_price,
# min(context.history.norm_queue))
order(symbol(stock_name), int(10000 * (next_day_norm_price - min(context.history.norm_queue))))
record(normPrediction=prediction)
record(normPrices=X_2)
record(Prediction=unnorm_prediction)
record(Prices=current_mean)
开发者ID:skye17,项目名称:newfront,代码行数:43,代码来源:net4.py
示例20: handle_data
def handle_data(context, data):
context.cnt += 1
new_prices = np.array([data[symbol(asset_name)].price for asset_name in context.panel.axes[0]], dtype='float32')
# print new_prices
if context.check == 0:
context.check = 1
context.old_prices = new_prices
return
price_diffs = new_prices - context.old_prices
normed_price_diffs = price_diffs / context.old_prices
# print context.portfolio['portfolio_value']
# new_portf = context.action
# new_portf = calc_portfolio(normed_price_diffs, context)
new_portf = context.pred[context.cnt]
for i in np.arange(len(new_portf)):
name = symbol(context.panel.axes[0][i])
num = new_portf[i] - context.portf[i]
order(name, num * 100)
context.portf = new_portf
context.old_prices = new_prices
开发者ID:skye17,项目名称:newfront,代码行数:21,代码来源:brand_new.py
注:本文中的zipline.api.order函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论