#Quantopian Algorithm ordervalue
7501 단어 QuantopianPython
order_value
order_value는 지정 품종과 거래액 주문의 함수다.
order_value(asset, amount, style=OrderType)
asset:Equity/Future 객체amount: 거래액. 플러스는 롱, 마이너스는 샷.
style: 주문 방법(지정 방법 참조order
알고리즘 예
코드를 한 군데 바꾸었다.
def initialize(context):
# AAPL
context.security = sid(24)
# rebalance 関数を毎日クローズ一分前(15:59)に実行するように指定
schedule_function(rebalance,
date_rule=date_rules.every_day(),
time_rule=time_rules.market_close(minutes = 1))
def rebalance(context, data):
# 過去5日間の平均を取得して,今日の価格よりも1%大きければLong
# 今日価格が移動平均より小さければ,ポジションクローズする
# 過去5日間のヒストリカルデータを取得.
# 【注意】https://www.quantopian.com/help#ide-history に説明があるとおり,
# 日中にヒストリカルデータを複数日分取得すると,
# 「過去4日分と今現在の価格」が取得できます.現在価格はhistorical data 同様,アジャストされた価格です.
price_history = data.history(
context.security,
fields='price',
bar_count=5,
frequency='1d'
)
# price_historyを出力
# log.info(price_history)
# 平均値
average_price = price_history.mean()
# 現在の価格
current_price = data.current(context.security, 'price')
# log.info(current_price)
# 注文しようとしている銘柄が,現在上場されているか確認
if data.can_trade(context.security):
# 平均値より,1%大きければ,Long
if current_price > (1.01 * average_price):
# 成り行きで10株買う
order_value(context.security, 1000) # ←変更箇所
log.info("Buying %s" % (context.security.symbol))
# 平均値より小さければ,ポジションをクローズ
elif current_price < average_price:
# 0と注文することでポジションを精算することになる
order_target(context.security, 0)
log.info("Selling %s" % (context.security.symbol))
# 平均値と現在価格を描画
record(current_price=current_price, average_price=average_price)
메모지
이 알고리즘은 조건에 따라 1000달러를 추가 구매하는 알고리즘이다. 1000달러 부분은 1000달러를 넘지 않는 주문을 말한다. 예를 들어 AAPL이 105달러면 9주를 주문한다. 주식 수량을 확인하려면 실행
run full backtest
후,Transaction Details를 보시면 확인할 수 있습니다.(주가에 맞추어 어쨌든 다섯 주 여섯 주 샀는데↓)
#Quantopian Algorithm order
나는 기쁠 때 알고리즘의 주문 방법을 조금씩 쓰고 싶다.
다음은.
기타 주문 방법
order_percent
#Quantopian Algorithm order
#Quantopian Algorithm orderpercent
#Quantopian Algorithm ordertarget
Reference
이 문제에 관하여(#Quantopian Algorithm ordervalue), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/shinseitaro/items/16f0f12ad65f428c2f4b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)