#Quantopian Algorithm orderpercent

7224 단어 QuantopianPython

order_percent


order_percent는 현재 투자조합 가치의 ~%를 주문하는 함수를 말한다. 현재 투자조합 가치는 위치 평가와 현금 합계를 가리킨다.order_percent(asset, amount, style=OrderType)asset:Equity/Future 객체
amount: 0.5면 현재 투자조합 가치의 50%를 Long.-0.5로 나누면 Short.
style: 주문 방법(지정 방법 참조order_percent의 설명)

알고리즘 예


(주문 방법 이외에 #Quantopian Algorithm order-Qita의 설명을 참조하십시오)

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):
            # 成り行きで現在のポートフォリオ価格に対して100%分のアップル株を買う
            order_percent(context.security, 1.0)
            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)

만약 현재 가격이 지난 5일 평균치보다 1% 크다면 현재 투자조합의 가치 AAPL(상당히 적극적인) 알고리즘을 사라.
천 달러부터 시작해서 첫날에는 여섯 주를 샀고 다음날에도 여섯 주를 샀다.

만약 조건이 있다면 우리는 조합의 가치 부분을 증매하여 이러한 거래 역사를 형성할 것이다.

메모지


여기서 말하는 투자조합 가치는 자신이 보유한 주식의 평가+현금을 가리킨다. 위의 Transaction Details에서 보듯이 다음날 6주가 증가하면첫 번째 자조자금은 천 달러로는 살 수 없다. 돈을 빌려도 구매를 늘리는 알고리즘이다. 투자조합 가치는 평가액+현금을 가리키는 것이지 평가액+현금-차관이 아니라는 것을 주의해 주십시오.
그럼 귀찮아요. 이건 정상이에요(?)내 생각엔
이런 거래 함수order_target/order_target_value/order_target_percent가 있으니 다음에 설명하겠습니다.

기타 주문 방법


#Quantopian Algorithm order
#Quantopian Algorithm ordervalue
#Quantopian Algorithm ordertarget

좋은 웹페이지 즐겨찾기