SHARE
TWEET

Untitled

a guest Jun 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top