Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature (Shows the latest orders from stocks ran on the algorithm through a watchlist) #5

Closed
wants to merge 1 commit into from

Conversation

uatemycookie22
Copy link

I have added this new feature to iterate through a watchlist of stocks and return the latest order (which is on the latest date of the given stock history) for each of the stocks. Entering 'today' when asked for a ticket prints this list of orders. The 'Current performance' that is printed with the order is simply a percentage change between the entry price and the latest value of the portfolio that followed the algorithm.

Code:

watchlist = ['BABA', 'IBM', 'PEN', 'GOOG', 'SPCE', 'AMD', 'NIO', 'ARKG', 'PENN', 'MRNA', 'WMT', 'AAPL', 'SBUX', 'NKE', 'SNE']
for ticker in watchlist:
        portfolio, entry_price, control_value, algo_value, prices, days = run_algo(ticker, starting_capital, starting_shares)
        order_today = portfolio.Orders[days-1]
        highlight_color = order_today['Type'] == "Buy" and 'green' or order_today['Type'] == "Sell" and 'red' or 'white'
        performance = math.floor( (algo_value-entry_price)/entry_price*100 )
        print(ticker,colored( order_today, highlight_color), "Current performance: "+ (algo_value >= entry_price and "+%" or algo_value < entry_price and "-%")+ str(performance))

Output:

BABA {'Type': 'Buy', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%183
IBM {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%9
PEN {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%270
GOOG {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%77
SPCE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%230
AMD {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%1020
NIO {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%573
ARKG {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%141
PENN {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%501
MRNA {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%460
WMT {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%103
AAPL {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%389
SBUX {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%141
NKE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%148
SNE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%292

@ryantcullen
Copy link
Owner

Cool! Would you mind submitting this on a new branch? If you do I will accept.

@uatemycookie22
Copy link
Author

Cool! Would you mind submitting this on a new branch? If you do I will accept.

Submit this on a new branch? I'm sorry I'm still a little unfamiliar with GitHub. Do you mean making a new branch on my fork and making a new pull request from that?

@ryantcullen
Copy link
Owner

Yep that's what I mean.

@ryantcullen
Copy link
Owner

Cool! Would you mind submitting this on a new branch? If you do I will accept.

Submit this on a new branch? I'm sorry I'm still a little unfamiliar with GitHub. Do you mean making a new branch on my fork and making a new pull request from that?

yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants