0

I'm building a trading bot and currently backtesting. I have two pandas DataFrames, one much longer than the other. The longer contains all the dates and all the indexes for x amount of years. The other data frame only contain the dates and indexes of which I bought or sold.

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'], 'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}

When I try to plot this on the same graph the line or scatter of the short list end up really compact in the beginning of the graph. How should I plot this to get a meaningful graph? The optimal graph would be to only have one line, the long one, and plot points on that line where trades occurred.

Thanks!

1
  • What are the x and y axis in your plot? x axis is 2,4,6,8 and y axis is the date? Commented Aug 8, 2020 at 9:53

1 Answer 1

1

You can use the dates for your x-axis:

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'],'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}


import matplotlib.pyplot as plt

plt.plot(Long_frame['date'], Long_frame['index'])
plt.plot(Short_frame['date'], Short_frame['index'],'.', markersize=15)

The trade date points are located at the date position and both graphs are 'equally distributed'

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that looks like what I'm after. I'm guessing it's possible to add an arbitrary amount of dataframes as well?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.