Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i=0
- stock = 100
- cash = 0
- for index, row in df2.iterrows():
- if df2.iloc[i][3] > df2.iloc[i+1][3]:
- if stock == 0: #future stock is cheaper, but no stock to sell
- continue
- else:
- cash = cash + df2.iloc[i][3] * stock #future stock is cheaper, so sell
- stock = 0
- else: #future stock is more expensive, so buy
- stock = round((cash/df2.iloc[i][3])-0.5)
- cash = round((cash - stock*df2.iloc[i][3])-0.5)
- i+=1
- i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement