顯示具有 資金管理相關 標籤的文章。 顯示所有文章
顯示具有 資金管理相關 標籤的文章。 顯示所有文章

2016年6月26日 星期日

權益曲線交易 Trading The Equity Curve

在進行程式交易時,總會碰到draw down,這是無法避免的事情。如果一般的狀況還好,產生的只是一般資金的draw down,但如果不幸運碰到交易開始後的最大回檔,就會變成Maximum Draw Down (MDD)。當這種情況發生,對我們寶貴賺取而來的資金甚於是本金,就是一個強大的傷害。因此,在碰到這樣的情況,為了保護我們的資金,我們得來判定現在進行中的策略(或策略組合)要不要繼續交易下去、還是得暫時下架、或是永久取消交易(也就是策略無法因應現在市場變化,策略的生命週期結束)。

對於資金曲線交易,本質是個簡單的觀念,也不需要太多複雜的想法,目的就是保護資金而已。一般常見的方式就是取資金曲線的簡單平均(SMA),在平均曲線上就進行交易(多+空),在平均曲線下就停止交易。來看一下國外網站上的簡介。
-----------------------------------------------------------------------------------------------------------------------

Trading The Equity Curve


Some trading systems have prolonged periods of winning or losing trades. Long winning streaks may be followed by a prolonged period of drawdown.  Wouldn’t it be nice if you could minimize those long drawdown periods? Here is one tip that might help you do just that. Try applying a simple moving average to your trading system’s equity curve and use that as a signal on when to stop and restart trading your system. This technique just might radically change your trading system’s performance.
How to do this? Well the moving average applied to your trading system’s equity curve creates a smoothed version of your trading system’s equity curve. You can now use this smoothed equity curve as a signal on when to stop or restart trading. For example, when the equity curve falls below the smoothed equity curve you can stop trading your system.  Why would you do this? Because your trading system is under performing, it’s losing money. Only after the equity curve starts to climb again should you start taking your trades once again. This technique is called trading the equity curve.
Trading the equity curve is like trading a basic moving average crossover system. When the fast moving average (your equity curve) crosses over the slower moving average (your smoothed equity curve) you go long (trade your system live). When the fast moving average crosses under the slower moving average you close your long trade (stop trading your live system).


In the image above the blue line is the equity curve of an automated trading system. The pink line is a 30-trade average of the equity curve. When the equity curve dips below the pink line, such as around trade number 60, you would stop trading the system. Once the equity curve rises above the pink line, around trade number 80, you would start trading the system once again.
It’s a great idea and with some systems this technique can really work wonders. In essence, we are using the equity curve as a signal or filter for our trading system. In the most simple case, it’s a switch telling us when to stop trading it and when to resume trading. But you could also use this signal to reduce your risk or switch to a different system instead of simply turning off the system.
(Skip some contents)

Here is section of the equity curve of the system without using the equity curve feedback.



You can see in the above equity curve we had an 83% drop in equity. Also, there is a six year lag between new equity highs. Below is the the equity curve when a 20-period simple moving average is applied. This means we only take trades when the current equity curve is above it’s 20-period simple moving average.


In this example you can see the drawdown was significantly reduced along with the time between new equity highs.

Does It Always Help?

The short answer is, no. Trading the equity curve works well on some trading systems that have prolonged periods of drawdown. Yet, other systems don’t benefit because the drawdowns are rather shallow and you end up hurting your equity more than anything. But like most things in the world of trading, you’ll have to perform some testing. Test different moving averages and test between halting all trading or reducing contract/share size. Remember, some systems do not benefit from this technique at all.
The Equity Curve Feedback Toolkit can also be use to create even more dynamic systems. For example, you can separate your long and short equity curves. Perhaps during a bear market you should only be taking short trades. Well, you can have your system disable long trades if they stop performing well. Likewise for short trades. In this regard, you could build a regime filter based upon the performance of the strategy.
You could also dynamically adjust your risk. That is, if your equity curve begins to fall you can reduce the number of shares or contracts you trade. Maybe when the equity curve is climbing, you need to increase your risk by buying more shares or contracts. You could also start or stop trading based upon drawdown or if the percentage of winners falls below a threshold. These are all possible with this kit.
(Skip some contents)
Source: http://systemtradersuccess.com/trading-the-equity-curve/
-----------------------------------------------------------------------------------------------------------------------------------
上面說明了一個簡單平均下權益曲線交易的範例,MDD可以由85% -> 50%,這樣的交果好或不好,那是見人見智。不過文中也說明了並不是每一種策略都適合,有時加進這樣的曲線交易,反而會讓原本的權益曲線更糟。所以,可以由各方面來做測試,例如:
1) 當在權益曲線平均下方時,可以用減少口數的方式來測試,而不是完全取消交易
2) 也可以把多單及空單分開做測試,在熊市時只針對空單來做,在牛市場只針對多單來做。
3) 當權益曲線在平均上方且穩定上揚時,可以考慮增加口數。

利用「簡單平均」也許只是其中一種方式,藍色投機客也提到使用布林通道1個標準差的下限來做為交易或不交易的標準(相較於平均數,好處是可避免交易次數太少的問題)。當然也可利用海龜通道也行,不過在權益曲線盤整時,可是會被巴的很慘,要有心理準備。
總之,權益曲線交易的唯一目標─「保護本金」,不被立即的MDD產生巨大本金減損。保護本金」、保護本金」、保護本金」,因為很重要,所以說三次。這個和市場交易策略不同,不用太複雜,選個跟自己個性可以相配的方式來控制就行,為自己的資產加把鎖。
Soro 沙羅 


2016年6月22日 星期三

[轉貼] Multicharts程式交易:加碼設定與進階聯想


每個投資人的偏好不同,有人習慣做長線,一抱或許就幾季幾年,也有投資人喜歡短線的進出場操作
其實不論是長線或短線的操作,都可以進行加碼,畢竟一個大趨勢當中必定也參雜了許多小趨勢。
加碼口數的設定上必須考量到下列幾點:
1.資金比例控管
以期貨大台來說,一口波段單如果以五十萬來操作,那麼當你預估策略可加碼到三口時,建議以100
以上,或者參考歷史最大連虧來準備你的起始資金。
2.操作週期長短
當投資人所操作的方式為較長期的策略,相對加碼口數會比短線操作來的大,而短線通常出現較頻繁
也為較小的趨勢,那麼就必須考量到加碼點位是否已經是該波段的相對高低點,這樣的加碼無疑是成
本上的墊高。
3.獲利加碼進場
由於法人資金水位較大,有些甚至大到可以撼動市場,於是它們有本錢在虧損的狀況下去凹單去加碼
直到價格走向獲利的方向。然而散戶資本不足,賠光了也就沒錢凹了,所以應該在手上部位在獲利狀
況下才進行加碼的動作。
進階設定與聯想
當原策略發展成加碼策略後,策略性質有了一定程度上的改變,以多通道加碼系統來說,絕非將原策略
原封不動的進行加碼就可以有效運用,原策略主要由通道系統進出場再輔以停利停損機制來控制績效
而改成加碼策略時做了以下的調整
1.限定加碼口數
為了避免進場在相對高低點而造成無謂損失。
2.將原本的固定金額停利換成獲利回吐機制
由於原策略只有一口單,當獲利到達一定金額後就停利出場,而加碼策略必須考量每一個加碼進場點
位都不同,固定金額停利方式容易錯失停利的機會,常常波段還沒結束就已出場,或者還沒到達停利
趨勢就反轉,於是採用獲利拉回百分比來出場,理由無它,當口數增加時為了要抓住獲利進而必免
過度拉回造成損失。
3.做錯立即停損出場
我們期待的是獲利加碼的概念,可是並非每一次都能成功搭上順風車,總有不小心摔車的經驗,不過
要注意一點,在加碼進場的同時,表示前一口單已經有一部分的未實現獲利存在,但是加碼後價格卻突
然背道而馳
導致
整體產生損失,手中所有部位產生淨損的狀態,那麼就請別戀棧了,這表示已經賠掉
前面的獲利,此時應該等待下一次的機會來臨。

[轉貼] 部位管理 (by 淩波微步)

Position Sizing(部位管理)
 
 如同德州撲克, 你無法每次都拿到好牌,
 但是你卻可以控制每次輸贏的多寡
 這就是Position Sizing要做的事情
 一般我們把PS歸在資金管理的範疇
 
 大部分人的系統開發都停留在第一階段
 也就是僅依據指標判多空
 部位則永遠固定在相同口數
 理論上非多即空,口數固定會有最大獲利,但也相對承受最大風險
 當我們資金少的時候, 只好如此
 
 但當我們資金夠大到可以做籌碼運用的時候, 我們就可以好好來規劃一下
 怎麼將戰術從點推廣到面甚至是3D/4D
 這部份在台灣程式交易論壇是比較少討論到的
 我這邊大概簡介三種
 
 1.點進點出
 
   口數公式是 P=(W/風險值)
 
   W:可為一常數, 當他除以風險值之後可以在你想要的段數間變化, 1~5
     進階的變化則是讓W與權益數連動
 
   風險值: 一般多半引用波動率或乖離率一類逆勢指標
 
   僅在進場的時候決定口數大小, 直到指標反向就全出, 是謂點進點出
 
 代表是阿政大的系統(www.yctseng.net)
 
 優點是遇到大段的可以從頭吃到尾
  缺點是容易紙上富貴
 
 2. 點進面出
 
   公式同1.
 
  但是會隨時重新計算 P , 當風險拉高, P值下降則進行部分停利的動作
  例如盤勢急殺急拉或跳空後, 導致乖離率或波動率驟升, 
  就依據新運算出來的P, 進行減碼停利的動作 
 
 好處是隨時在控制風險, 停利有依據, 非常符合人性
  這是我最喜歡的停利方式
  
 例如4/19急殺之後,空單減碼,就算後面有急拉也不會太懊惱
 
  缺點是趨勢未明的時候容易被巴大條的
  優點上面有說, 就是比較不會紙上富貴
 
 3. 面進點出
 
  2相反
  採用分批進場的方式, 俗稱加碼
  在趨勢不明的時候僅建立基本單,
 隨著基本單獲利出現, 波動率升高, 趨勢明朗才漸漸把口數放大
 
  如版上的lovebeast大就是這樣的模式
 
  優點是前單可以保護後單
 缺點是趨勢的動能也有限度, 怕的是後單進場的時候也是動能停止的時候,
 口數一大會連同之前的獲利一併吃掉
 
 三種模式各有優缺點
 在基礎順勢模型相同的狀況下(僅決定多或空)
 據我的經驗, 以點進面出或面進點出的方式 (即分批進場或分批出場)
 比起點進點出更可以有效降低drawdown而不影響獲利

[轉貼] Position Sizing Rules

Position Sizing Rules

 
October 4th, 2011
 
Following a small discussion I had about advantages and disadvantages of using different position sizing techniques in the ATC 2011 championship of the expert advisors I decided to talk a bit more about various position sizing rules that can used in Forex trading. It’s a very important topic and this blog’s readers agree with this thesis. In my opinion, there are 5 main types of position sizing techniques:
Below I try to explain more about each of these systems of rules.

Fixed position size

Probably the most widely used position size — a trader just uses a fixed lot size (for example, 1 standard lot) on all the positions. The technique is very simple to implement — both manually and in expert advisor. It doesn’t require any calculations. The problem is that it’s very limited and can be quite dangerous (if the fixed size is too high).
The income of the trader doesn’t rise with the growth of the account balance — so the trader isn’t earning profit that would be earned by employing some other position sizing models. When a trader sets fixed position size to some large amount compared to the account balance, there’s a danger that the account will get wiped out in case of a continuous losing streak.
For my ATC 2011 EA I’ve chosen this type of position sizing because it offers a very fast buildup of balance in the beginning and becomes less aggressive in the end. So far I’ve been lucky with it: after one big loss, 2 positions are showing nice profit. Nevertheless, I don’t recommend this position sizing system for your real account trading.
Example: Every position’s volume is set to 3 standard lots.

Martingale position sizing

If you think that the fixed position sizing is dangerous, then Martingale position sizing is definitely not for you. The main rule of this technique is to increase your position size as you take losses. It’s derived from Martingale gambling system, which involves doubling your bet anytime you lose and was very popular back in XIX century; it is still popular among some gamblers and Forex traders. This system offers a sure-fire money winning method for a trader with the infinite account balance, but, unfortunately, even George Soros‘ account isn’t infinitely big.
In Forex, Martingale position sizing is somewhat popular partially because it offers a comfort of potential revenge on the market. A trader doubling a position size after a loss is hoping to get back what was lost and also gain some profit at the same time. In reality, a streak of 5–6 losses in a row usually leaves the trading account empty.
Example: Using one lot as a position size, you’ve lost $1,000 on a trade. You increase the next position’s size to two standards lots to double your potential profit (to cover your previous loss). If that one is lost too, you double the position size again to 4 standard lots, and so on.

Fixed fractional position sizing

This system is often called reverse Martingale, because here a trader increases position size after a winning trade and decreases it after a losing trade. The idea is to minimize the risk of ruin and to increase exponentially the income in case of a continuous profitability of the employed trading strategy.
Although, it’s probably the most effective and safe position sizing systems for Forex, unfortunately, it also has its disadvantages. The biggest of them is that it works poorly with trading strategies that often involve losses after huge wins — such position sizing would then increase the loss, decreasing the overall strategy’s performance. I’ve dropped this method specifically because of that disadvantage, as my ATC 2011 EA often shows significant losses after winning a trade. Second disadvantage is a rather slow buildup of the account balance compared to fixed position sizing if moderate fraction ratio is used.
Example: Your account balance is $7,500. You decide to set your position size to 0.01% of your account size. $7,500 * 0.01% = 0.75 lot. So you set your position volume to 0.75. If you win, let’s say, $500, your balance increases to $8,000, and 0.01% of it will be 0.8 lot. If you lose, let’s say, also $500, your balance becomes $7,000, and 0.01% of it will be 0.7 lot.
As you see, it is a very flexible position sizing system because you can vary the ratio and thus the risk according your preference.

ATR-based position sizing

Actually, it’s just an additional rule for the fixed fractional position sizing technique (but can be used with any of them). It involves position size normalization according to the current value of Average True Range (ATR) indicator. ATR shows the volatility of the market. As ATR increases, a smaller position size would be advised because volatile market has a higher chance of pushing the trade out of its planned way. As ATR decreases, a bigger position can be opened as there’s less probability for a price spike to hit the stop-loss .
This position sizing add-on is useful for the trending Forex strategies and can be harmful for range trading, where spikes can be useful to hit take-profit .
Example: Your account balance is $10,000 and you decide to set your position size to 0.02% of the account size. You are trading EUR/USD and consider ATR = 0.00100 as a ”normal value”. Calculate fixed fractional position size: $10,000 * 0.02% = 2 lots . The current ATR is at 0.00221 (which means more than double “normal” volatility). Calculate ATR-adjusted position size: 2 lots / (0.00221 / 0.00100) = 0.905 . So you set your position volume to 0.905 lot (or, if your broker doesn’t allow using one thousandth fractions of a lot, 0.91 lot). Then this position wins you $2,700. For the next position you recalculate the fixed fractional position size: $12,700 * 0.02% = 2.54 lots . The FX market is raging with volatility and ATR on EUR/USD has risen to 0.00562. Now, recalculate the ATR-adjusted position size: 2.54 lots / (0.00562 / 0.00100) = 0.452 lot (or 0.45) .
This method to adjust position size is extremely adaptive but due to the amount of required calculations is better used with the automated Forex expert advisors rather than manually.

Risk-based position sizing

This one is also an addition to the other position sizing rules and is more popular with the fractional position sizing too. While, usually, a Forex trader bases the position size solely on the size of the account, here, one would also apply the size of the stop-loss of the particular position. The main idea with risk-based position sizing is to limit the potential loss to some fraction of the account balance based on the stop-loss .
Example: Your account balance is $12,000 and your stop-loss is set to 40 pips (normal pips), and you want to risk no more than 1.5% on your next EUR/USD trade. Calculate the maximum risk in dollars: $12,000 * 1.5% = $180 . 1 pip is worth $10 on 1 standard lot of EUR/USD. Calculate the position size: $180 / (40 pips * $10) = 0.45 . That is, if you want to risk no more than 1.5% on this trade with the given balance and stop-loss , you may open a position of 0.45 standard lot volume.
To calculate position size for risk-based method easily, you can use our free online Forex position size calculator.

Conclusion

Some traders also use no position sizing rules in Forex at all. That’s not a very professional trait. Position sizing can help you to improve the strong points of the trading strategy and decrease the chance of ruining the live trading account. If you know traders that still size their positions chaotically, direct them to this article, please :-).

If you have some questions or comments regarding the listed position sizing rules in Forex, please feel free to reply using the form below.


[轉貼] 各種資金管理模型的Easy Language - 藍色投機客

之前有報告過各種資金管理的模型,那時候是用MSA3這個軟體來做模擬和測試的,可是如果MSA3的試用期滿之後,可能就不能再繼續使用了。而在TS forum裡面,有個叫做Hamfon的高手,他把各種資金管理模型都寫成Easy Language了,所以有興趣的朋友可以直接用TS就來做資金管理的模擬和測試了。

他把八種資金管理的模型都寫出來了,分別是:
1 = Fixed Fraction (based on Percentage input, as well as CurrentBalance and Margin)
2 = Fixed Ratio (based on InvDelta, LotSize, CurrentBalance, and OriginalStake)
3 = Percent Risk (based on CurrentBalance, RiskPct and StopLossAmount)
4 = Percent Volatility (based on CurrentBalance and VolatilityPct)
5 = Fixed Lot (always same size)
6 = Fixed Margin Amount (increments/decrements the position size in fixed steps based on CurrentBalance and percentage of Margin)
7 = Fixed Margin Amount with Trailing (same as #6, but also temporarily decreases position size on a drawdown)
8 = Conservative Fixed (calculates based on CurrentBalance related to Margin and DrawDown)

 
而他用了一個簡單的三條移動平均線系統當作他測試進出場的系統,各位可以改寫成用你們自己的進出場系統,再搭配他的資金管理模型,就可以看出各種不同模型對於最終資產的影響。

下面是他原始的文章,裡面有基本的說明,還有每個參數的解說。附加的檔案我放在最下面:

==========================================================

Position sizing is a key element in strategy development yet too often overlooked. With anappropriate trade sizing strategy maximum potential drawdown of a system is understood and used in conjunction with increasing bet size as equity grows...both a must for making the most out of a system... and keeping afloat by minimizing risk. An excellent overview of position sizing can be found in Van Tharp's book 'Trade Your Way To Financial Freedom'.


With help from ebear, I have designed a position sizing Function for TradeStation that allows you to test several position sizing algorithms, and optimize them for particular trading conditions, tickers, timeframes, margins, and capital.


Although these algorithms are just a few of many possibilities, we have found them to be the basis for more complex schemes - and have, in general, tried to stay with the KISS simplicity principle.


We also implemented and tested the Optimal-F algorithm, but discarded it because the position size swings were, in our opinion, excessive, with higher maximum drawdown and risk of ruin.

The attached Function includes the following eight algorithms (with their parameters detailed below). A sample Strategy is also attached. This strategy (which works pretty well!) is a simple 3-moving average "stack" -
that is, we go long when fast and medium MA are both above the slow MA, and when the fast crosses up over the medium MA (stacked upside down for short trade signals). Note that I kept the parameters separate for most of the
algorithms, so that you can optimize them separately. Also, the parameters that are specific to a particular algorithm include that number in the parameter name. Recommended starting values for the Function Input
parameters are given in parentheses - these are the default values in the attached sample Strategy.


1 = Fixed Fraction (based on Percentage input, as well as CurrentBalance and Margin)
2 = Fixed Ratio (based on InvDelta, LotSize, CurrentBalance, and OriginalStake)
3 = Percent Risk (based on CurrentBalance, RiskPct and StopLossAmount)
4 = Percent Volatility (based on CurrentBalance and VolatilityPct)
5 = Fixed Lot (always same size)
6 = Fixed Margin Amount (increments/decrements the position size in fixed steps based on CurrentBalance and percentage of Margin)
7 = Fixed Margin Amount with Trailing (same as #6, but also temporarily decreases position size on a drawdown)
8 = Conservative Fixed (calculates based on CurrentBalance related to Margin and DrawDown)

Here are the parameters for the PositionSizer Function:
AlgorithmNum(1) - specify value 1 through 8 to choose which algorithm to use
OriginalStake(20000) - how much money you start with
MarginAmt(3700) - margin for futures
TradeLotSize(1) - Scaling adjustment - normally 1 for Futures, 100 for stocks
MaxLotSize(100) - trade no more than this many contracts
Factor(1) - level of conservative/aggressive trading
IncludeOpenPL(false) - do we include Profit/Loss from current open position in CurrentBalance?
FixedFracPct#1(0.3) - for Fixed Fraction
InvDelta#2(0.0005) - for Fixed Ratio
RiskPct#3(3.4) - for Percent Risk
StopLossPct#3#4(2) - for Percent Risk and Percent Volatility
VolatilityPct#4(4) - for Percent Volatility
VolatilityScaling#4(2) - for Percent Volatility
FixedLot#5(1) - for Fixed Lot
IncMarginPct#6#7(200) - Percentage of current "base" where we increase the position size
DecMarginPct#6#7(50) - Percentage of current "base" where we decrease the position size
TrailingPct#7(90) - Percentage of current "base" where we temporarily decrease the position size
MaxDrawDownBux#8(500) - Maximum allowed drawdown before changing position size

Comments and suggestions for improving the code are welcome - thanks! I also have other TradeStation strategies, functions, and indicators on my web site athttp://www.hamfon.com/daytrade . 

HamFon
HamFon@HamFon.com

========================================================
Easy Language 的檔案放在這裡: