|
clonex
2012-05-21 20:56:20
0
|
|
Hello,
thank you for your advice.
I succesfuly passed your steps . Here is OnEndperiod code:
MMPosition[] positions = Portfolio.GetOpenPositions();
double[] arr = new double[] {};
double sum = 0;
for(int i=0;i < positions.Length;i++)
{
MMPosition pos = positions[i];
TimeSeries ts = Data.ParseFormula("a = sharpe(close,10);").GetTimeSeries(pos.Symbol, "a");
//Divers.Output("ts:"+ts[0]);
double sharpe =ts[0];
//Divers.Output("ts:"+sharpe);
sum += ts[i];
}
Divers.Output("sum: "+sum);
double weight = 0;
for(int i=0;i < positions.Length;i++)
{
MMPosition pos = positions[i];
TimeSeries ts = Data.ParseFormula("a = sharpe(close,10);").GetTimeSeries(pos.Symbol, "a");
double sharpe =ts[0];
weight = sharpe/sum;
//Divers.Output("weight"+weight);
double cash = Portfolio.GetTotalEquity("long")*weight;
//Divers.Output("numberofcash:"+numberofcash);
Divers.Output("Cash: "+cash);
TimeSeries close = Data.ParseFormula("a = close;").GetTimeSeries(pos.Symbol, "a");
Divers.Output("Close:"+close[0]);
double numberofshares = cash/close[0];
Divers.Output("numberofshares: "+numberofshares);
Functions.AddLongPosition(pos.Symbol,numberofshares,Orders.CloseMarketOrder());
}
I think that specific values (Sharpe ratio for each position, weight of each position, Calculate the number of shares to buy/sell based on the expected size and the current position size) are calculated correctly.
But now i have final problem. When i use this MM script strategy buys after some trades galactic numbers of shares and makes big losses. In my strategy i use N bar stop via vector language.
Other problem i see is that i need to calculate values only when my strategy send Market on CLose order next day. In current setup script calculates values every day...
Thank You
Here ist exported list of my trades:
Symbol Trade Entry Exit Perf Profit Shares Pos. value Nb bars Perf/Bar MAE MFE Scale In Scale Out Exit type
XLK (open) Long 2.2.2000 0:00 5.4.2012 0:00 0,707605118 2,8649E+12 2,29156E+11 6,91363E+12 3064 0,000230942 -0,780664395 0,258517888 547 0
XLV (open) Long 2.2.2000 0:00 5.4.2012 0:00 0,425682817 3,89068E+12 3,47388E+11 1,30305E+13 3064 0,00013893 -0,326030449 0,411065726 634 0
EWH (open) Long 2.2.2000 0:00 5.4.2012 0:00 0,997867183 9,35708E+11 1,06687E+11 1,87342E+12 3064 0,000325675 -0,468405216 1,137412237 282 0
EWJ (open) Long 2.2.2000 0:00 5.4.2012 0:00 0,210704575 1,80894E+11 1,05739E+11 1,03942E+12 3064 6,87678E-05 -0,566037736 0,099622642 288 0
EWJ Long 31.1.2000 0:00 2.2.2000 0:00 0,008371385 163,13 1483 19649,75 2 0,004185693 -0,01217656 0,008371385 0 0 N-Bars Stop
EWH Long 31.1.2000 0:00 2.2.2000 0:00 0,010131712 130,4 1304 13000,88 2 0,005065856 -0,028368794 0,014184397 0 0 N-Bars Stop
XLV Long 31.1.2000 0:00 2.2.2000 0:00 0,037764933 674,24 688 18527,84 2 0,018882466 -0,008477842 0,037764933 0 0 N-Bars Stop
XLK Long 31.1.2000 0:00 2.2.2000 0:00 0,02847131 560,3 431 20239,76 2 0,014235655 -0,053000438 0,02847131 0 0 N-Bars Stop
|
|