726
edits
No edit summary |
No edit summary |
||
(17 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
Download [[Media:Portfolio_Trader_Strategy_Examples.pdf|Portfolio_Trader_Strategy_Examples.pdf]] for regular MultiCharts (PowerLanguage) in '''.PDF''' format. | |||
== Rotation Strategy == | == Rotation Strategy == | ||
Line 62: | Line 62: | ||
==== Portfolio_Rotation_MM Signal ==== | ==== Portfolio_Rotation_MM Signal ==== | ||
The signal is used as a '''Money | The signal is used as a '''Money Management Signal''' in portfolio. This study verifies the indicator values for all the portfolio instruments and manages positions opening. | ||
The number of portfolio instruments for which positions will be opened is set by the user: | The number of portfolio instruments for which positions will be opened is set by the user: | ||
Line 171: | Line 171: | ||
<syntaxhighlight>var: slave_idx(pmms_strategies_get_by_symbol_name(symbolname data2)); | <syntaxhighlight>var: slave_idx(pmms_strategies_get_by_symbol_name(symbolname data2)); | ||
once if 0 > slave_idx then | once if 0 > slave_idx then | ||
raiseruntimeerror(text("specified slave trader on instrument ", doublequote, symbolname data2, doublequote, " not found"));</syntaxhighlight> | raiseruntimeerror(text("specified slave trader on instrument", doublequote, symbolname data2, doublequote, "not found"));</syntaxhighlight> | ||
To synchronize the capital invested into positions for both instruments, we need to send the price of the current position of the main instrument to the pair strategy: | To synchronize the capital invested into positions for both instruments, we need to send the price of the current position of the main instrument to the pair strategy: | ||
Line 184: | Line 184: | ||
This signal '''Portfolio_SpreadTradingSystem.Slave Signal''' is calculated for the second instrument of the pair. It monitors all entries and exits generated by the previous signal '''Portfolio_SpreadTradingSystem.Master Signal''' for the main instrument of the pair and trades in the opposite direction. Firstly, all synchronization is done when '''MPMoney''' variable returned by master strategy changes. | This signal '''Portfolio_SpreadTradingSystem.Slave Signal''' is calculated for the second instrument of the pair. It monitors all entries and exits generated by the previous signal '''Portfolio_SpreadTradingSystem.Master Signal''' for the main instrument of the pair and trades in the opposite direction. Firstly, all synchronization is done when '''MPMoney''' variable returned by master strategy changes. | ||
<syntaxhighlight>value1 = pmms_from_portfolio_currency( pmm_get_my_named_num("MPMoney") );</syntaxhighlight> | <syntaxhighlight>value1 = pmms_from_portfolio_currency(pmm_get_my_named_num("MPMoney") );</syntaxhighlight> | ||
We extract this variable and convert it from portfolio currency into instrument currency. Then, based on its value, we calculate the number of contracts for potential entry positions: | We extract this variable and convert it from portfolio currency into instrument currency. Then, based on its value, we calculate the number of contracts for potential entry positions: | ||
Line 193: | Line 193: | ||
master_mp = IntPortion( value1 / ( value33 * bigpointvalue) );</syntaxhighlight> | master_mp = IntPortion( value1 / ( value33 * bigpointvalue) );</syntaxhighlight> | ||
Current position of the instrument: | |||
<syntaxhighlight>my_mp = currentcontracts*marketposition;</syntaxhighlight> | <syntaxhighlight>my_mp = currentcontracts*marketposition;</syntaxhighlight> | ||
Line 203: | Line 203: | ||
end;</syntaxhighlight> | end;</syntaxhighlight> | ||
We’ll check if the main | We’ll check if the main position of the instrument has closed: | ||
<syntaxhighlight>if 0 = value1 then begin // need to close position | <syntaxhighlight>if 0 = value1 then begin // need to close position | ||
Line 215: | Line 215: | ||
If it has closed, we’ll close the position for the second instrument as well. If the main instrument has an open position, then we will determine the position’s direction for the second instrument: | If it has closed, we’ll close the position for the second instrument as well. If the main instrument has an open position, then we will determine the position’s direction for the second instrument: | ||
<syntaxhighlight>if 0 < value1 then begin // | <syntaxhighlight>if 0 < value1 then begin // buy</syntaxhighlight> | ||
Value1 > 0 means that to synchronize the positions we should buy. There can be two cases: | Value1 > 0 means that to synchronize the positions we should buy. There can be two cases: | ||
Line 277: | Line 276: | ||
<syntaxhighlight>// *** restrictions | <syntaxhighlight>// *** restrictions | ||
once if barstatus(BasedOnData) < 0 then raiseruntimeerror("Portfolio Rank Signal Base needs datastream " + numtostr(BasedOnData, 0)); | once if barstatus(BasedOnData) < 0 then raiseruntimeerror("Portfolio Rank Signal Base needs datastream" + numtostr(BasedOnData, 0)); | ||
once if 1 <> getappinfo(aiisportfoliomode) then raiseruntimeerror("Portfolio Rank Signal Base can be applied to MCPortfolio application only."); | once if 1 <> getappinfo(aiisportfoliomode) then raiseruntimeerror("Portfolio Rank Signal Base can be applied to MCPortfolio application only."); | ||
// **************** | // **************** | ||
Line 301: | Line 300: | ||
if 0 > MoneyCostForInvestPerCtrct then | if 0 > MoneyCostForInvestPerCtrct then | ||
raiseruntimeerror( text("Error! Price = ", potential_entry_price:0:6, "PMargin = ", Portfolio_GetMarginPerContract, "PMaxPLoss = ", Portfolio_GetMarginPerContract) ); | raiseruntimeerror( text("Error! Price = ", potential_entry_price:0:6, | ||
"PMargin = ", Portfolio_GetMarginPerContract, "PMaxPLoss = ", Portfolio_GetMarginPerContract) ); | |||
// MoneyCostForInvestPerCtrct in currency of the symbol. Convert it to portfolio currency ... | // MoneyCostForInvestPerCtrct in currency of the symbol. Convert it to portfolio currency ... | ||
Line 331: | Line 332: | ||
Let us apply some restrictions to the signal: a) it can be used only in Portfolio Trading, b) portfolio size should not be higher than 10 000 instruments and c) the number of instruments should correspond to user inputs that determine the number of entries: | Let us apply some restrictions to the signal: a) it can be used only in Portfolio Trading, b) portfolio size should not be higher than 10 000 instruments and c) the number of instruments should correspond to user inputs that determine the number of entries: | ||
<syntaxhighlight>once if 1 <> getappinfo(aiisportfoliomode) then raiseruntimeerror("Portfolio Rank Money Management Signal can be applied | <syntaxhighlight>once if 1 <> getappinfo(aiisportfoliomode) | ||
then raiseruntimeerror("Portfolio Rank Money Management Signal can be applied to MCPortfolio application only."); | |||
once if pmms_strategies_count() > 10000 | |||
then raiseruntimeerror | |||
("Portfolio Rank Money Management Signal too much instruments, max value = " + numtostr(100000, 0)); | |||
once if pmms_strategies_count() < BuyBestN + SellWorseN then raiseruntimeerror("Portfolio Rank Money Management Signal, please check inputs, BuyBestN + SellWorseN should be less or equal to tradable Instruments number"); | once if pmms_strategies_count() < BuyBestN + SellWorseN | ||
then raiseruntimeerror | |||
("Portfolio Rank Money Management Signal, please check inputs, BuyBestN + SellWorseN should be less or equal to tradable Instruments number"); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 386: | Line 397: | ||
if TraceOutput then | if TraceOutput then | ||
print("CurrentBar = ", currentbar:0:0, ". Allow LONG for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]); | print("CurrentBar = ", currentbar:0:0, ". | ||
Allow LONG for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]); | |||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 426: | Line 439: | ||
MyIndicator= (R - AvgReturn ) / Sdev | MyIndicator= (R - AvgReturn ) / Sdev | ||
end; | end; | ||
{Retrieve MyIndicator Rank. Rank is from 1 to 500 since our universe is 500 Stocks} | {Retrieve MyIndicator Rank. Rank is from 1 to 500 since our universe is 500 Stocks} | ||
If Rank<=10 then Buy 200 contracts next bar at O; {Go Long the best 10 stocks} | If Rank<=10 then Buy 200 contracts next bar at O; {Go Long the best 10 stocks} | ||
Else If Rank>=490 then SellShort 200 contracts next bar at O; {Go Short the | Else If Rank>=490 then SellShort 200 contracts next bar at O; {Go Short the worse 10 stocks}</syntaxhighlight> | ||
The above is a classic case of Stocks Relative Performance Trading. | |||
MyIndicator should be generic, meaning that the user should be able to change this Ranking Indicator as he wishes. Another Example of Ranking Indicator might be: | |||
<syntaxhighlight>MyIndicator = ADX of data2;</syntaxhighlight> | |||
Then allow trading only in those stocks that have the highest ADX. | |||
<br> | |||
<div style="background-color: #E3FBE5;">'''Note:''' These signals are given mainly for reference. If you receive some inconsistent results, you can modify the signals according to your needs.</div> | |||
[[Category:Portfolio Trading]] | [[Category:Portfolio Trading]] |