C SHARP CODER NEEDED to design an equity long-only systematic momentum product. (Images in the Details section are missing, can be supplied)

About the client

Switzerland

Posted on Nov 07, 2016 / Est. budget $ 3,000 / Project closed
An equity long-only systematic momentum product.


Strategy:


To invest in the highest momentum S&P 500 stocks.


Process:


Sourcing: Rank the S&P 500 stocks based on highest momentum
Execution: Construct a portfolio of the highest momentum stocks
Backtesting: Multiple scenarios of various variations on ranking the high momentum stock will be run once a week.
Risk Management:
Portfolio construction:
Start buying from the top of your list until you run out of cash
Allocate the same risk to each position (based on individual volatility)
Create sector caps to avoid being fully invested in one sector (v.unlikely)
Additional filters:
The stock must be trading above 100dma
The stock must have no gaps larger than 15% in the past 90 days
A minimum of 25 positions (??)
A maximum of 4% weight per position (??)
Periodical rebalancing to ensure the right stocks at the right weights
No new positions are added in a bear market.
A bear market is defined as the S&P 500 trading below its 200dma
Stop losses: ??
Exits: Allow existing positions to run.
Var, Historic Sharpe Ratio, etc.




Data, Minimum Requirements:


Daily price indicators (more frequent if back testing provides positive evidence).
Backtesting:
Coverage of all current S&P 500 constituents.
Coverage of all previous S&P 500 constituents.
Coverage of graveyard, i.e. all de-listed former members of the S&P 500.
S&P 500 historical joiners and leavers table.
Mapping of changed symbols, e.g. mergers, spin-offs etc.
Corporate actions adjustment factors.
Cash dividends adjustment factors.




Operational Costs:


Office: (Rent, Inventory, etc)
Communication: (Internet/Telephone)
Hard & Software:
Market data: QuantQuote $1,000 fixed one-off and $100 per month
Database: MySql is free or NaviCat Premium (cost tbd)
RightEdge $648, annually
Microsoft Visual Studio is free
etc.




Back Testing:


Structuring the Data:


QuantQuote delivers flat files of three types via FTP:
Raw data files
Factor files
Mapping files.


One file is delivered on the FTP server every day for every stock.
This is raw data and adjustment factors will be applied to get real prices.
The raw price in the data file is multiplied with the split factor.
The raw price in the data file is multiplied with the dividend factor as well.
This results in a total return series.
The mapping table links changed symbols, merged companies etc.


Automating the daily downloads:


The files are delivered on an FTP server.
Automate a download using i.e. StackOverflow.com


Creating a database for all data to be stored:


Using MySql
At least four tables are required for this exercise:
First table: Raw price history. To simplify make it a daily resolution table


Second Table: Factors:
Third Table: Mapping:
















Then use an SQL query to ask these three tables to return an adjusted and mapped data series that looks something like this:







Adjust these prices:


Multiply all the price data by the split factor to get prices adjusted for splits and corporate actions.
Multiply by the dividend factor to get a total return series.
Divide the volume by the split factor (if using volume for anything).


Software Solution:


RightEdge is based on the CLR platform, you can code simulation in C# and make plugins for reporting, visualization, simulation, data handling etc.


Adapting the Data:


Neither RightEdge nor any other software will read straight from the MySql tables.
RightEdge ships with plenty of sample code: to learn the API for a data retrieval adapter, open a simple one, like the Yahoo Data Retrieval sample and modify it to read from your database instead.
To open the files you need a compiler: Microsoft Visual Studio
Make a new dll. Reference RightEdge.Common and MySql.Data. Implement the IService and IBarDataRetreival interfaces. Fill in the blanks in the code. Finally, use the SQL query or something similar, to go fetch the correct, adjusted data and feed it back to RightEdge.
Remember to return properly adjusted series. If you want to go a step deeper, put a toggle in the user interface for getting total return data or regular price data.
When it’s done, compile it and copy the dll into RightEdge’s plugin folder. If all is done correctly, it will be part of the platform when you next open it.




Setting up the Adapter:


Go to the tools menu in RightEdge and select Configure Services. Click new. You should now see it listed. Give it a name and add it.




Watch List:


Make a new watch list and open its settings. Go to the Service tab and tell your watch list to use your data adapter.
Now you can add all your symbols. If you want to do it manually, copy/paste them in. If you want to do it properly, take a look at the file SymbolConfig.xml in the RightEdge folder under your user profile. Make a little program that auto populates symbols with all the correct meta data, by writing straight to the SymbolConfig.xml.
You would need all current and past members of an index, regardless of whether those stocks still exist or not.
Once you’ve got the symbols in there click the update symbol, and data will load. When you see errors or 0 bars, you’ve got a problem.
Chart data: Double click one of your stocks and see. If you get the data now, you’re ready to build the trading strategy.




Strategy:


Aim and value creation of this strategy is to have the most return per unit of volatility.


Chose Universe:


Can be S&P 500, 400, 600, 1500


Market Type Filter:


Do not add any new positions in a bear market. Allow existing positions to run.
Define a bear market using a filter. e.g. S&P 500 below 200dma stop buying stocks.


Ranking Stocks:


Creativity: Can design proprietary analytics for specific purpose without using any usual technical analysis terminology. These should always be based on sound maths and logic, make sense intuitively and be easy to visualise. The simulation work will prove whether or not it adds value. Concept will always be what kind of price behaviour/pattern reflects value in a stock.
Medium term momentum ranking: Use exponential regression to rank stocks.
Calculations use the past 90 trading days.
The exponential regression slope gives the measurement of how much percent up or down the slope of the line of best fit is moving, or the average percent move per day.
An exponential slope is expressed in percent vs a linear slope which is nominal (not useful unless relative to the stock price)
To make comparisons easier we annualise this percentage measurement.
Going by our aim, we want the smoothest gains possible, not wild price behaviour.
In order to measure how snugly the price data fits the regression line we use the coefficient of determination or R squared where 0 is the worst fit, and 1 the best.
Multiplying the annual percentage slope by the R squared will give the best ranking.


Buying:


Constructing the Portfolio:
Start buying from the top of your list until you run out of cash
Allocate the same risk to each position (based on individual volatility)
Create sector caps to avoid being fully invested in one sector (v.unlikely)
Additional filters:
The stock must be trading above 100dma
The stock must have no gaps larger than 15% in the past 90 days


Position Sizing:


Aim is to allocate risk, not cash
Use risk parity allocation
Simple equation: Number of shares = ((Account Value * Risk Factor) / ATR)
ATR: Average True Range (maximum of the days high to low or move from previous day). Can use the 20 day ATR.
Risk Factor: Target daily impact per stock. 0.001 RF means a 0.1% targeted daily impact on the portfolio, or $100 in a $100k account. The lower the risk factor, the more positions you will have at one time.


Keeping Positions Balanced over time (once/twice a month, chose a day…)


Aim is to keep each position’s average daily impact the same over time
Also adjust for overall portfolio value over time and any inflows/outlflows
Dynamic process of continual rebalancing with updated portfolio size and stock ATR
Rebalancing should be done on a periodic basis
A filter can be set for maximum difference between target risk and current risk.
One off re-balances can me made when stocks have extraordinary moves.


Selling:
No stop loss orders
Positions fall off when they are replaced with better risk allocation whether they position is moving up or down does not matter in this case


Portfolio Rebalancing: (once a week, choose a day and stick to it)
The decision to drop a position will be based on its ranking within your universe
If using the S&P 500 say any live position must stay within the top 20% of stocks rankings
If using the S&P 1500 this would be lowered to the top 5%-10% of stocks
We keep our positions as long as they remain in the top percentile of our universe
If all stocks are moving down we have a failsafe. If the stock closes below its 100dma we sell it the next day
So we have four Sell rules:
1/ Sell if the stock is no longer in the top percentile of our universe.
2/ Sell if the stock trades below its 100dma.
3/ Sell if the stock had a gap over 15%
4/ Sell if the stock left the index
To reallocate cash after selling check the market type filter:
If not trading >200dma then you cannot buy anything.
If trading >200dma check the top list and buy the highest ranked stocks on the list that you do not already own until you run out of cash (follow Buying rules).

Project bids (6)

Bids are visible only by project owner and Premium members.