Name
定投策略
Author
巴啦啦小魔仙
Strategy Description
股语有云:新手死于追高,老手死于抄底。讲究的是一个择时问题,一不小心就被套牢了,所以很多策略都会去做一些趋势预测,根据趋势进行调整持仓情况。
而对于定投策略,即定期定额的投资策略,根本核心是——低买高卖,越跌越买,而不是追涨杀跌。所以对于定投策略,可以认为随时都可以买。
制定一份有效的定投策略,能够大幅提高定投的收益,我们在定投前都应该把自己的计划落于纸上,按照计划执行,减少人为的干预,坚持下去,止盈不止损,才能真正体会到定投的价值所在。
在这里我们为控制风险对操作范围加以限制,拟定了如下策略规则:
每分钟定投1手空单,20倍杠杆。 未平的仓位,如果亏损超过3%,继续定投。如果盈利超过3%,每分钟平仓2手 其中,在测试脚本中,定投周期、定投数量、杠杆倍数、盈亏率、仓位方向为可配置项。
如果你对该策略有兴趣,请+V:Irene11229 (点击我的主页,我将会持续更新更多策略,同时还可获得几大头部交易所的市场分析数据)
Source (python)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import time
from kumex.client import Trade
class Aip(object):
def __init__(self):
# read configuration from json file
with open('config.json', 'r') as file:
config = json.load(file)
self.api_key = config['api_key']
self.api_secret = config['api_secret']
self.api_passphrase = config['api_passphrase']
self.sandbox = config['is_sandbox']
self.symbol = config['symbol']
self.timer = int(config['timer'])
self.size = int(config['size'])
self.side = config['side']
self.leverage = config['leverage']
self.rate = float(config['rate'])
self.trade = Trade(self.api_key, self.api_secret, self.api_passphrase, is_sandbox=self.sandbox)
if self.side == 'sell':
self.close = 'buy'
else:
self.close = 'sell'
def get_position_pcnt(self):
position = self.trade.get_position_details(self.symbol)
return float(position['unrealisedPnlPcnt'])
if __name__ == '__main__':
aip = Aip()
market_order = aip.trade.create_market_order(aip.symbol, aip.side, aip.leverage, type='market', size=aip.size)
print('create a market %s order, order id = %s' % (aip.side, market_order['orderId']))
while 1:
time.sleep(aip.timer * 60)
pcnt = aip.get_position_pcnt()
if pcnt < 0 and abs(pcnt) > aip.rate:
market_order = aip.trade.create_market_order(aip.symbol, aip.side, aip.leverage,
type='market', size=aip.size)
print('create a market %s order, order id = %s' % (aip.side, market_order['orderId']))
elif pcnt > 0 and pcnt > aip.rate:
market_order = aip.trade.create_market_order(aip.symbol, aip.close, aip.leverage,
type='market', size=(aip.size*2))
print('create a market %s order, order id = %s' % (aip.close, market_order['orderId']))
Detail
https://www.fmz.com/strategy/207710
Last Modified
2021-03-04 10:13:37