Click here to Login





                                                   Long/short portfolio rebalancing

  0

0
julie detriech
2017-05-28 16:34:41


Hello,

I am quite new to Quantshare and still don't fully understand the intricacies. I am trying to combine a long/short portfolio based on past returns with a
periodic rebalancing (monthly or quarterly) but I can't figure out first how to go about rebalancing?
- Should I sell/cover existing positions in the strategy (in which case how do I sell/cover ALL existing positions and replace them with new ones?)? Here's my strategy code:
topperc=Comp(Roc(close,30),"Percentile")>=90;
botperc=Comp(Roc(close,30),"Percentile")<=10;

Buy=topperc;
Short=botperc;

*I am not sure how to include the rebalancing here?


- Or should it be included in the money management part? Here is the money management script I am working with:

if( Divers.CurrentDate.Day <= 7 && Divers.CurrentDate.DayOfWeek == DayOfWeek.Monday)
{
Functions.AddMetric("Rebalanced", 1);
// Rebalance Monthly
double equity = Portfolio.GetTotalEquity("long") + Portfolio.GetTotalEquity("short");
double nb = Portfolio.GetAllowedNumberOfPositions("long") + Portfolio.GetAllowedNumberOfPositions("short");
double expectedSize = equity / nb;
Divers.Output("Expected Size: " + expectedSize);
MMPosition[] positions = Portfolio.GetOpenPositions();
for(int i=0;i < positions.Length;i++)
{
MMPosition pos = positions[i];
double sizeDiff = pos.PositionEquity - expectedSize;
int diff = (int)(sizeDiff / pos.LastPrice);
if(diff == 0)
{
// Nothing to do
}
else
{
bool enterShort = (diff > 0) ? true : false;
enterShort = (pos.IsLong) ? enterShort : !enterShort; // Revert enter if the position is short
diff = Math.Abs(diff); // Set positive number of shares
if(enterShort)
{
Divers.Output(pos.Symbol + " (Short): " + diff + " Share(s)");
Functions.AddShortPosition(pos.Symbol, diff, Orders.OpenMarketOrder());
}
else
{
Divers.Output(pos.Symbol + " (Long): " + diff + " Share(s)");
Functions.AddLongPosition(pos.Symbol, diff, Orders.OpenMarketOrder());
}
}
}
}



QuantShare
2017-05-30 08:51:10

  0

To rebalance you just need to exit all positions.

Something like:
sell = month() != ref(month(), 1); // Rebalance monthly



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Custom Trading System Rebalancing
Portfolio Statistics to CSV File
Permanent Portfolio Timing Active Rebalance V0.1
Correlation To Portfolio
Hedge a portfolio strategy

How-to Lessons
How to add trades from one portfolio to another one
How to get trading orders from a portfolio programmatically
How to import trades into a portfolio
How to create a strategy-based portfolio
How to quickly add several positions to your portfolio

Related Forum Threads
Different symbol list for Long/Short / custom portfolio categorie...
Late portfolio buy/sell signals
Ranking System & Portfolio Intraday or Realtime data support
Capital allocation - total capital is split in Long/Short strateg...
True Portfolio Order Generation

Blog Posts
How to combine long, short and custom portfolio strategies within...
How to get buy and sell orders for a portfolio based on a trading...
True portfolio simulation applied to trading systems
Export Trading Orders from a Portfolio to a File
6 ideas to implement in your portfolio to reduce your trading ris...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.