Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

python - How to make a sell call based on some condition in pandas

I have a stock dataset. Where my potential buy call is executed based on some conditions. In my application there can only be one open position, therefore there will be a lot less expected buys.

If I want to sell a stock I need to buy it first. After that my stock needs to gain or lose 10 pips to execute a sell as shown in a dummy dataset.

After my expected sales are defined I can determine expected buys as well (as I said there can only be one open position).

My expected output is expected_sell and expected_buy.

import pandas as pd

d = {'buy': [0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1], 'close': [-2, 5, -8, 6, 15, -1, 15, -6, 16, -4, 2, 11, 12]}
df = pd.DataFrame(data=d)

df['expected_sell'] = [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1]
df['expected_buy'] = [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0]

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...