Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. i=0
  2. stock = 100
  3. cash = 0
  4.  
  5. for index, row in df2.iterrows():
  6. if df2.iloc[i][3] > df2.iloc[i+1][3]:
  7. if stock == 0: #future stock is cheaper, but no stock to sell
  8. continue
  9. else:
  10. cash = cash + df2.iloc[i][3] * stock #future stock is cheaper, so sell
  11. stock = 0
  12. else: #future stock is more expensive, so buy
  13. stock = round((cash/df2.iloc[i][3])-0.5)
  14. cash = round((cash - stock*df2.iloc[i][3])-0.5)
  15. i+=1
  16. i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement