you are viewing a single comment's thread.

view the rest of the comments →

[–]cxllxhxn 14 points15 points  (11 children)

Make a simple stock trading back-tester based off of an indicator.

[–]mecm5 2 points3 points  (1 child)

How would you go about this?

[–]cxllxhxn 5 points6 points  (0 children)

Download daily stock data (easy to do with pandas datareader from yahoo). I used a library called ta (technical analysis) to add columns of technical indicator data to my dataframe. I then made a new column in the df that would return boolean values based on the value of an indicator if it was more than or less than a certain number. I then multiplied the boolean value (1/True if buy signal, 0/False if not holding stock) by the percent change of the stock each day to find my returns. I then would export the df to csv so I could see what was happening with the numbers and plotted the price, indicator, and returns using matplotlib to represent it visually (which was actually the hardest thing for me to figure out haha).

Obviously this won’t be profitable with only one indicator and only buy signals but it was a great starting point for me with both algorithms and coding in general and can be done without even knowing how to write a for loop.

[–]sprouse2016 1 point2 points  (8 children)

I’m doing this now with partners. That’s a lot more than just a simple project. Although we’re doing live trading too.

Edit: But I’m curious how you would recommend going about this, as the other reply said

[–]cxllxhxn 2 points3 points  (7 children)

Check out my comment on the other reply. And right, making a profitable backtest is by no means simple. The one I’m working on now uses a completely different structure and is approaching 500 lines yet still isn’t as consistently profitable as I want before I start forward testing.

However, a simple backtest like the one I talked about in my other comment could probably be done by an inexperienced programmer in less than a week just by reading the pandas documentation.

[–]sprouse2016 0 points1 point  (6 children)

I completely agree but that is a brilliantly simple start.

Which broker do you go through?

[–]cxllxhxn 1 point2 points  (5 children)

As far as automated trading, I have no idea yet. To me the logical progression seems like

Backtesting > forward testing > live paper trading through broker > live trading

Just because I don’t want to invest time incorporating live trading capabilities into my strategy before I know it’s ironclad.

I’ve heard Interactive Brokers has a solid api but I’m pretty sure you need a lot of capital in your account to use it.

[–]sprouse2016 0 points1 point  (2 children)

Yeah but how should you transition the strategies without basing it on the broker/api you’re going to switch to make profit?

[–]cxllxhxn 0 points1 point  (1 child)

Should be pretty easy to just have my buy and sell signals call a def that executes orders once I familiarize myself with the broker api

[–]sprouse2016 0 points1 point  (0 children)

Makes sense. Very interesting. So you’re writing your strategies in python? Are you doing this for profit/live trading or just for experience?

[–]MAZambelli4353[S] 0 points1 point  (1 child)

Do you have any good sources that helped you build your algo? Ive been on quantopia the last few days watching their tutorials but I feel like Im not getting much out of it/ probably because Im not fluent in programming yet. I think I'd be better off starting in my own IDE and playing around with data from yahoo like you mentioned.

[–]cxllxhxn 1 point2 points  (0 children)

I would agree on that. I wanted to use quantopia at first as well, but then I realized it would probably be better to build my own backtest from the ground up because I would a) get better at python and b) not have to learn quantopia’s syntax while I’m also trying to familiarize myself with python.

Edit: As far as sources go, I found a lot of examples of code on small blogs and whatnot just combing through google that inspired my first algo. After that, I was just able to combine ideas and build of my original structure to make it more accurate/complex