Back

Data points set times

Hello,

I would like to get points for an equity symbol for set times and write a buy ticket on it. 

For example, 

Start at 0 seconds. 

At 5 seconds 

Data point Quote SPY  

At 10 Seconds

Data point Quote SPY

At 15 Seconds 

Data point Quote SPY

 

 

and so on. 

Then use > or < logic to compare thouse data points 

 

Thank you for reading this simple start from me. 

Update Backtest








Maybe use the history method (which returns a Pandas dataframe) and then the 'resample' dataframe method. Something like this

 

# Get the last 50 datapoints with second resolution
# Note than in a notebook brackets around the symbol don't work
# In an algorithm they are required.
history = qb.History('SPY', 50, Resolution.Second)

# Select the close values and use the unstack method to get a column for each security
close_df = history.close.unstack(level=0)

# Use the 'resample' method to get closes at 5 sec increments
# The 'last' method simply gets the last value in each bucket
close_5s_df = close_df.resample('5S', closed='right', label='right').last()

# The dataframe syntax using iloc is sometimes unwieldly.
# One could turn the whole thing into a list first
close_5s_list = close_5s.SPY.tolist()

# Now it's easy to index the list to get specific values
# This will get thefirst (earliest) value in the list
close_5s_list[0]

 

Instead of resampling and returning the last value in each bucket, it may be desireable to get the average price during the interval. This can be done by replacing 'last()' with 'mean()'.

 

close_5s = close_df.resample('5S', closed='right', label='right').mean()

 

With all the values in a list it's easy to compare them

 

close_5s_list[0] > close_5s_list[3]

 

See attached notebook for more examples.

0

Thank you Dan.

I tried sharing this with you. (This is my main account.) I had created some others to colaborate with other people with untill I realized that there was a share feature.

 

I am not very good at programing so I have been trying to use Visial Studio to help walk me though some of this.

It hasn't been as visual as I was hopeing.

 

The 5 second mean time is great because that gives a better idea then the instentanious snapshot.

I'll try to figure out once I have the list to assign them variables then use a simple math equasion that if true buys a certain symbol.

For example, once the list is in a format like

a. price 1

b. price 2

c. price 3

d. price 4

e. price 5

6,7,8,9,10,11 and a few others so on

 

I'll simply write in

if a>d and e>a and .......... then ( buy X)

I'm still playing with visual studio and wil be trying to check in to write your sugestions in this algorithum.

0

David, Thank you for sharing your algorithm. I was able to open it. The first thing I noticed was that it's in C#. The code above works in Python but won't in C#. I saw the "Py" next to your name and assumed that's how you would be programming. Though the two languages are very similar, the specifics (which it seems you are asking for help on) are differrent. I'm really only comfortable helping if you're looking for a Python solution. Let me know if you would like to switch over.

0

The only reason I picked C# is becuase when I was a young man in college I once got a C- grade in regular C programing.

And I tried very hard.

Lets switch it over to Python. I know NOTHING ABOUT PYTHON. But want to learn.

I have some finantial background, and not code as you can see.

Lets do it sir.

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed