Help us understand the problem. What is going on with this article?

#Quantopian Algorithm で order_target_value

More than 1 year has passed since last update.

order_target_value

order_target_valueは,とある銘柄をポートフォリオに指定した額だけ保有する注文方法です.

order_target_value(asset, amount, style=OrderType)

asset: Equity/Future オブジェクト
amount: 取引額.正であればLong,負であればShort.
style: 注文方法(指定方法はorder_target_valueを参照)

アルゴリズム例

(オーダー方法以外は,#Quantopian Algorithm で order - Qiitaにコメントで説明していますのでご参照下さい)

def initialize(context):
    context.security = sid(24)
    schedule_function(rebalance, 
                      date_rule=date_rules.every_day(),
                      time_rule=time_rules.market_close(minutes = 1))

def rebalance(context, data):
    price_history = data.history(
        context.security,
        fields='price',
        bar_count=5,
        frequency='1d'
    )
    average_price = price_history.mean()
    current_price = data.current(context.security, 'price') 
    if data.can_trade(context.security):
        if current_price > (1.01 * average_price):
            # ポートフォリオに1000ドル分のアップル株を保有するように注文する.
            order_target_value(context.security, 1000)
            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(current_price=current_price, average_price=average_price)

メモ

order_target_valueは,order_valueと同様に,株数ではなく〇〇ドル分保有する,という注文ができます.1000ドル分とは,1000ドルを超えないオーダーという意味になります.

order_valueとの違いは,ポートフォリオに〇〇ドル分保有したら,その後,注文トリガーに当たっても取引はしない,というところです.
上記コードで言えば,current_price が 5日平均価格よりも1%高ければ,アップルを1000ドル注文する,というロジックですが,もし既にポートフォリオにアップルを1000ドル分持っていれば,注文はDoneされません.この挙動は,order_targetと同じのでご参照ください.

他のオーダー方法

#Quantopian Algorithm で order
#Quantopian Algorithm で order_value
#Quantopian Algorithm で order_percent
#Quantopian Algorithm で order_target

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away