Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Need help putting together simple code to determine profitability of previously suggested trades

I belong to a couple of decent stock picking newsletters that have had good results. However, I'm trying to figure out the appropriate risk/reward ratio were I to enter into the various suggested trades. I have a slew of old trade idea records that I would like to analyze (and it would take way too long to click through the charts of each ticker).

Can someone explain how I can create a program that spits out the result of a specific trade, given that I provide the following trade metrics?: (i) ticker symbol, (ii) stop loss price/percentage, (iii) entry price, (iv) profit target price/percentage and (v) shares purchased?

It seems like it should be relatively simple to accomplish - I have all of the data in a spreadsheet and if I can figure out how to code something that will tell me the end result of each trade (e.g. stop loss hit for 2% loss or target hit for 15% gain), that would be perfect.

2 responses

You will need to export your data into a CSV, then import that into Quantopian. See the "Using Fetcher to create a custom universe" part here. You should be able to then go through each stock you traded in a given day, and calculate whatever you want. You may have better luck just using the CSV to send Quantopian the trades you made for each day in the past, then simulating those trades. Or is that what you were planning on doing? Quantopian will give you a lot of statistics in the backtest result, and you can log anything else you might need.

This is probably a few steps from where you are, but another thing you may require is a function to go along with importing the CSV so that, if there are no records in the CSV file for a certain date, old data is not re-used. See my post on the bottom of this thread: https://www.quantopian.com/posts/define-custom-universe-via-fetcher-using-the-new-universe-func-callback

Let me know if you need any more help!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

This was a harder exercise than I thought it would be :)

I put together something that uses Mark Gomes's "Poised to Triple" published recommendations. I first made them into a CSV file with the simple format of Date, Security Name, Security Symbol. Then I apply the simple "PTT" rules within the algorithm. I can't speak for how truthful his "tracker" page is, but the algorithm seems to work and is attached here for your reference.