- 精华
- 0
- 在线时间
- 174 小时
- UID
- 117185
- 积分
- 220
- 帖子
- 68
- 阅读权限
- 40
- 注册时间
- 2013-3-21
- 最后登录
- 2015-6-2
- 精华
- 0
- UID
- 117185
- 积分
- 220
- 帖子
- 68
- 主题
- 10
- 阅读权限
- 40
- 注册时间
- 2013-3-21
- 最后登录
- 2015-6-2
|
投资学里经典的一句话 - 限制损失,让盈利奔跑。只要盈亏比达到一个理想的值,那胜率低也一样能赚到钱。为了验证这个理论,我写了一个随机发买卖单的模型,并且限制每次损失的上限,对盈利进行追踪止损。模型为日内交易,每3分钟发一个单。- Params
- Numeric InitialStop(2);
- Numeric BreakEvenStop(3);
- Numeric TrailStop(5);
-
- Vars
- Numeric RandNum;
- Numeric BuyOrSell;
- Numeric StopLine;
- Numeric MyEntryPrice;
- Numeric MyExitPrice;
- NumericSeries HighestAfterEntry;
- NumericSeries LowestAfterEntry;
- Begin
- If(Time>=0.1455){//如果要实盘测试,把Time改为CurrentTime
- If(MarketPosition == 1)
- Sell(0,Close);
- If(MarketPosition == -1)
- BuyToCover(0,Close);
- return;
- }
- If(BarsSinceentry == 0)
- {
- HighestAfterEntry = Close;
- LowestAfterEntry = Close;
- If(MarketPosition <> 0)
- {
- HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice);
- LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice);
- }
- }else
- {
- HighestAfterEntry = Max(HighestAfterEntry,High);
- LowestAfterEntry = Min(LowestAfterEntry,Low);
- }
- Commentary("HighestAfterEntry="+Text(HighestAfterEntry)); Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
- MyEntryPrice = AvgEntryPrice;
- If(MarketPosition==1) // 有多仓的情况
- {
- StopLine = AvgEntryPrice * (1-InitialStop/1000);
-
- If(HighestAfterEntry[1] >= MyEntryPrice *(1 + BreakEvenStop/1000))
- Stopline = MyEntryPrice;
-
- If(Stopline < HighestAfterEntry[1]*(1 - TrailStop/1000))
- Stopline = HighestAfterEntry[1]*(1 - TrailStop/1000);
-
- if(Low <= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
- Sell(0,MyExitPrice);
- return;
- }
- }else if(MarketPosition==-1) // 有空仓的情况
- {
- StopLine = AvgEntryPrice * (1+InitialStop/1000);
-
- If(LowestAfterEntry[1] <= MyEntryPrice *(1 - BreakEvenStop/1000))
- Stopline = MyEntryPrice;
-
- If(Stopline > LowestAfterEntry[1]*(1 + TrailStop/1000))
- Stopline = LowestAfterEntry[1]*(1 + TrailStop/1000);
-
- Commentary("StopLine="+Text(Stopline));
- If(High >= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
- BuyToCover(0,MyExitPrice);
- return;
- }
- }
- RandNum = Rand(0,100); //产生0到100的随机数
- BuyOrSell = Mod(RandNum,2); //产生0到1的随机数
- Commentary("BuyOrSell:"+TEXT(BuyOrSell));
- If(BuyOrSell == 0 && Mod(Minute,3) == 0 && MarketPosition!= -1) //如果BuyOrSell为0,每3分钟发一次多单
- Buy(1,Close);
- else If(BuyOrSell == 1 && Mod(Minute,3) == 0 && MarketPosition!=1)//如果BuyOrSell为1,每3分钟发一次空单
- SellShort(1,Close);
- End
复制代码 用这个模型在橡胶单日做了10次测试,开一手,结果意外的发现共赢8次,仅亏2次。最大亏损才660,最大盈利4210. 难道是我RP比较好?
第1次 : 亏450
第2次 : 赢1520
第3次 : 赢2790
第4次 :赢3540
第5次 :赢4210
第6次 :亏660
第7次 :赢2840
第8次 :赢1020
第9次 :赢3130
第10次 :赢810
不信邪,再测10次,结果还是很意外的盈利8次,亏2两次。不过这次最大亏损达到4910,最大盈利4030.
第1次 : 赢240
第2次 : 赢1480
第3次 : 赢1020
第4次 :赢360
第5次 :亏4910
第6次 :赢4030
第7次 :赢1920
第8次 :赢1230
第9次 :赢1980
第10次 :亏3090
经过这次测试我终于相信盈利其实跟入市的选择关系并不大,关键是要控制好亏损,让盈利尽量增长,就是人们经常说的高盈亏比。篮球赛场上也有一句话,就是谁的防守好谁就能赢得总冠军,我相信投资也是一样的,我们很难控制盈利,那我们能做的就是很好的防守,让损失降到最低。小弟愚见,欢迎拍砖。 |
|